Grafalgo
Library of useful data structures and algorithms
/Users/jst/src/grafalgo/cpp/dataStructures/heaps/unit/testLheapSet.cpp
Go to the documentation of this file.
00001 
00009 #include "LheapSet.h"
00010 #include "Utest.h"
00011 
00012 using namespace grafalgo;
00013 
00014 void basicTests() {
00015         LheapSet hset; string s;
00016 
00017         cout << "writing empty heap set: " << hset.toString(s) << "\n\n";
00018 
00019         hset.setkey(1,5); hset.setkey(3,4); hset.setkey(5,6);
00020         int h1 = 1; h1 = hset.insert(3,h1); h1 = hset.insert(5,h1);
00021         Utest::assertTrue(hset.findmin(h1) == 3, "min item does not match");
00022         cout << "writing hset with 3 item heap\n" << hset.toString(s) << endl;
00023 
00024         hset.setkey(8,2); hset.setkey(9,7); hset.setkey(7,3);
00025         int h2 = 8; h2 = hset.insert(9,h2); h2 = hset.insert(7,h2);
00026         Utest::assertTrue(hset.findmin(h2) == 8, "min item does not match");
00027         cout << "writing hset with two 3 item heaps\n"
00028              << hset.toString(s) << endl;
00029 
00030         h1 = hset.meld(h1,h2);
00031         Utest::assertTrue(hset.findmin(h1) == 8, "min item does not match");
00032         cout << "after melding\n" << hset.toString(s) << endl;
00033 
00034         h1 = hset.deletemin(h1);
00035         Utest::assertTrue(hset.findmin(h1) == 7, "min item does not match");
00036         cout << "after deletemin\n" << hset.toString(s) << endl;
00037 
00038         h1 = hset.deletemin(h1);
00039         Utest::assertTrue(hset.findmin(h1) == 3, "min item does not match");
00040         cout << "after deletemin\n" << hset.toString(s) << endl;
00041 }
00042 
00046 int main() {
00047         cout << "running basic tests\n";
00048         basicTests();
00049         cout << "basic tests passed\n";
00050 
00051         // add more systematic tests for each individual method
00052 }
 All Classes Files Functions Variables Typedefs Friends