Skip to content

Commit

Permalink
include unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shajoezhu committed Jun 26, 2015
1 parent b45ba1a commit a861085
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@
.dirstamp
topo
topo_dbg
unittest
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ before_install:

script:
- make
- make unittest
- ./unittest
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@ FLAGS = -O3 -g -std=c++0x -DVERSION=\"${VERSION}\"
SOURCE = all_gene_topo.cpp

.PHONY: all
all: clean_all topo topo_dbg
all: topo topo_dbg

topo:
topo: all_gene_topo.hpp all_gene_topo.cpp main.cpp
${COMPILER} ${FLAGS} -DNDEBUG -o topo ${SOURCE} main.cpp

topo_dbg:
topo_dbg: all_gene_topo.hpp all_gene_topo.cpp main.cpp
${COMPILER} ${FLAGS} -o topo_dbg ${SOURCE} main.cpp

# Tester flags
unittests_CXXFLAGS = -DUNITTEST -DNDEBUG -std=c++0x -DVERSION=\"${VERSION}\"
unittests_LDADD = -lcppunit -ldl

test_src = test_topo.cpp ${SOURCE}

unittest: all_gene_topo.hpp all_gene_topo.cpp test_runner.cpp test_topo.cpp
${COMPILER} ${unittests_CXXFLAGS} ${test_src} test_runner.cpp -o unittest ${unittests_LDADD}

.PHONY: clean
clean:
rm -f topo topo_dbg
Expand Down
Empty file removed README
Empty file.
1 change: 1 addition & 0 deletions README
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
A simple program for enumerating all possible binary tree Newick strings from given taxon names. This program is part of the program hybrid-coal.
USEAGE:

$ ./topo a b c d e
17 changes: 11 additions & 6 deletions all_gene_topo.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* hybrid-Lambda is used to simulate gene trees given species network under
* hybrid-Lambda is used to simulate gene trees given species network under
* coalescent process.
*
* Copyright (C) 2010 -- 2014 Sha (Joe) Zhu
*
*
* Copyright (C) 2010 -- 2015 Sha (Joe) Zhu
*
* This file is part of hybrid-Lambda.
*
*
* hybrid-Lambda is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
Expand All @@ -23,13 +23,18 @@
/*! \file all_gene_topo.cpp
* \brief Enumerate all possible tree topologies for given number of taxon */

#include"all_gene_topo.hpp"
#include "all_gene_topo.hpp"

//GeneTopoList::GeneTopoList( string tree_str ){
GeneTopoList::GeneTopoList( vector < string > &TipLabels_in ){
this->TipLabels = TipLabels_in;
//this->extract_TipLabels_from_TreeStr ( tree_str );
assert ( this->TipLabels.size() >= 2 ) ;
this->run();
}


void GeneTopoList::run(){
this->init();
this->core();
this->finalize();
Expand Down
24 changes: 14 additions & 10 deletions all_gene_topo.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* hybrid-Lambda is used to simulate gene trees given species network under
* hybrid-Lambda is used to simulate gene trees given species network under
* coalescent process.
*
* Copyright (C) 2010 -- 2014 Sha (Joe) Zhu
*
*
* Copyright (C) 2010 -- 2015 Sha (Joe) Zhu
*
* This file is part of hybrid-Lambda.
*
*
* hybrid-Lambda is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
Expand Down Expand Up @@ -49,6 +49,7 @@ using namespace std;
class GeneTopoList {
friend class HybridCoal;
friend class TopoApp;
friend class TestGeneTopoList;
//deque < string > TreeList;
vector < string > TreeList;
vector < string > TipLabels;
Expand All @@ -59,7 +60,8 @@ class GeneTopoList {
string add_new_taxa_at_int(string &in_str, size_t i, string &newly_added );
string add_new_taxa_at_tip(string &in_str, size_t i, string &newly_added, string added_to );
string extract_label( string &in_str, size_t i);


void run();
void init();
void core();
void extract_TipLabels_from_TreeStr ( string &tree_str );
Expand Down Expand Up @@ -88,7 +90,7 @@ class TopoApp {

void parse(){
if ( argc_ == 1 ){
cout << "print help "<<endl;
cout << "USEAGE: ./topo a b c d e "<<endl;
return;
}

Expand All @@ -100,9 +102,11 @@ class TopoApp {
}

void finalize(){
if ( topo_list_->TreeList.size() > 1 )
topo_list_ ->init();
topo_list_ ->core();
if ( topo_list_->TipLabels.size() > 1 ) {
topo_list_ ->run();
} {
cout << " Please provide at least two taxon names." <<endl;
}
for ( size_t i = 0; i < topo_list_->TreeList.size(); i++){
cout << topo_list_->TreeList[i] << endl;
}
Expand Down
22 changes: 22 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
/*
* hybrid-Lambda is used to simulate gene trees given species network under
* coalescent process.
*
* Copyright (C) 2010 -- 2015 Sha (Joe) Zhu
*
* This file is part of hybrid-Lambda.
*
* hybrid-Lambda is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "all_gene_topo.hpp"

int main ( int argc, char *argv[] ) {
Expand Down
34 changes: 34 additions & 0 deletions test_runner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Execute this program to run the test suite.
*
* Usually there's no need to change anything in here.
*/
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/CompilerOutputter.h>

using namespace CppUnit;

int main(void) {
TestResult controller;

TestResultCollector result;
controller.addListener(&result);

BriefTestProgressListener progress;
controller.addListener(&progress);

TestRunner runner;
runner.addTest( TestFactoryRegistry::getRegistry().makeTest() );
runner.run(controller);

CompilerOutputter outputter(&result, std::cerr);
outputter.write();

return result.wasSuccessful() ? 0 : 1;
}

// EOF
62 changes: 62 additions & 0 deletions test_topo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include <cppunit/TestCase.h>
#include <cppunit/extensions/HelperMacros.h>
#include "all_gene_topo.hpp"

#pragma GCC diagnostic ignored "-Wwrite-strings"

class TestGeneTopoList : public CppUnit::TestCase {

CPPUNIT_TEST_SUITE( TestGeneTopoList );
CPPUNIT_TEST ( testConstructor );
CPPUNIT_TEST ( testExtract );
CPPUNIT_TEST_SUITE_END();
private:

public:
void setUp() {
return;
}

void tearDown() {
return;
}

void testConstructor(){
const char *vinit3[] = {"a", "b", "c"};
std::vector<std::string> v3(vinit3, end(vinit3));
GeneTopoList testList3(v3);
CPPUNIT_ASSERT ( testList3.TipLabels.size() == (unsigned)3 );
CPPUNIT_ASSERT ( testList3.TreeList.size() == (unsigned)3 );

const char *vinit4[] = {"a", "b", "c", "d"};
std::vector<std::string> v4(vinit4, end(vinit4));
GeneTopoList testList4(v4);
CPPUNIT_ASSERT ( testList4.TipLabels.size() == (unsigned)4 );
CPPUNIT_ASSERT ( testList4.TreeList.size() == (unsigned)15 );

const char *vinit5[] = {"a", "b", "c", "d", "e"};
std::vector<std::string> v5(vinit5, end(vinit5));
GeneTopoList testList5(v5);
CPPUNIT_ASSERT ( testList5.TipLabels.size() == (unsigned)5 );
CPPUNIT_ASSERT ( testList5.TreeList.size() == (unsigned)105 );

const char *vinit6[] = {"a", "b", "c", "1", "2", "3"};
std::vector<std::string> v6(vinit6, end(vinit6));
GeneTopoList testList6(v6);
CPPUNIT_ASSERT ( testList6.TipLabels.size() == (unsigned)6 );
CPPUNIT_ASSERT ( testList6.TreeList.size() == (unsigned)945 );

}

void testExtract(){
GeneTopoList testList;
string tree = "(((A,B),C),D);";
CPPUNIT_ASSERT_NO_THROW(testList.extract_TipLabels_from_TreeStr(tree));
CPPUNIT_ASSERT ( testList.TipLabels.size() == (unsigned)4 );
CPPUNIT_ASSERT_NO_THROW(testList.init());
CPPUNIT_ASSERT_NO_THROW(testList.core());
CPPUNIT_ASSERT ( testList.TreeList.size() == (unsigned)15 );
}
};

CPPUNIT_TEST_SUITE_REGISTRATION( TestGeneTopoList );

0 comments on commit a861085

Please sign in to comment.