Grafalgo
Library of useful data structures and algorithms
/Users/jst/src/grafalgo/cpp/dataStructures/basic/unit/testClist.cpp
Go to the documentation of this file.
00001 
00009 #include "Clist.h"
00010 #include "Utest.h"
00011 
00012 using namespace grafalgo;
00013 
00014 void basicTests() {
00015         int n1 = 12; Clist cl(n1); string s;
00016 
00017         for (int i = 1; i <= n1; i++)
00018                 Utest::assertTrue(cl.suc(i) == i && cl.pred(i) == i,
00019                                   "don't have singletons on startup");
00020 
00021         cout << "writing initial collection" << endl;
00022         cout << cl << endl;
00023 
00024         cl.join(1,2); cl.join(3,4);
00025         for (int i = 6; i <= 10; i++) cl.join(i-1,i);
00026         cout << "writing collection after some joins" << endl;
00027         cout << cl << endl;
00028         Utest::assertEqual("{[a b], [c d], [e f g h i j]}",cl.toString(s),
00029                            "incorrect result following joins");
00030 
00031         cl.remove(7); cl.remove(9);
00032         cout << "writing collection after some removes" << endl;
00033         cout << cl << endl;
00034         Utest::assertEqual("{[a b], [c d], [e f h j]}",
00035                            cl.toString(s),
00036                            "incorrect result following removes");
00037 
00038         Clist cl2(n1); cl2.copyFrom(cl);
00039         Utest::assertEqual("{[a b], [c d], [e f h j]}",
00040                            cl2.toString(s),
00041                            "incorrect result following copy");
00042         cl2.expand(27);
00043         Utest::assertEqual("{[1 2], [3 4], [5 6 8 10]}",
00044                            cl2.toString(s),
00045                            "incorrect result following expand");
00046 }
00047 
00051 int main() {
00052         cout << "running basic tests\n";
00053         basicTests();
00054         cout << "basic tests passed\n";
00055 
00056         // add more systematic tests for each individual method
00057 }
 All Classes Files Functions Variables Typedefs Friends