Grafalgo
Library of useful data structures and algorithms
/Users/jst/src/grafalgo/cpp/dataStructures/basic/unit/testPartition.cpp
Go to the documentation of this file.
00001 
00009 #include "Partition.h"
00010 #include "Utest.h"
00011 
00012 using namespace grafalgo;
00013 
00014 void basicTests() {
00015         int n1 = 10; Partition prtn(n1); string s;
00016 
00017         cout << "writing initial partition: " << prtn << endl;
00018         Utest::assertEqual(prtn.toString(s), "{}",
00019                                              "initial partition not correct");
00020 
00021         prtn.link(1,2); prtn.link(3,4); prtn.link(5,6);
00022         cout << "writing new partition: " << prtn << endl;
00023         Utest::assertEqual(prtn.toString(s), "{[a b*] [c d*] [e f*]}",
00024                                              "mismatch after 3 links");
00025 
00026         prtn.link(2,4); prtn.link(4,7); prtn.link(6,8);
00027         cout << "writing new partition: " << prtn << endl;
00028         Utest::assertEqual(prtn.toString(s), "{[a b c d* g] [e f* h]}", 
00029                                              "mismatch after 3 more links");
00030 
00031         prtn.link(9,10); prtn.link(6,10); prtn.link(10,4);
00032         cout << "writing new partition: " << prtn << endl;
00033         Utest::assertEqual(prtn.toString(s), "{[a b c d* e f g h i j]}",
00034                                              "mismatch after another 3 links");
00035         prtn.expand(27); prtn.link(13,27);
00036         cout << "writing expanded partition: " << prtn << endl;
00037         Utest::assertEqual(prtn.toString(s), "{[1 2 3 4* 5 6 7 8 9 10] "
00038                                              "[13 27*]}",
00039                                              "mismatch after expand/link");
00040 }
00041 
00045 int main() {
00046         cout << "running basic tests\n";
00047         basicTests();
00048         cout << "basic tests passed\n";
00049 
00050         // add more systematic tests for each individual method
00051 }
 All Classes Files Functions Variables Typedefs Friends