]> ruin.nu Git - germs.git/commitdiff
adding countCycles, findComponents, findIntervals declaration, with initial tests
authorMichael Andreen <harv@ruin.nu>
Tue, 19 Jun 2007 08:27:42 +0000 (08:27 +0000)
committerMichael Andreen <harv@ruin.nu>
Tue, 19 Jun 2007 08:27:42 +0000 (08:27 +0000)
src/genealgorithms.cpp
src/genealgorithms.h
src/test/genealgorithmstest.cpp

index b2d7fa6132b0463ee9a1b1cdf8f240bddf1204f9..7dc832f252c208900b92c234879c8f09b5a93c24 100644 (file)
@@ -22,6 +22,7 @@
 #include "geneorder.h"
 
 #include <algorithm>
+#include <set>
 #include <cstdlib>
 using namespace std;
 
@@ -53,3 +54,21 @@ std::vector<std::vector<int> > robinsonSchensted(const GeneOrder& go){
        }
        return v;
 }
+
+int countCycles(const GeneOrder& go){
+       int cycles = 0;
+       set<size_t> marked;
+       for (size_t p = 1; p < go.size() - 1; ++p){
+               if (marked.find(p) != marked.end())
+                       continue;
+       }
+       return cycles;
+}
+
+std::vector<Component> findComponents(const GeneOrder& go){
+       return vector<Component>();
+}
+
+std::vector<Interval> findIntervals(const GeneOrder& go){
+       return vector<Interval>();
+}
index 4c519a7e3167a40384893a86dea243f20d1ac6d9..4c938e394bd42fa1ea3eb710239811dd32277e99 100644 (file)
 
 class GeneOrder;
 
+struct Component{
+       Component(int b,int e,int s):begin(b),end(e),sign(s){}
+       int begin;
+       int end;
+       int sign;
+};
+typedef std::pair<size_t,size_t> Interval;
+
 /**
  * Returns the length of the longest increasing sequence and the longest
  * decreasing sequence.
@@ -35,5 +43,20 @@ std::pair<int,int> longestSequences(const GeneOrder& go);
  */
 std::vector<std::vector<int> > robinsonSchensted(const GeneOrder& go);
 
+/**
+ * Counts the number of cycles in the gene order.
+ */
+int countCycles(const GeneOrder& go);
+
+/**
+ * Finds the components in the gene order.
+ */
+std::vector<Component> findComponents(const GeneOrder& go);
+
+/**
+ * Find intervals.
+ */
+std::vector<Interval> findIntervals(const GeneOrder& go);
+
 #endif
 
index 55ebb58db7085ff5cbeb242d7ce7b3057d97659c..50a5c736c1903ac2bd6d8a7941cccfec715353d4 100644 (file)
@@ -22,6 +22,8 @@ class TESTNAME : public CPPUNIT_NS::TestFixture
   CPPUNIT_TEST_SUITE( TESTNAME );
   CPPUNIT_TEST( testRobinsonSchensted );
   CPPUNIT_TEST( testLongestSequences );
+  CPPUNIT_TEST( testFindIntervals );
+  CPPUNIT_TEST( testCountCycles );
   CPPUNIT_TEST_SUITE_END();
 
 protected:
@@ -74,11 +76,35 @@ protected:
                
                GeneOrder go2(_validPerm2.begin(),_validPerm2.end());
                p = longestSequences(go2);
-               int first[] = {0,1,3,5,6,7,9};
-               int second[] = {2,4,8};
                CPPUNIT_ASSERT_EQUAL(7,p.first);
                CPPUNIT_ASSERT_EQUAL(2,p.second);
        }
+       void testFindIntervals (){
+               GeneOrder go(_validPerm.begin(),_validPerm.end());
+               vector<pair<size_t,size_t> > v = findIntervals(go);
+               CPPUNIT_ASSERT_EQUAL(4ul,v.size());
+               Interval go10(1,1);
+               Interval go12(3,3);
+               CPPUNIT_ASSERT(go10 == v[0]);
+               CPPUNIT_ASSERT(go12 == v[2]);
+               
+               GeneOrder go2(_validPerm2.begin(),_validPerm2.end());
+               v = findIntervals(go);
+               CPPUNIT_ASSERT_EQUAL(9ul,v.size());
+               Interval go20(1,3);
+               Interval go22(1,4);
+               CPPUNIT_ASSERT(go20 == v[0]);
+               CPPUNIT_ASSERT(go22 == v[2]);
+       }
+       void testCountCycles (){
+               GeneOrder go(_validPerm.begin(),_validPerm.end());
+               int c = countCycles(go);
+               CPPUNIT_ASSERT_EQUAL(4,c);
+               
+               GeneOrder go2(_validPerm3.begin(),_validPerm3.end());
+               c = countCycles(go2);
+               CPPUNIT_ASSERT_EQUAL(6,c);
+       }
 
 };