]> ruin.nu Git - germs.git/blobdiff - src/test/componenttreetest.cpp
count leaves
[germs.git] / src / test / componenttreetest.cpp
index 3bde9b196eb94ebaee11cd650b14eb6d71e70ec3..d85c59a429c9a0fffd693a6d001da5e37fc38fb8 100644 (file)
@@ -24,6 +24,7 @@ class TESTNAME : public CPPUNIT_NS::TestFixture
   CPPUNIT_TEST_SUITE( TESTNAME );
   CPPUNIT_TEST( testCreate );
   CPPUNIT_TEST( testMakeUnoriented );
+  CPPUNIT_TEST( testCountLeaves );
   CPPUNIT_TEST_SUITE_END();
 
 protected:
@@ -61,7 +62,7 @@ protected:
        void testCreate (){
                GeneOrder go(_validPerm.begin(),_validPerm.end());
                ComponentTree t(findComponents(go));
-               ComponentTree::Node* n = &t._root;
+               ComponentTree::Node* n = t._root;
 
                CPPUNIT_ASSERT_EQUAL((size_t)4u,count(n));
                CPPUNIT_ASSERT_EQUAL((size_t)5u,count(n,true));
@@ -78,7 +79,7 @@ protected:
 
                GeneOrder go2(_validPerm4.begin(),_validPerm4.end());
                ComponentTree t2(findComponents(go2));
-               n = &t2._root;
+               n = t2._root;
 
                CPPUNIT_ASSERT_EQUAL((size_t)6u,count(n));
                CPPUNIT_ASSERT_EQUAL((size_t)9u,count(n,true));
@@ -102,7 +103,7 @@ protected:
                GeneOrder go(_validPerm.begin(),_validPerm.end());
                ComponentTree t(findComponents(go));
                t.makeUnoriented();
-               ComponentTree::Node* n = &t._root;
+               ComponentTree::Node* n = t._root;
 
                CPPUNIT_ASSERT_EQUAL((size_t)0u,count(n));
                CPPUNIT_ASSERT_EQUAL((size_t)1u,count(n,true));
@@ -111,7 +112,7 @@ protected:
                GeneOrder go2(_validPerm4.begin(),_validPerm4.end());
                ComponentTree t2(findComponents(go2));
                t2.makeUnoriented();
-               n = &t2._root;
+               n = t2._root;
 
                CPPUNIT_ASSERT_EQUAL((size_t)4u,count(n));
                CPPUNIT_ASSERT_EQUAL((size_t)6u,count(n,true));
@@ -126,6 +127,22 @@ protected:
                CPPUNIT_ASSERT(n->_children[1]->_children[0]->_children[1]->_comp == go24);
        }
 
+       void testCountLeaves (){
+               GeneOrder go(_validPerm.begin(),_validPerm.end());
+               ComponentTree t(findComponents(go));
+               t.makeUnoriented();
+
+               //CPPUNIT_ASSERT_EQUAL((size_t)0u,t.countLeaves());
+
+               GeneOrder go2(_validPerm4.begin(),_validPerm4.end());
+               ComponentTree t2(findComponents(go2));
+               t2.makeUnoriented();
+               ComponentTree::Node* n = t2._root;
+               CPPUNIT_ASSERT_EQUAL((size_t)2u,n->_children.size());
+               CPPUNIT_ASSERT_EQUAL(false,n->_children.empty());
+               CPPUNIT_ASSERT_EQUAL((size_t)3u,t2.countLeaves());
+       }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION( TESTNAME );