Grafalgo
Library of useful data structures and algorithms
|
00001 00009 #include "FheapSet.h" 00010 #include "Utest.h" 00011 00012 using namespace grafalgo; 00013 00014 void basicTests() { 00015 FheapSet hset; string s; 00016 00017 cout << "writing empty heap set: " << hset.toString(s) << endl; 00018 //Utest::assertEqual(hset.toString(s), "", "initial heap not correct"); 00019 00020 hset.setKey(1,5); 00021 int h1 = 1; h1 = hset.insert(3,h1,4); h1 = hset.insert(5,h1,6); 00022 Utest::assertTrue(hset.findmin(h1) == 3, "min item does not match"); 00023 cout << "writing hset with 3 item heap\n" << hset.toString(s) << endl; 00024 00025 hset.setKey(8,2); 00026 int h2 = 8; h2 = hset.insert(9,h2,7); h2 = hset.insert(7,h2,3); 00027 Utest::assertTrue(hset.findmin(h2) == 8, "min item does not match"); 00028 cout << "writing hset with two 3 item heaps\n" 00029 << hset.toString(s) << endl; 00030 00031 h1 = hset.meld(h1,h2); 00032 Utest::assertTrue(hset.findmin(h1) == 8, "min item does not match"); 00033 cout << "writing hset with 6 item heap\n" 00034 << hset.toString(s) << endl; 00035 00036 h1 = hset.decreasekey(9,6,h1); 00037 Utest::assertTrue(hset.findmin(h1) == 9, "min item does not match"); 00038 cout << "writing hset after decreasekey\n" 00039 << hset.toString(s) << endl; 00040 00041 h1 = hset.deletemin(h1); 00042 Utest::assertTrue(hset.findmin(h1) == 8, "min item does not match"); 00043 cout << "writing modified hset with 5 item heap\n" 00044 << hset.toString(s) << endl; 00045 00046 h1 = hset.deletemin(h1); 00047 Utest::assertTrue(hset.findmin(h1) == 7, "min item does not match"); 00048 cout << "writing modified hset with 4 item heap\n" 00049 << hset.toString(s) << endl; 00050 00051 h1 = hset.decreasekey(5,4,h1); 00052 cout << "writing hset after decreasekey\n" 00053 << hset.toString(s) << endl; 00054 } 00055 00059 int main() { 00060 cout << "running basic tests\n"; 00061 basicTests(); 00062 cout << "basic tests passed\n"; 00063 00064 // add more systematic tests for each individual method 00065 }