summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Dyer <cdyer@cs.cmu.edu>2012-05-02 02:30:52 -0400
committerChris Dyer <cdyer@cs.cmu.edu>2012-05-02 02:30:52 -0400
commit1c32f3e2831aefdf50fd226d3e1b314c804afc3b (patch)
tree69c07b672f279f69c12525fde02fa2675e63ea6f
parent721ff772038c117da8746836533609eda7737443 (diff)
remove dependency on gtest, remove all-static
-rw-r--r--configure.ac2
-rw-r--r--decoder/Makefile.am21
-rw-r--r--decoder/earley_composer.cc1
-rw-r--r--decoder/ff_test.cc64
-rw-r--r--decoder/grammar.cc1
-rw-r--r--decoder/grammar_test.cc24
-rw-r--r--decoder/hg_test.cc143
-rw-r--r--decoder/hg_test.h9
-rw-r--r--decoder/parser_test.cc21
-rw-r--r--decoder/trule_test.cc32
-rw-r--r--dpmert/Makefile.am10
-rw-r--r--dpmert/lo_test.cc32
-rw-r--r--gi/pf/cfg_wfst_composer.cc1
-rw-r--r--mteval/Makefile.am6
-rw-r--r--mteval/scorer_test.cc81
-rw-r--r--utils/Makefile.am18
-rw-r--r--utils/crp_test.cc31
-rw-r--r--utils/dict_test.cc37
-rw-r--r--utils/logval_test.cc60
-rw-r--r--utils/m_test.cc52
-rw-r--r--utils/small_vector_test.cc145
-rw-r--r--utils/weights_test.cc22
22 files changed, 314 insertions, 499 deletions
diff --git a/configure.ac b/configure.ac
index b709a2c9..0d54cf46 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,6 +12,7 @@ AC_PROG_CXX
AC_LANG_CPLUSPLUS
BOOST_REQUIRE([1.44])
BOOST_PROGRAM_OPTIONS
+BOOST_TEST
AC_ARG_ENABLE(mpi,
[ --enable-mpi Build MPI binaries, assumes mpi.h is present ],
[ mpi=yes
@@ -77,7 +78,6 @@ AC_CHECK_HEADER(google/dense_hash_map,
[AC_DEFINE([HAVE_SPARSEHASH], [1], [flag for google::dense_hash_map])])
AC_PROG_INSTALL
-GTEST_LIB_CHECK(1.0)
AM_CONDITIONAL([RAND_LM], false)
AC_ARG_WITH(randlm,
diff --git a/decoder/Makefile.am b/decoder/Makefile.am
index ec51d643..d16a9147 100644
--- a/decoder/Makefile.am
+++ b/decoder/Makefile.am
@@ -1,34 +1,25 @@
bin_PROGRAMS = cdec
-if HAVE_GTEST
noinst_PROGRAMS = \
trule_test \
hg_test \
- ff_test \
parser_test \
grammar_test
- # cfg_test
-TESTS = trule_test ff_test parser_test grammar_test hg_test
-# cfg_test
-#cfg_test_SOURCES = cfg_test.cc
-#cfg_test_LDADD = $(GTEST_LDFLAGS) $(GTEST_LIBS) libcdec.a ../mteval/libmteval.a ../utils/libutils.a -lz
+TESTS = trule_test parser_test grammar_test hg_test
parser_test_SOURCES = parser_test.cc
-parser_test_LDADD = $(GTEST_LDFLAGS) $(GTEST_LIBS) libcdec.a ../mteval/libmteval.a ../utils/libutils.a -lz
-ff_test_SOURCES = ff_test.cc
-ff_test_LDADD = $(GTEST_LDFLAGS) $(GTEST_LIBS) libcdec.a ../mteval/libmteval.a ../utils/libutils.a -lz
+parser_test_LDADD = $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) libcdec.a ../mteval/libmteval.a ../utils/libutils.a -lz
grammar_test_SOURCES = grammar_test.cc
-grammar_test_LDADD = $(GTEST_LDFLAGS) $(GTEST_LIBS) libcdec.a ../mteval/libmteval.a ../utils/libutils.a -lz
+grammar_test_LDADD = $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) libcdec.a ../mteval/libmteval.a ../utils/libutils.a -lz
hg_test_SOURCES = hg_test.cc
-hg_test_LDADD = $(GTEST_LDFLAGS) $(GTEST_LIBS) libcdec.a ../mteval/libmteval.a ../utils/libutils.a -lz
+hg_test_LDADD = $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) libcdec.a ../mteval/libmteval.a ../utils/libutils.a -lz
trule_test_SOURCES = trule_test.cc
-trule_test_LDADD = $(GTEST_LDFLAGS) $(GTEST_LIBS) libcdec.a ../mteval/libmteval.a ../utils/libutils.a -lz
-endif
+trule_test_LDADD = $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) libcdec.a ../mteval/libmteval.a ../utils/libutils.a -lz
cdec_SOURCES = cdec.cc
cdec_LDADD = libcdec.a ../mteval/libmteval.a ../utils/libutils.a ../klm/lm/libklm.a ../klm/util/libklm_util.a -lz
-AM_CPPFLAGS = -W -Wno-sign-compare $(GTEST_CPPFLAGS) -I.. -I../mteval -I../utils -I../klm
+AM_CPPFLAGS = -DBOOST_TEST_DYN_LINK -W -Wno-sign-compare $(GTEST_CPPFLAGS) -I.. -I../mteval -I../utils -I../klm
rule_lexer.cc: rule_lexer.l
$(LEX) -s -CF -8 -o$@ $<
diff --git a/decoder/earley_composer.cc b/decoder/earley_composer.cc
index 385baf8b..d265d954 100644
--- a/decoder/earley_composer.cc
+++ b/decoder/earley_composer.cc
@@ -4,6 +4,7 @@
#include <fstream>
#include <map>
#include <queue>
+#include <tr1/unordered_map>
#include <tr1/unordered_set>
#include <boost/shared_ptr.hpp>
diff --git a/decoder/ff_test.cc b/decoder/ff_test.cc
deleted file mode 100644
index 9e640517..00000000
--- a/decoder/ff_test.cc
+++ /dev/null
@@ -1,64 +0,0 @@
-#include <cassert>
-#include <iostream>
-#include <fstream>
-#include <vector>
-#include <gtest/gtest.h>
-#include "hg.h"
-#include "ff_lm.h"
-#include "ff.h"
-#include "trule.h"
-#include "sentence_metadata.h"
-
-using namespace std;
-
-LanguageModel* lm_ = NULL;
-LanguageModel* lm3_ = NULL;
-
-class FFTest : public testing::Test {
- public:
- FFTest() : smeta(0,Lattice()) {
- if (!lm_) {
- static LanguageModel slm("-o 2 ./test_data/test_2gram.lm.gz");
- lm_ = &slm;
- static LanguageModel slm3("./test_data/dummy.3gram.lm -o 3");
- lm3_ = &slm3;
- }
- }
- protected:
- virtual void SetUp() { }
- virtual void TearDown() { }
- SentenceMetadata smeta;
-};
-
-TEST_F(FFTest, LM3) {
- int x = lm3_->NumBytesContext();
- Hypergraph::Edge edge1;
- edge1.rule_.reset(new TRule("[X] ||| x y ||| one ||| 1.0 -2.4 3.0"));
- Hypergraph::Edge edge2;
- edge2.rule_.reset(new TRule("[X] ||| [X,1] a ||| [X,1] two ||| 1.0 -2.4 3.0"));
- Hypergraph::Edge edge3;
- edge3.rule_.reset(new TRule("[X] ||| [X,1] a ||| zero [X,1] two ||| 1.0 -2.4 3.0"));
- vector<const void*> ants1;
- string state(x, '\0');
- SparseVector<double> feats;
- SparseVector<double> est;
- lm3_->TraversalFeatures(smeta, edge1, ants1, &feats, &est, (void *)&state[0]);
- cerr << "returned " << feats << endl;
- cerr << edge1.feature_values_ << endl;
- cerr << lm3_->DebugStateToString((const void*)&state[0]) << endl;
- EXPECT_EQ("[ one ]", lm3_->DebugStateToString((const void*)&state[0]));
- ants1.push_back((const void*)&state[0]);
- string state2(x, '\0');
- lm3_->TraversalFeatures(smeta, edge2, ants1, &feats, &est, (void *)&state2[0]);
- cerr << lm3_->DebugStateToString((const void*)&state2[0]) << endl;
- EXPECT_EQ("[ one two ]", lm3_->DebugStateToString((const void*)&state2[0]));
- string state3(x, '\0');
- lm3_->TraversalFeatures(smeta, edge3, ants1, &feats, &est, (void *)&state3[0]);
- cerr << lm3_->DebugStateToString((const void*)&state3[0]) << endl;
- EXPECT_EQ("[ zero one <{STAR}> one two ]", lm3_->DebugStateToString((const void*)&state3[0]));
-}
-
-int main(int argc, char **argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/decoder/grammar.cc b/decoder/grammar.cc
index 714390f0..d1fe53af 100644
--- a/decoder/grammar.cc
+++ b/decoder/grammar.cc
@@ -4,6 +4,7 @@
#include <utility>
#include <map>
#include <tr1/unordered_map>
+#include <tr1/unordered_set>
#include "rule_lexer.h"
#include "filelib.h"
diff --git a/decoder/grammar_test.cc b/decoder/grammar_test.cc
index cde00efa..e1a94709 100644
--- a/decoder/grammar_test.cc
+++ b/decoder/grammar_test.cc
@@ -1,8 +1,11 @@
+#define BOOST_TEST_MODULE g_test
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+
#include <cassert>
#include <iostream>
#include <fstream>
#include <vector>
-#include <gtest/gtest.h>
#include "trule.h"
#include "tdict.h"
#include "grammar.h"
@@ -12,18 +15,16 @@
using namespace std;
-class GrammarTest : public testing::Test {
- public:
+struct GrammarTest {
GrammarTest() {
Weights::InitFromFile("test_data/weights.gt", &wts);
}
- protected:
- virtual void SetUp() { }
- virtual void TearDown() { }
vector<weight_t> wts;
};
-
-TEST_F(GrammarTest,TestTextGrammar) {
+
+BOOST_FIXTURE_TEST_SUITE( s, GrammarTest );
+
+BOOST_AUTO_TEST_CASE(TestTextGrammar) {
vector<double> w;
vector<const FeatureFunction*> ms;
ModelSet models(w, ms);
@@ -38,7 +39,7 @@ TEST_F(GrammarTest,TestTextGrammar) {
g.AddRule(r3);
}
-TEST_F(GrammarTest,TestTextGrammarFile) {
+BOOST_AUTO_TEST_CASE(TestTextGrammarFile) {
GrammarPtr g(new TextGrammar("./test_data/grammar.prune"));
vector<GrammarPtr> grammars(1, g);
@@ -52,8 +53,5 @@ TEST_F(GrammarTest,TestTextGrammarFile) {
parser.Parse(lattice, &forest);
forest.PrintGraphviz();
}
+BOOST_AUTO_TEST_SUITE_END()
-int main(int argc, char **argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/decoder/hg_test.cc b/decoder/hg_test.cc
index 5d1910fb..8455a865 100644
--- a/decoder/hg_test.cc
+++ b/decoder/hg_test.cc
@@ -1,6 +1,7 @@
+#define BOOST_TEST_MODULE hg_test
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
#include <iostream>
-#include <fstream>
-#include <vector>
#include "tdict.h"
#include "json_parse.h"
@@ -11,12 +12,11 @@
#include "hg_test.h"
-
using namespace std;
-typedef HGSetup HGTest;
+BOOST_FIXTURE_TEST_SUITE( s, HGSetup );
-TEST_F(HGTest,Controlled) {
+BOOST_AUTO_TEST_CASE(Controlled) {
Hypergraph hg;
CreateHG_tiny(&hg);
SparseVector<double> wts;
@@ -27,15 +27,15 @@ TEST_F(HGTest,Controlled) {
prob_t prob = ViterbiESentence(hg, &trans);
cerr << TD::GetString(trans) << "\n";
cerr << "prob: " << prob << "\n";
- EXPECT_FLOAT_EQ(-80.839996, log(prob));
- EXPECT_EQ("X <s>", TD::GetString(trans));
+ BOOST_CHECK_CLOSE(-80.839996, log(prob), 1e-4);
+ BOOST_CHECK_EQUAL("X <s>", TD::GetString(trans));
vector<prob_t> post;
hg.PrintGraphviz();
prob_t c2 = Inside<prob_t, ScaledEdgeProb>(hg, NULL, ScaledEdgeProb(0.6));
- EXPECT_FLOAT_EQ(-47.8577, log(c2));
+ BOOST_CHECK_CLOSE(-47.8577, log(c2), 1e-4);
}
-TEST_F(HGTest,Union) {
+BOOST_AUTO_TEST_CASE(Union) {
Hypergraph hg1;
Hypergraph hg2;
CreateHG_tiny(&hg1);
@@ -57,16 +57,16 @@ TEST_F(HGTest,Union) {
c3 = ViterbiESentence(hg1, &t3);
int l3 = ViterbiPathLength(hg1);
cerr << c3 << "\t" << TD::GetString(t3) << endl;
- EXPECT_FLOAT_EQ(c2.as_float(), c3.as_float());
- EXPECT_EQ(TD::GetString(t2), TD::GetString(t3));
- EXPECT_EQ(l2, l3);
+ BOOST_CHECK_CLOSE(c2.as_float(), c3.as_float(), 1e-4);
+ BOOST_CHECK_EQUAL(TD::GetString(t2), TD::GetString(t3));
+ BOOST_CHECK_EQUAL(l2, l3);
wts.set_value(FD::Convert("f2"), -1);
hg1.Reweight(wts);
c4 = ViterbiESentence(hg1, &t4);
cerr << c4 << "\t" << TD::GetString(t4) << endl;
- EXPECT_EQ("Z <s>", TD::GetString(t4));
- EXPECT_FLOAT_EQ(98.82, log(c4));
+ BOOST_CHECK_EQUAL("Z <s>", TD::GetString(t4));
+ BOOST_CHECK_CLOSE(98.82, log(c4), 1e-4);
vector<pair<vector<WordID>, prob_t> > list;
KBest::KBestDerivations<vector<WordID>, ESentenceTraversal> kbest(hg1, 10);
@@ -76,13 +76,13 @@ TEST_F(HGTest,Union) {
if (!d) break;
list.push_back(make_pair(d->yield, d->score));
}
- EXPECT_TRUE(list[0].first == t4);
- EXPECT_FLOAT_EQ(log(list[0].second), log(c4));
- EXPECT_EQ(list.size(), 6);
- EXPECT_FLOAT_EQ(log(list.back().second / list.front().second), -97.7);
+ BOOST_CHECK(list[0].first == t4);
+ BOOST_CHECK_CLOSE(log(list[0].second), log(c4), 1e-4);
+ BOOST_CHECK_EQUAL(list.size(), 6);
+ BOOST_CHECK_CLOSE(log(list.back().second / list.front().second), -97.7, 1e-4);
}
-TEST_F(HGTest,ControlledKBest) {
+BOOST_AUTO_TEST_CASE(ControlledKBest) {
Hypergraph hg;
CreateHG(&hg);
vector<double> w(2); w[0]=0.4; w[1]=0.8;
@@ -101,11 +101,11 @@ TEST_F(HGTest,ControlledKBest) {
cerr << TD::GetString(d->yield) << endl;
++best;
}
- EXPECT_EQ(4, best);
+ BOOST_CHECK_EQUAL(4, best);
}
-TEST_F(HGTest,InsideScore) {
+BOOST_AUTO_TEST_CASE(InsideScore) {
SparseVector<double> wts;
wts.set_value(FD::Convert("f1"), 1.0);
Hypergraph hg;
@@ -117,18 +117,18 @@ TEST_F(HGTest,InsideScore) {
cerr << "cost: " << cost << "\n";
hg.PrintGraphviz();
prob_t inside = Inside<prob_t, EdgeProb>(hg);
- EXPECT_FLOAT_EQ(1.7934048, inside.as_float()); // computed by hand
+ BOOST_CHECK_CLOSE(1.7934048, inside.as_float(), 1e-4); // computed by hand
vector<prob_t> post;
inside = hg.ComputeBestPathThroughEdges(&post);
- EXPECT_FLOAT_EQ(-0.3, log(inside)); // computed by hand
- EXPECT_EQ(post.size(), 4);
+ BOOST_CHECK_CLOSE(-0.3, log(inside), 1e-4); // computed by hand
+ BOOST_CHECK_EQUAL(post.size(), 4);
for (int i = 0; i < 4; ++i) {
cerr << "edge post: " << log(post[i]) << '\t' << hg.edges_[i].rule_->AsString() << endl;
}
}
-TEST_F(HGTest,PruneInsideOutside) {
+BOOST_AUTO_TEST_CASE(PruneInsideOutside) {
SparseVector<double> wts;
wts.set_value(FD::Convert("Feature_1"), 1.0);
Hypergraph hg;
@@ -147,7 +147,7 @@ TEST_F(HGTest,PruneInsideOutside) {
hg.PrintGraphviz();
}
-TEST_F(HGTest,TestPruneEdges) {
+BOOST_AUTO_TEST_CASE(TestPruneEdges) {
Hypergraph hg;
CreateLatticeHG(&hg);
SparseVector<double> wts;
@@ -161,7 +161,7 @@ TEST_F(HGTest,TestPruneEdges) {
hg.PrintGraphviz();
}
-TEST_F(HGTest,TestIntersect) {
+BOOST_AUTO_TEST_CASE(TestIntersect) {
Hypergraph hg;
CreateHG_int(&hg);
SparseVector<double> wts;
@@ -178,7 +178,7 @@ TEST_F(HGTest,TestIntersect) {
cerr << TD::GetString(d->yield) << endl;
++best;
}
- EXPECT_EQ(4, best);
+ BOOST_CHECK_EQUAL(4, best);
Lattice target(2);
target[0].push_back(LatticeArc(TD::Convert("a"), 0.0, 1));
@@ -187,7 +187,7 @@ TEST_F(HGTest,TestIntersect) {
hg.PrintGraphviz();
}
-TEST_F(HGTest,TestPrune2) {
+BOOST_AUTO_TEST_CASE(TestPrune2) {
Hypergraph hg;
CreateHG_int(&hg);
SparseVector<double> wts;
@@ -202,7 +202,7 @@ TEST_F(HGTest,TestPrune2) {
cerr << "TODO: fix this pruning behavior-- the resulting HG should be empty!\n";
}
-TEST_F(HGTest,Sample) {
+BOOST_AUTO_TEST_CASE(Sample) {
Hypergraph hg;
CreateLatticeHG(&hg);
SparseVector<double> wts;
@@ -215,7 +215,7 @@ TEST_F(HGTest,Sample) {
hg.PrintGraphviz();
}
-TEST_F(HGTest,PLF) {
+BOOST_AUTO_TEST_CASE(PLF) {
Hypergraph hg;
string inplf = "((('haupt',-2.06655,1),('hauptgrund',-5.71033,2),),(('grund',-1.78709,1),),(('für\\'',0.1,1),),)";
HypergraphIO::ReadFromPLF(inplf, &hg);
@@ -226,10 +226,10 @@ TEST_F(HGTest,PLF) {
string outplf = HypergraphIO::AsPLF(hg);
cerr << " IN: " << inplf << endl;
cerr << "OUT: " << outplf << endl;
- EXPECT_EQ(inplf,outplf);
+ BOOST_CHECK_EQUAL(inplf,outplf);
}
-TEST_F(HGTest,PushWeightsToGoal) {
+BOOST_AUTO_TEST_CASE(PushWeightsToGoal) {
Hypergraph hg;
CreateHG(&hg);
vector<double> w(2); w[0]=0.4; w[1]=0.8;
@@ -243,7 +243,7 @@ TEST_F(HGTest,PushWeightsToGoal) {
hg.PrintGraphviz();
}
-TEST_F(HGTest,TestSpecialKBest) {
+BOOST_AUTO_TEST_CASE(TestSpecialKBest) {
Hypergraph hg;
CreateHGBalanced(&hg);
vector<double> w(1); w[0]=0;
@@ -259,7 +259,7 @@ TEST_F(HGTest,TestSpecialKBest) {
hg.PrintGraphviz();
}
-TEST_F(HGTest, TestGenericViterbi) {
+BOOST_AUTO_TEST_CASE(TestGenericViterbi) {
Hypergraph hg;
CreateHG_tiny(&hg);
SparseVector<double> wts;
@@ -270,11 +270,11 @@ TEST_F(HGTest, TestGenericViterbi) {
const prob_t prob = ViterbiESentence(hg, &trans);
cerr << TD::GetString(trans) << "\n";
cerr << "prob: " << prob << "\n";
- EXPECT_FLOAT_EQ(-80.839996, log(prob));
- EXPECT_EQ("X <s>", TD::GetString(trans));
+ BOOST_CHECK_CLOSE(-80.839996, log(prob), 1e-4);
+ BOOST_CHECK_EQUAL("X <s>", TD::GetString(trans));
}
-TEST_F(HGTest, TestGenericInside) {
+BOOST_AUTO_TEST_CASE(TestGenericInside) {
Hypergraph hg;
CreateTinyLatticeHG(&hg);
SparseVector<double> wts;
@@ -282,16 +282,16 @@ TEST_F(HGTest, TestGenericInside) {
hg.Reweight(wts);
vector<prob_t> inside;
prob_t ins = Inside<prob_t, EdgeProb>(hg, &inside);
- EXPECT_FLOAT_EQ(1.7934048, ins.as_float()); // computed by hand
+ BOOST_CHECK_CLOSE(1.7934048, ins.as_float(), 1e-4); // computed by hand
vector<prob_t> outside;
Outside<prob_t, EdgeProb>(hg, inside, &outside);
- EXPECT_EQ(3, outside.size());
- EXPECT_FLOAT_EQ(1.7934048, outside[0].as_float());
- EXPECT_FLOAT_EQ(1.3114071, outside[1].as_float());
- EXPECT_FLOAT_EQ(1.0, outside[2].as_float());
+ BOOST_CHECK_EQUAL(3, outside.size());
+ BOOST_CHECK_CLOSE(1.7934048, outside[0].as_float(), 1e-4);
+ BOOST_CHECK_CLOSE(1.3114071, outside[1].as_float(), 1e-4);
+ BOOST_CHECK_CLOSE(1.0, outside[2].as_float(), 1e-4);
}
-TEST_F(HGTest,TestGenericInside2) {
+BOOST_AUTO_TEST_CASE(TestGenericInside2) {
Hypergraph hg;
CreateHG(&hg);
SparseVector<double> wts;
@@ -303,21 +303,21 @@ TEST_F(HGTest,TestGenericInside2) {
Outside<prob_t, EdgeProb>(hg, inside, &outside);
for (int i = 0; i < hg.nodes_.size(); ++i)
cerr << i << "\t" << log(inside[i]) << "\t" << log(outside[i]) << endl;
- EXPECT_FLOAT_EQ(0, log(inside[0]));
- EXPECT_FLOAT_EQ(-1.7861683, log(outside[0]));
- EXPECT_FLOAT_EQ(-0.4, log(inside[1]));
- EXPECT_FLOAT_EQ(-1.3861683, log(outside[1]));
- EXPECT_FLOAT_EQ(-0.8, log(inside[2]));
- EXPECT_FLOAT_EQ(-0.986168, log(outside[2]));
- EXPECT_FLOAT_EQ(-0.96, log(inside[3]));
- EXPECT_FLOAT_EQ(-0.8261683, log(outside[3]));
- EXPECT_FLOAT_EQ(-1.562512, log(inside[4]));
- EXPECT_FLOAT_EQ(-0.22365622, log(outside[4]));
- EXPECT_FLOAT_EQ(-1.7861683, log(inside[5]));
- EXPECT_FLOAT_EQ(0, log(outside[5]));
+ BOOST_CHECK_CLOSE(0, log(inside[0]), 1e-4);
+ BOOST_CHECK_CLOSE(-1.7861683, log(outside[0]), 1e-4);
+ BOOST_CHECK_CLOSE(-0.4, log(inside[1]), 1e-4);
+ BOOST_CHECK_CLOSE(-1.3861683, log(outside[1]), 1e-4);
+ BOOST_CHECK_CLOSE(-0.8, log(inside[2]), 1e-4);
+ BOOST_CHECK_CLOSE(-0.986168, log(outside[2]), 1e-4);
+ BOOST_CHECK_CLOSE(-0.96, log(inside[3]), 1e-4);
+ BOOST_CHECK_CLOSE(-0.8261683, log(outside[3]), 1e-4);
+ BOOST_CHECK_CLOSE(-1.562512, log(inside[4]), 1e-4);
+ BOOST_CHECK_CLOSE(-0.22365622, log(outside[4]), 1e-4);
+ BOOST_CHECK_CLOSE(-1.7861683, log(inside[5]), 1e-4);
+ BOOST_CHECK_CLOSE(0, log(outside[5]), 1e-4);
}
-TEST_F(HGTest,TestAddExpectations) {
+BOOST_AUTO_TEST_CASE(TestAddExpectations) {
Hypergraph hg;
CreateHG(&hg);
SparseVector<double> wts;
@@ -327,13 +327,13 @@ TEST_F(HGTest,TestAddExpectations) {
SparseVector<prob_t> feat_exps;
prob_t z = InsideOutside<prob_t, EdgeProb,
SparseVector<prob_t>, EdgeFeaturesAndProbWeightFunction>(hg, &feat_exps);
- EXPECT_FLOAT_EQ(-2.5439765, (feat_exps.value(FD::Convert("f1")) / z).as_float());
- EXPECT_FLOAT_EQ(-2.6357865, (feat_exps.value(FD::Convert("f2")) / z).as_float());
+ BOOST_CHECK_CLOSE(-2.5439765, (feat_exps.value(FD::Convert("f1")) / z).as_float(), 1e-4);
+ BOOST_CHECK_CLOSE(-2.6357865, (feat_exps.value(FD::Convert("f2")) / z).as_float(), 1e-4);
cerr << feat_exps << endl;
cerr << "Z=" << z << endl;
}
-TEST_F(HGTest, Small) {
+BOOST_AUTO_TEST_CASE(Small) {
Hypergraph hg;
CreateSmallHG(&hg);
SparseVector<double> wts;
@@ -352,19 +352,19 @@ TEST_F(HGTest, Small) {
cerr << "cost: " << cost << "\n";
vector<prob_t> post;
prob_t c2 = Inside<prob_t, ScaledEdgeProb>(hg, NULL, ScaledEdgeProb(0.6));
- EXPECT_FLOAT_EQ(2.1431036, log(c2));
+ BOOST_CHECK_CLOSE(2.1431036, log(c2), 1e-4);
}
-TEST_F(HGTest, JSONTest) {
+BOOST_AUTO_TEST_CASE(JSONTest) {
ostringstream os;
JSONParser::WriteEscapedString("\"I don't know\", she said.", &os);
- EXPECT_EQ("\"\\\"I don't know\\\", she said.\"", os.str());
+ BOOST_CHECK_EQUAL("\"\\\"I don't know\\\", she said.\"", os.str());
ostringstream os2;
JSONParser::WriteEscapedString("yes", &os2);
- EXPECT_EQ("\"yes\"", os2.str());
+ BOOST_CHECK_EQUAL("\"yes\"", os2.str());
}
-TEST_F(HGTest, TestGenericKBest) {
+BOOST_AUTO_TEST_CASE(TestGenericKBest) {
Hypergraph hg;
CreateHG(&hg);
//CreateHGBalanced(&hg);
@@ -386,7 +386,7 @@ TEST_F(HGTest, TestGenericKBest) {
}
}
-TEST_F(HGTest, TestReadWriteHG) {
+BOOST_AUTO_TEST_CASE(TestReadWriteHG) {
Hypergraph hg,hg2;
CreateHG(&hg);
hg.edges_.front().j_ = 23;
@@ -395,12 +395,9 @@ TEST_F(HGTest, TestReadWriteHG) {
HypergraphIO::WriteToJSON(hg, false, &os);
istringstream is(os.str());
HypergraphIO::ReadFromJSON(&is, &hg2);
- EXPECT_EQ(hg2.NumberOfPaths(), hg.NumberOfPaths());
- EXPECT_EQ(hg2.edges_.front().j_, 23);
- EXPECT_EQ(hg2.edges_.back().prev_i_, 99);
+ BOOST_CHECK_EQUAL(hg2.NumberOfPaths(), hg.NumberOfPaths());
+ BOOST_CHECK_EQUAL(hg2.edges_.front().j_, 23);
+ BOOST_CHECK_EQUAL(hg2.edges_.back().prev_i_, 99);
}
-int main(int argc, char **argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/decoder/hg_test.h b/decoder/hg_test.h
index 3da6533c..043f970a 100644
--- a/decoder/hg_test.h
+++ b/decoder/hg_test.h
@@ -5,10 +5,7 @@
#include "hg.h"
#include "hg_io.h"
#include <sstream>
-#include <gtest/gtest.h>
-using namespace std;
-using namespace testing;
#pragma GCC diagnostic ignored "-Wunused-variable"
namespace {
@@ -25,7 +22,7 @@ Name perro_wts="SameFirstLetter 1 LongerThanPrev 1 ShorterThanPrev 1 GlueTop 0.0
}
// you can inherit from this or just use the static methods
-struct HGSetup : public Test {
+struct HGSetup {
enum {
HG,
HG_int,
@@ -43,11 +40,11 @@ struct HGSetup : public Test {
static void Json(Hypergraph *hg,std::string const& json) {
std::istringstream i(json);
- ASSERT_TRUE(HypergraphIO::ReadFromJSON(&i, hg));
+ HypergraphIO::ReadFromJSON(&i, hg);
}
static void JsonFile(Hypergraph *hg,std::string f) {
ReadFile rf(f);
- ASSERT_TRUE(HypergraphIO::ReadFromJSON(rf.stream(), hg)) << "read from HG file "<<f;
+ HypergraphIO::ReadFromJSON(rf.stream(), hg);
}
static void JsonTestFile(Hypergraph *hg,std::string n) {
JsonFile(hg,"test_data/"+n);
diff --git a/decoder/parser_test.cc b/decoder/parser_test.cc
index da1fbd89..e2916e44 100644
--- a/decoder/parser_test.cc
+++ b/decoder/parser_test.cc
@@ -1,8 +1,7 @@
-#include <cassert>
-#include <iostream>
-#include <fstream>
-#include <vector>
-#include <gtest/gtest.h>
+#define BOOST_TEST_MODULE ParseTest
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include "lattice.h"
#include "hg.h"
#include "trule.h"
#include "bottom_up_parser.h"
@@ -10,13 +9,7 @@
using namespace std;
-class ChartTest : public testing::Test {
- protected:
- virtual void SetUp() { }
- virtual void TearDown() { }
-};
-
-TEST_F(ChartTest,LanguageModel) {
+BOOST_AUTO_TEST_CASE(Parse) {
LatticeArc a(TD::Convert("ein"), 0.0, 1);
LatticeArc b(TD::Convert("haus"), 0.0, 1);
Lattice lattice(2);
@@ -29,7 +22,3 @@ TEST_F(ChartTest,LanguageModel) {
parser.Parse(lattice, &forest);
}
-int main(int argc, char **argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/decoder/trule_test.cc b/decoder/trule_test.cc
index dfb6d417..0cb7e2e8 100644
--- a/decoder/trule_test.cc
+++ b/decoder/trule_test.cc
@@ -1,19 +1,14 @@
#include "trule.h"
-#include <gtest/gtest.h>
-#include <cassert>
+#define BOOST_TEST_MODULE TRuleTest
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
#include <iostream>
#include "tdict.h"
using namespace std;
-class TRuleTest : public testing::Test {
- protected:
- virtual void SetUp() { }
- virtual void TearDown() { }
-};
-
-TEST_F(TRuleTest,TestFSubstitute) {
+BOOST_AUTO_TEST_CASE(TestFSubstitute) {
TRule r1("[X] ||| ob [X,1] [X,2] sah . ||| whether [X,1] saw [X,2] . ||| 0.99");
TRule r2("[X] ||| ich ||| i ||| 1.0");
TRule r3("[X] ||| ihn ||| him ||| 1.0");
@@ -32,34 +27,29 @@ TEST_F(TRuleTest,TestFSubstitute) {
assert(TD::GetString(res) == "ob ich ihn sah .");
}
-TEST_F(TRuleTest,TestPhrasetableRule) {
+BOOST_AUTO_TEST_CASE(TestPhrasetableRule) {
TRulePtr t(TRule::CreateRulePhrasetable("gato ||| cat ||| PhraseModel_0=-23.2;Foo=1;Bar=12"));
cerr << t->AsString() << endl;
assert(t->scores_.size() == 3);
};
-TEST_F(TRuleTest,TestMonoRule) {
+BOOST_AUTO_TEST_CASE(TestMonoRule) {
TRulePtr m(TRule::CreateRuleMonolingual("[LHS] ||| term1 [NT] term2 [NT2] [NT3]"));
assert(m->Arity() == 3);
cerr << m->AsString() << endl;
TRulePtr m2(TRule::CreateRuleMonolingual("[LHS] ||| term1 [NT] term2 [NT2] [NT3] ||| Feature1=0.23"));
assert(m2->Arity() == 3);
cerr << m2->AsString() << endl;
- EXPECT_FLOAT_EQ(m2->scores_.value(FD::Convert("Feature1")), 0.23);
+ BOOST_CHECK_CLOSE(m2->scores_.value(FD::Convert("Feature1")), 0.23, 1e-6);
}
-TEST_F(TRuleTest,TestRuleR) {
+BOOST_AUTO_TEST_CASE(TestRuleR) {
TRule t6;
t6.ReadFromString("[X] ||| den [X,1] sah [X,2] . ||| [X,2] saw the [X,1] . ||| 0.12321 0.23232 0.121");
cerr << "TEXT: " << t6.AsString() << endl;
- EXPECT_EQ(t6.Arity(), 2);
- EXPECT_EQ(t6.e_[0], -1);
- EXPECT_EQ(t6.e_[3], 0);
-}
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
+ BOOST_CHECK_EQUAL(t6.Arity(), 2);
+ BOOST_CHECK_EQUAL(t6.e_[0], -1);
+ BOOST_CHECK_EQUAL(t6.e_[3], 0);
}
diff --git a/dpmert/Makefile.am b/dpmert/Makefile.am
index 2676fb50..00768271 100644
--- a/dpmert/Makefile.am
+++ b/dpmert/Makefile.am
@@ -5,17 +5,15 @@ bin_PROGRAMS = \
sentserver \
sentclient
-if HAVE_GTEST
noinst_PROGRAMS = \
lo_test
TESTS = lo_test
-endif
sentserver_SOURCES = sentserver.c
-sentserver_LDFLAGS = -all-static -pthread
+sentserver_LDFLAGS = -pthread
sentclient_SOURCES = sentclient.c
-sentclient_LDFLAGS = -all-static -pthread
+sentclient_LDFLAGS = -pthread
mr_dpmert_generate_mapper_input_SOURCES = mr_dpmert_generate_mapper_input.cc line_optimizer.cc
mr_dpmert_generate_mapper_input_LDADD = $(top_srcdir)/decoder/libcdec.a $(top_srcdir)/mteval/libmteval.a $(top_srcdir)/utils/libutils.a -lz
@@ -30,6 +28,6 @@ mr_dpmert_reduce_SOURCES = error_surface.cc ces.cc mr_dpmert_reduce.cc line_opti
mr_dpmert_reduce_LDADD = $(top_srcdir)/decoder/libcdec.a $(top_srcdir)/mteval/libmteval.a $(top_srcdir)/utils/libutils.a -lz
lo_test_SOURCES = lo_test.cc ces.cc mert_geometry.cc error_surface.cc line_optimizer.cc
-lo_test_LDADD = $(GTEST_LDFLAGS) $(GTEST_LIBS) $(top_srcdir)/decoder/libcdec.a $(top_srcdir)/mteval/libmteval.a $(top_srcdir)/utils/libutils.a -lz
+lo_test_LDADD = $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) $(top_srcdir)/decoder/libcdec.a $(top_srcdir)/mteval/libmteval.a $(top_srcdir)/utils/libutils.a -lz
-AM_CPPFLAGS = -W -Wall -Wno-sign-compare $(GTEST_CPPFLAGS) -I$(top_srcdir)/utils -I$(top_srcdir)/decoder -I$(top_srcdir)/mteval
+AM_CPPFLAGS = -DBOOST_TEST_DYN_LINK -W -Wall -Wno-sign-compare $(GTEST_CPPFLAGS) -I$(top_srcdir)/utils -I$(top_srcdir)/decoder -I$(top_srcdir)/mteval
diff --git a/dpmert/lo_test.cc b/dpmert/lo_test.cc
index 5d90aabb..d47a95b5 100644
--- a/dpmert/lo_test.cc
+++ b/dpmert/lo_test.cc
@@ -1,9 +1,12 @@
+#define BOOST_TEST_MODULE LineOptimizerTest
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+
#include <cmath>
#include <iostream>
#include <fstream>
#include <boost/shared_ptr.hpp>
-#include <gtest/gtest.h>
#include "ns.h"
#include "ns_docscorer.h"
@@ -20,12 +23,6 @@
using namespace std;
-class OptTest : public testing::Test {
- protected:
- virtual void SetUp() { }
- virtual void TearDown() { }
-};
-
const char* ref11 = "australia reopens embassy in manila";
const char* ref12 = "( afp , manila , january 2 ) australia reopened its embassy in the philippines today , which was shut down about seven weeks ago due to what was described as a specific threat of a terrorist attack .";
const char* ref21 = "australia reopened manila embassy";
@@ -35,14 +32,14 @@ const char* ref32 = "( afp report from manila , january 2 ) australia reopened i
const char* ref41 = "australia to re - open its embassy to manila";
const char* ref42 = "( afp , manila , thursday ) australia reopens its embassy to manila , which was closed for the so - called \" clear \" threat of terrorist attack 7 weeks ago .";
-TEST_F(OptTest, TestCheckNaN) {
+BOOST_AUTO_TEST_CASE( TestCheckNaN) {
double x = 0;
double y = 0;
double z = x / y;
- EXPECT_EQ(true, isnan(z));
+ BOOST_CHECK_EQUAL(true, isnan(z));
}
-TEST_F(OptTest,TestConvexHull) {
+BOOST_AUTO_TEST_CASE(TestConvexHull) {
boost::shared_ptr<MERTPoint> a1(new MERTPoint(-1, 0));
boost::shared_ptr<MERTPoint> b1(new MERTPoint(1, 0));
boost::shared_ptr<MERTPoint> a2(new MERTPoint(-1, 1));
@@ -55,10 +52,10 @@ TEST_F(OptTest,TestConvexHull) {
ConvexHull c = a;
c *= b;
cerr << a << " (*) " << b << " = " << c << endl;
- EXPECT_EQ(3, c.size());
+ BOOST_CHECK_EQUAL(3, c.size());
}
-TEST_F(OptTest,TestConvexHullInside) {
+BOOST_AUTO_TEST_CASE(TestConvexHullInside) {
const string json = "{\"rules\":[1,\"[X] ||| a\",2,\"[X] ||| A [1]\",3,\"[X] ||| c\",4,\"[X] ||| C [1]\",5,\"[X] ||| [1] B [2]\",6,\"[X] ||| [1] b [2]\",7,\"[X] ||| X [1]\",8,\"[X] ||| Z [1]\"],\"features\":[\"f1\",\"f2\",\"Feature_1\",\"Feature_0\",\"Model_0\",\"Model_1\",\"Model_2\",\"Model_3\",\"Model_4\",\"Model_5\",\"Model_6\",\"Model_7\"],\"edges\":[{\"tail\":[],\"feats\":[],\"rule\":1}],\"node\":{\"in_edges\":[0]},\"edges\":[{\"tail\":[0],\"feats\":[0,-0.8,1,-0.1],\"rule\":2}],\"node\":{\"in_edges\":[1]},\"edges\":[{\"tail\":[],\"feats\":[1,-1],\"rule\":3}],\"node\":{\"in_edges\":[2]},\"edges\":[{\"tail\":[2],\"feats\":[0,-0.2,1,-0.1],\"rule\":4}],\"node\":{\"in_edges\":[3]},\"edges\":[{\"tail\":[1,3],\"feats\":[0,-1.2,1,-0.2],\"rule\":5},{\"tail\":[1,3],\"feats\":[0,-0.5,1,-1.3],\"rule\":6}],\"node\":{\"in_edges\":[4,5]},\"edges\":[{\"tail\":[4],\"feats\":[0,-0.5,1,-0.8],\"rule\":7},{\"tail\":[4],\"feats\":[0,-0.7,1,-0.9],\"rule\":8}],\"node\":{\"in_edges\":[6,7]}}";
Hypergraph hg;
istringstream instr(json);
@@ -99,7 +96,7 @@ TEST_F(OptTest,TestConvexHullInside) {
}
}
-TEST_F(OptTest, TestS1) {
+BOOST_AUTO_TEST_CASE( TestS1) {
int fPhraseModel_0 = FD::Convert("PhraseModel_0");
int fPhraseModel_1 = FD::Convert("PhraseModel_1");
int fPhraseModel_2 = FD::Convert("PhraseModel_2");
@@ -177,7 +174,7 @@ TEST_F(OptTest, TestS1) {
double m = LineOptimizer::LineOptimize(metric,es, LineOptimizer::MAXIMIZE_SCORE, &score);
clock_t t_opt=clock();
cerr << "line optimizer returned: " << m << " (SCORE=" << score << ")\n";
- EXPECT_FLOAT_EQ(0.48719698, score);
+ BOOST_CHECK_CLOSE(0.48719698, score, 1e-5);
SparseVector<double> res = axis;
res *= m;
res += wts;
@@ -193,7 +190,7 @@ TEST_F(OptTest, TestS1) {
cerr << TD::GetString(t2) << endl;
}
-TEST_F(OptTest,TestZeroOrigin) {
+BOOST_AUTO_TEST_CASE(TestZeroOrigin) {
const string json = "{\"rules\":[1,\"[X7] ||| blA ||| without ||| LHSProb=3.92173 LexE2F=2.90799 LexF2E=1.85003 GenerativeProb=10.5381 RulePenalty=1 XFE=2.77259 XEF=0.441833 LabelledEF=2.63906 LabelledFE=4.96981 LogRuleCount=0.693147\",2,\"[X7] ||| blA ||| except ||| LHSProb=4.92173 LexE2F=3.90799 LexF2E=1.85003 GenerativeProb=11.5381 RulePenalty=1 XFE=2.77259 XEF=1.44183 LabelledEF=2.63906 LabelledFE=4.96981 LogRuleCount=1.69315\",3,\"[S] ||| [X7,1] ||| [1] ||| GlueTop=1\",4,\"[X28] ||| EnwAn ||| title ||| LHSProb=3.96802 LexE2F=2.22462 LexF2E=1.83258 GenerativeProb=10.0863 RulePenalty=1 XFE=0 XEF=1.20397 LabelledEF=1.20397 LabelledFE=-1.98341e-08 LogRuleCount=1.09861\",5,\"[X0] ||| EnwAn ||| funny ||| LHSProb=3.98479 LexE2F=1.79176 LexF2E=3.21888 GenerativeProb=11.1681 RulePenalty=1 XFE=0 XEF=2.30259 LabelledEF=2.30259 LabelledFE=0 LogRuleCount=0 SingletonRule=1\",6,\"[X8] ||| [X7,1] EnwAn ||| entitled [1] ||| LHSProb=3.82533 LexE2F=3.21888 LexF2E=2.52573 GenerativeProb=11.3276 RulePenalty=1 XFE=1.20397 XEF=1.20397 LabelledEF=2.30259 LabelledFE=2.30259 LogRuleCount=0 SingletonRule=1\",7,\"[S] ||| [S,1] [X28,2] ||| [1] [2] ||| Glue=1\",8,\"[S] ||| [S,1] [X0,2] ||| [1] [2] ||| Glue=1\",9,\"[S] ||| [X8,1] ||| [1] ||| GlueTop=1\",10,\"[Goal] ||| [S,1] ||| [1]\"],\"features\":[\"PassThrough\",\"Glue\",\"GlueTop\",\"LanguageModel\",\"WordPenalty\",\"LHSProb\",\"LexE2F\",\"LexF2E\",\"GenerativeProb\",\"RulePenalty\",\"XFE\",\"XEF\",\"LabelledEF\",\"LabelledFE\",\"LogRuleCount\",\"SingletonRule\"],\"edges\":[{\"tail\":[],\"spans\":[0,1,-1,-1],\"feats\":[5,3.92173,6,2.90799,7,1.85003,8,10.5381,9,1,10,2.77259,11,0.441833,12,2.63906,13,4.96981,14,0.693147],\"rule\":1},{\"tail\":[],\"spans\":[0,1,-1,-1],\"feats\":[5,4.92173,6,3.90799,7,1.85003,8,11.5381,9,1,10,2.77259,11,1.44183,12,2.63906,13,4.96981,14,1.69315],\"rule\":2}],\"node\":{\"in_edges\":[0,1],\"cat\":\"X7\"},\"edges\":[{\"tail\":[0],\"spans\":[0,1,-1,-1],\"feats\":[2,1],\"rule\":3}],\"node\":{\"in_edges\":[2],\"cat\":\"S\"},\"edges\":[{\"tail\":[],\"spans\":[1,2,-1,-1],\"feats\":[5,3.96802,6,2.22462,7,1.83258,8,10.0863,9,1,11,1.20397,12,1.20397,13,-1.98341e-08,14,1.09861],\"rule\":4}],\"node\":{\"in_edges\":[3],\"cat\":\"X28\"},\"edges\":[{\"tail\":[],\"spans\":[1,2,-1,-1],\"feats\":[5,3.98479,6,1.79176,7,3.21888,8,11.1681,9,1,11,2.30259,12,2.30259,15,1],\"rule\":5}],\"node\":{\"in_edges\":[4],\"cat\":\"X0\"},\"edges\":[{\"tail\":[0],\"spans\":[0,2,-1,-1],\"feats\":[5,3.82533,6,3.21888,7,2.52573,8,11.3276,9,1,10,1.20397,11,1.20397,12,2.30259,13,2.30259,15,1],\"rule\":6}],\"node\":{\"in_edges\":[5],\"cat\":\"X8\"},\"edges\":[{\"tail\":[1,2],\"spans\":[0,2,-1,-1],\"feats\":[1,1],\"rule\":7},{\"tail\":[1,3],\"spans\":[0,2,-1,-1],\"feats\":[1,1],\"rule\":8},{\"tail\":[4],\"spans\":[0,2,-1,-1],\"feats\":[2,1],\"rule\":9}],\"node\":{\"in_edges\":[6,7,8],\"cat\":\"S\"},\"edges\":[{\"tail\":[5],\"spans\":[0,2,-1,-1],\"feats\":[],\"rule\":10}],\"node\":{\"in_edges\":[9],\"cat\":\"Goal\"}}";
Hypergraph hg;
istringstream instr(json);
@@ -228,8 +225,3 @@ TEST_F(OptTest,TestZeroOrigin) {
ComputeErrorSurface(*scorer1, envs[0], &es[0], metric, hg);
}
-int main(int argc, char **argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
-
diff --git a/gi/pf/cfg_wfst_composer.cc b/gi/pf/cfg_wfst_composer.cc
index 20520c81..517446d4 100644
--- a/gi/pf/cfg_wfst_composer.cc
+++ b/gi/pf/cfg_wfst_composer.cc
@@ -4,6 +4,7 @@
#include <fstream>
#include <map>
#include <queue>
+#include <tr1/unordered_map>
#include <tr1/unordered_set>
#include <boost/shared_ptr.hpp>
diff --git a/mteval/Makefile.am b/mteval/Makefile.am
index e7126675..8d844e24 100644
--- a/mteval/Makefile.am
+++ b/mteval/Makefile.am
@@ -2,11 +2,9 @@ bin_PROGRAMS = \
fast_score \
mbr_kbest
-if HAVE_GTEST
noinst_PROGRAMS = \
scorer_test
TESTS = scorer_test
-endif
noinst_LIBRARIES = libmteval.a
@@ -19,6 +17,6 @@ mbr_kbest_SOURCES = mbr_kbest.cc
mbr_kbest_LDADD = libmteval.a $(top_srcdir)/utils/libutils.a -lz
scorer_test_SOURCES = scorer_test.cc
-scorer_test_LDADD = libmteval.a $(GTEST_LDFLAGS) $(GTEST_LIBS) $(top_srcdir)/utils/libutils.a -lz
+scorer_test_LDADD = libmteval.a $(top_srcdir)/utils/libutils.a $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) -lz
-AM_CPPFLAGS = -W -Wall -Wno-sign-compare $(GTEST_CPPFLAGS) -I$(top_srcdir)/utils
+AM_CPPFLAGS = -DBOOST_TEST_DYN_LINK -W -Wall -Wno-sign-compare $(GTEST_CPPFLAGS) -I$(top_srcdir)/utils
diff --git a/mteval/scorer_test.cc b/mteval/scorer_test.cc
index 73159557..0e400a3a 100644
--- a/mteval/scorer_test.cc
+++ b/mteval/scorer_test.cc
@@ -1,7 +1,7 @@
#include <iostream>
-#include <fstream>
-#include <valarray>
-#include <gtest/gtest.h>
+#define BOOST_TEST_MODULE ScoreTest
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
#include "ns.h"
#include "tdict.h"
@@ -11,9 +11,8 @@
using namespace std;
-class ScorerTest : public testing::Test {
- protected:
- virtual void SetUp() {
+struct Stuff {
+ Stuff() {
refs0.resize(4);
refs1.resize(4);
TD::ConvertSentence("export of high-tech products in guangdong in first two months this year reached 3.76 billion us dollars", &refs0[0]);
@@ -28,15 +27,15 @@ class ScorerTest : public testing::Test {
TD::ConvertSentence("xinhua news agency , guangzhou , 16th of march ( reporter chen ) -- latest statistics suggest that guangdong exports new advanced technology product totals $ 3.76 million , 34.8 percent last corresponding period and accounts for 25.5 percent of the total export province .", &hyp2);
}
- virtual void TearDown() { }
-
- vector<vector<WordID> > refs0;
- vector<vector<WordID> > refs1;
- vector<WordID> hyp1;
- vector<WordID> hyp2;
+ vector<vector<WordID> > refs0;
+ vector<vector<WordID> > refs1;
+ vector<WordID> hyp1;
+ vector<WordID> hyp2;
};
-TEST_F(ScorerTest, TestCreateFromFiles) {
+BOOST_FIXTURE_TEST_SUITE( s, Stuff );
+
+BOOST_AUTO_TEST_CASE(TestCreateFromFiles) {
vector<string> files;
files.push_back("test_data/re.txt.0");
files.push_back("test_data/re.txt.1");
@@ -45,19 +44,19 @@ TEST_F(ScorerTest, TestCreateFromFiles) {
DocScorer ds(IBM_BLEU, files);
}
-TEST_F(ScorerTest, TestBLEUScorer) {
+BOOST_AUTO_TEST_CASE(TestBLEUScorer) {
ScorerP s1 = SentenceScorer::CreateSentenceScorer(IBM_BLEU, refs0);
ScorerP s2 = SentenceScorer::CreateSentenceScorer(IBM_BLEU, refs1);
ScoreP b1 = s1->ScoreCandidate(hyp1);
- EXPECT_FLOAT_EQ(0.23185077, b1->ComputeScore());
+ BOOST_CHECK_CLOSE(0.23185077, b1->ComputeScore(), 1e-4);
ScoreP b2 = s2->ScoreCandidate(hyp2);
- EXPECT_FLOAT_EQ(0.38101241, b2->ComputeScore());
+ BOOST_CHECK_CLOSE(0.38101241, b2->ComputeScore(), 1e-4);
b1->PlusEquals(*b2);
- EXPECT_FLOAT_EQ(0.348854, b1->ComputeScore());
- EXPECT_FALSE(b1->IsAdditiveIdentity());
+ BOOST_CHECK_CLOSE(0.348854, b1->ComputeScore(), 1e-4);
+ BOOST_CHECK(!b1->IsAdditiveIdentity());
string details;
b1->ScoreDetails(&details);
- EXPECT_EQ("BLEU = 34.89, 81.5|50.8|29.5|18.6 (brev=0.898)", details);
+ BOOST_CHECK_EQUAL("BLEU = 34.89, 81.5|50.8|29.5|18.6 (brev=0.898)", details);
cerr << details << endl;
string enc;
b1->Encode(&enc);
@@ -66,13 +65,13 @@ TEST_F(ScorerTest, TestBLEUScorer) {
cerr << "Encoded BLEU score size: " << enc.size() << endl;
b3->ScoreDetails(&details);
cerr << details << endl;
- EXPECT_FALSE(b3->IsAdditiveIdentity());
- EXPECT_EQ("BLEU = 34.89, 81.5|50.8|29.5|18.6 (brev=0.898)", details);
+ BOOST_CHECK(!b3->IsAdditiveIdentity());
+ BOOST_CHECK_EQUAL("BLEU = 34.89, 81.5|50.8|29.5|18.6 (brev=0.898)", details);
ScoreP bz = b3->GetZero();
- EXPECT_TRUE(bz->IsAdditiveIdentity());
+ BOOST_CHECK(bz->IsAdditiveIdentity());
}
-TEST_F(ScorerTest, TestTERScorer) {
+BOOST_AUTO_TEST_CASE(TestTERScorer) {
ScorerP s1 = SentenceScorer::CreateSentenceScorer(TER, refs0);
ScorerP s2 = SentenceScorer::CreateSentenceScorer(TER, refs1);
string details;
@@ -88,19 +87,19 @@ TEST_F(ScorerTest, TestTERScorer) {
cerr << t1->ComputeScore() << endl;
t1->ScoreDetails(&details);
cerr << "DETAILS: " << details << endl;
- EXPECT_EQ("TER = 44.16, 4| 8| 16| 6 (len=77)", details);
+ BOOST_CHECK_EQUAL("TER = 44.16, 4| 8| 16| 6 (len=77)", details);
string enc;
t1->Encode(&enc);
ScoreP t3 = SentenceScorer::CreateScoreFromString(TER, enc);
details.clear();
t3->ScoreDetails(&details);
- EXPECT_EQ("TER = 44.16, 4| 8| 16| 6 (len=77)", details);
- EXPECT_FALSE(t3->IsAdditiveIdentity());
+ BOOST_CHECK_EQUAL("TER = 44.16, 4| 8| 16| 6 (len=77)", details);
+ BOOST_CHECK(!t3->IsAdditiveIdentity());
ScoreP tz = t3->GetZero();
- EXPECT_TRUE(tz->IsAdditiveIdentity());
+ BOOST_CHECK(tz->IsAdditiveIdentity());
}
-TEST_F(ScorerTest, TestTERScorerSimple) {
+BOOST_AUTO_TEST_CASE(TestTERScorerSimple) {
vector<vector<WordID> > ref(1);
TD::ConvertSentence("1 2 3 A B", &ref[0]);
vector<WordID> hyp;
@@ -112,7 +111,7 @@ TEST_F(ScorerTest, TestTERScorerSimple) {
cerr << "DETAILS: " << details << endl;
}
-TEST_F(ScorerTest, TestSERScorerSimple) {
+BOOST_AUTO_TEST_CASE(TestSERScorerSimple) {
vector<vector<WordID> > ref(1);
TD::ConvertSentence("A B C D", &ref[0]);
vector<WordID> hyp1;
@@ -132,7 +131,7 @@ TEST_F(ScorerTest, TestSERScorerSimple) {
cerr << "DETAILS: " << details << endl;
}
-TEST_F(ScorerTest, TestCombiScorer) {
+BOOST_AUTO_TEST_CASE(TestCombiScorer) {
ScorerP s1 = SentenceScorer::CreateSentenceScorer(BLEU_minus_TER_over_2, refs0);
string details;
ScoreP t1 = s1->ScoreCandidate(hyp1);
@@ -146,16 +145,16 @@ TEST_F(ScorerTest, TestCombiScorer) {
t2->ScoreDetails(&details);
cerr << "DETAILS: " << details << endl;
ScoreP cz = t2->GetZero();
- EXPECT_FALSE(t2->IsAdditiveIdentity());
- EXPECT_TRUE(cz->IsAdditiveIdentity());
+ BOOST_CHECK(!t2->IsAdditiveIdentity());
+ BOOST_CHECK(cz->IsAdditiveIdentity());
cz->PlusEquals(*t2);
- EXPECT_FALSE(cz->IsAdditiveIdentity());
+ BOOST_CHECK(!cz->IsAdditiveIdentity());
string d2;
cz->ScoreDetails(&d2);
- EXPECT_EQ(d2, details);
+ BOOST_CHECK_EQUAL(d2, details);
}
-TEST_F(ScorerTest, AERTest) {
+BOOST_AUTO_TEST_CASE(AERTest) {
vector<vector<WordID> > refs0(1);
TD::ConvertSentence("0-0 2-1 1-2 3-3", &refs0[0]);
@@ -174,10 +173,10 @@ TEST_F(ScorerTest, AERTest) {
string d2;
y->ScoreDetails(&d2);
cerr << d2 << endl;
- EXPECT_EQ(d2, details);
+ BOOST_CHECK_EQUAL(d2, details);
}
-TEST_F(ScorerTest, Kernel) {
+BOOST_AUTO_TEST_CASE(Kernel) {
for (int i = 1; i < 10; ++i) {
const float l = (i / 10.0);
float f = ssk<4>(refs0[0], hyp1, l) +
@@ -204,7 +203,7 @@ TEST_F(ScorerTest, Kernel) {
}
}
-TEST_F(ScorerTest, NewScoreAPI) {
+BOOST_AUTO_TEST_CASE(NewScoreAPI) {
//EvaluationMetric* metric = EvaluationMetric::Instance("IBM_BLEU");
//EvaluationMetric* metric = EvaluationMetric::Instance("METEOR");
EvaluationMetric* metric = EvaluationMetric::Instance("COMB:IBM_BLEU=0.5;TER=-0.5");
@@ -223,8 +222,4 @@ TEST_F(ScorerTest, NewScoreAPI) {
//cerr << metric->ComputeScore(statse) << endl;
}
-int main(int argc, char **argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
-
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/utils/Makefile.am b/utils/Makefile.am
index 2fc6ae21..46650c75 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -4,7 +4,6 @@ bin_PROGRAMS = reconstruct_weights atools
noinst_PROGRAMS = ts phmt mfcr_test
TESTS = ts phmt mfcr_test
-if HAVE_GTEST
noinst_PROGRAMS += \
crp_test \
dict_test \
@@ -14,7 +13,6 @@ noinst_PROGRAMS += \
small_vector_test
TESTS += crp_test small_vector_test logval_test weights_test dict_test m_test
-endif
reconstruct_weights_SOURCES = reconstruct_weights.cc
@@ -44,23 +42,23 @@ endif
phmt_SOURCES = phmt.cc
ts_SOURCES = ts.cc
m_test_SOURCES = m_test.cc
-m_test_LDADD = $(GTEST_LDFLAGS) $(GTEST_LIBS)
+m_test_LDADD = $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS)
dict_test_SOURCES = dict_test.cc
-dict_test_LDADD = $(GTEST_LDFLAGS) $(GTEST_LIBS)
+dict_test_LDADD = $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS)
mfcr_test_SOURCES = mfcr_test.cc
-mfcr_test_LDADD = $(GTEST_LDFLAGS) $(GTEST_LIBS)
+mfcr_test_LDADD = $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS)
weights_test_SOURCES = weights_test.cc
-weights_test_LDADD = $(GTEST_LDFLAGS) $(GTEST_LIBS)
+weights_test_LDADD = $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS)
crp_test_SOURCES = crp_test.cc
-crp_test_LDADD = $(GTEST_LDFLAGS) $(GTEST_LIBS)
+crp_test_LDADD = $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS)
logval_test_SOURCES = logval_test.cc
-logval_test_LDADD = $(GTEST_LDFLAGS) $(GTEST_LIBS)
+logval_test_LDADD = $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS)
small_vector_test_SOURCES = small_vector_test.cc
-small_vector_test_LDADD = $(GTEST_LDFLAGS) $(GTEST_LIBS)
+small_vector_test_LDADD = $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS)
AM_LDFLAGS = libutils.a -lz
################################################################
# do NOT NOT NOT add any other -I includes NO NO NO NO NO ######
-AM_CPPFLAGS = -W -Wall -Wno-sign-compare $(GTEST_CPPFLAGS) -I.
+AM_CPPFLAGS = -DBOOST_TEST_DYN_LINK -W -Wall -Wno-sign-compare -I.
################################################################
diff --git a/utils/crp_test.cc b/utils/crp_test.cc
index 561cd4dd..0cdb7afd 100644
--- a/utils/crp_test.cc
+++ b/utils/crp_test.cc
@@ -2,25 +2,18 @@
#include <vector>
#include <string>
-#include <gtest/gtest.h>
+#define BOOST_TEST_MODULE CrpTest
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
#include "ccrp.h"
#include "sampler.h"
-const size_t MAX_DOC_LEN_CHARS = 10000000;
-
using namespace std;
-class CRPTest : public testing::Test {
- public:
- CRPTest() {}
- protected:
- virtual void SetUp() { }
- virtual void TearDown() { }
- MT19937 rng;
-};
+MT19937 rng;
-TEST_F(CRPTest, Dist) {
+BOOST_AUTO_TEST_CASE(Dist) {
CCRP<string> crp(0.1, 5);
double un = 0.25;
int tt = 0;
@@ -41,7 +34,7 @@ TEST_F(CRPTest, Dist) {
cout << " P(foo)=" << crp.prob("foo", un) << endl;
double x = crp.prob("bar", un) + crp.prob("hi", un) + crp.prob("baz", un) + crp.prob("foo", un);
cout << " tot=" << x << endl;
- EXPECT_FLOAT_EQ(1.0, x);
+ BOOST_CHECK_CLOSE(1.0, x, 1e-6);
tt += crp.decrement("hi", &rng);
tt += crp.decrement("bar", &rng);
cout << crp << endl;
@@ -50,7 +43,7 @@ TEST_F(CRPTest, Dist) {
cout << "tt=" << tt << endl;
}
-TEST_F(CRPTest, Exchangability) {
+BOOST_AUTO_TEST_CASE(Exchangability) {
double tot = 0;
double xt = 0;
CCRP<int> crp(0.5, 1.0);
@@ -79,24 +72,20 @@ TEST_F(CRPTest, Exchangability) {
++hist[c];
tot += c;
}
- EXPECT_EQ(cust, crp.num_customers());
+ BOOST_CHECK_EQUAL(cust, crp.num_customers());
cerr << "P(a) = " << (xt / samples) << endl;
cerr << "E[num tables] = " << (tot / samples) << endl;
double error = fabs((tot / samples) - 5.4);
cerr << " error = " << error << endl;
- EXPECT_LT(error, 0.1); // it's possible for this to fail, but
+ BOOST_CHECK_MESSAGE(error < 0.1, "error is too big = " << error); // it's possible for this to fail, but
// very, very unlikely
for (int i = 1; i <= cust; ++i)
cerr << i << ' ' << (hist[i]) << endl;
}
-TEST_F(CRPTest, LP) {
+BOOST_AUTO_TEST_CASE(LP) {
CCRP<string> crp(1,1,1,1,0.1,50.0);
crp.increment("foo", 1.0, &rng);
cerr << crp.log_crp_prob() << endl;
}
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
diff --git a/utils/dict_test.cc b/utils/dict_test.cc
index 2049ec27..dac65de1 100644
--- a/utils/dict_test.cc
+++ b/utils/dict_test.cc
@@ -3,45 +3,34 @@
#include "fdict.h"
#include <iostream>
-#include <gtest/gtest.h>
+#define BOOST_TEST_MODULE CrpTest
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
#include <cassert>
using namespace std;
-class DTest : public testing::Test {
- public:
- DTest() {}
- protected:
- virtual void SetUp() { }
- virtual void TearDown() { }
-};
-
-TEST_F(DTest, Convert) {
+BOOST_AUTO_TEST_CASE(Convert) {
Dict d;
WordID a = d.Convert("foo");
WordID b = d.Convert("bar");
std::string x = "foo";
WordID c = d.Convert(x);
- EXPECT_NE(a, b);
- EXPECT_EQ(a, c);
- EXPECT_EQ(d.Convert(a), "foo");
- EXPECT_EQ(d.Convert(b), "bar");
+ assert(a != b);
+ BOOST_CHECK_EQUAL(a, c);
+ BOOST_CHECK_EQUAL(d.Convert(a), "foo");
+ BOOST_CHECK_EQUAL(d.Convert(b), "bar");
}
-TEST_F(DTest, FDictTest) {
+BOOST_AUTO_TEST_CASE(FDictTest) {
int fid = FD::Convert("First");
- EXPECT_GT(fid, 0);
- EXPECT_EQ(FD::Convert(fid), "First");
+ assert(fid > 0);
+ BOOST_CHECK_EQUAL(FD::Convert(fid), "First");
string x = FD::Escape("=");
cerr << x << endl;
- EXPECT_NE(x, "=");
+ assert(x != "=");
x = FD::Escape(";");
cerr << x << endl;
- EXPECT_NE(x, ";");
-}
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
+ assert(x != ";");
}
diff --git a/utils/logval_test.cc b/utils/logval_test.cc
index 6133f5ce..119fa0e4 100644
--- a/utils/logval_test.cc
+++ b/utils/logval_test.cc
@@ -1,56 +1,51 @@
#include "logval.h"
-
-#include <gtest/gtest.h>
+#define BOOST_TEST_MODULE LogValTest
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
#include <iostream>
-class LogValTest : public testing::Test {
- protected:
- virtual void SetUp() { }
- virtual void TearDown() { }
-};
-
using namespace std;
-TEST_F(LogValTest,Order) {
+BOOST_AUTO_TEST_CASE(Order) {
LogVal<double> a(-0.3);
LogVal<double> b(0.3);
LogVal<double> c(2.4);
- EXPECT_LT(a,b);
- EXPECT_LT(b,c);
- EXPECT_LT(a,c);
- EXPECT_FALSE(b < a);
- EXPECT_FALSE(c < a);
- EXPECT_FALSE(c < b);
- EXPECT_FALSE(c < c);
- EXPECT_FALSE(b < b);
- EXPECT_FALSE(a < a);
+ BOOST_CHECK_LT(a,b);
+ BOOST_CHECK_LT(b,c);
+ BOOST_CHECK_LT(a,c);
+ BOOST_CHECK(b >= a);
+ BOOST_CHECK(c >= a);
+ BOOST_CHECK(c >= b);
+ BOOST_CHECK(c >= c);
+ BOOST_CHECK(b >= b);
+ BOOST_CHECK(a >= a);
}
-TEST_F(LogValTest,Negate) {
+BOOST_AUTO_TEST_CASE(Negate) {
LogVal<double> x(-2.4);
LogVal<double> y(2.4);
y.negate();
- EXPECT_FLOAT_EQ(x.as_float(),y.as_float());
+ BOOST_CHECK_CLOSE(x.as_float(),y.as_float(), 1e-6);
}
-TEST_F(LogValTest,Inverse) {
+BOOST_AUTO_TEST_CASE(Inverse) {
LogVal<double> x(1/2.4);
LogVal<double> y(2.4);
- EXPECT_FLOAT_EQ(x.as_float(),y.inverse().as_float());
+ BOOST_CHECK_CLOSE(x.as_float(),y.inverse().as_float(), 1e-6);
}
-TEST_F(LogValTest,Minus) {
+BOOST_AUTO_TEST_CASE(Minus) {
LogVal<double> x(12);
LogVal<double> y(2);
LogVal<double> z1 = x - y;
LogVal<double> z2 = x;
z2 -= y;
- EXPECT_FLOAT_EQ(z1.as_float(), z2.as_float());
- EXPECT_FLOAT_EQ(z1.as_float(), 10.0);
- EXPECT_FLOAT_EQ((y - x).as_float(), -10.0);
+ BOOST_CHECK_CLOSE(z1.as_float(), z2.as_float(), 1e-6);
+ BOOST_CHECK_CLOSE(z1.as_float(), 10.0, 1e-6);
+ BOOST_CHECK_CLOSE((y - x).as_float(), -10.0, 1e-6);
}
-TEST_F(LogValTest,TestOps) {
+BOOST_AUTO_TEST_CASE(TestOps) {
LogVal<double> x(-12.12);
LogVal<double> y(x);
cerr << x << endl;
@@ -62,18 +57,13 @@ TEST_F(LogValTest,TestOps) {
LogVal<double> bb(-0.3);
cerr << (aa + bb) << endl;
cerr << (bb + aa) << endl;
- EXPECT_FLOAT_EQ((aa + bb).as_float(), (bb + aa).as_float());
- EXPECT_FLOAT_EQ((aa + bb).as_float(), -0.1);
+ BOOST_CHECK_CLOSE((aa + bb).as_float(), (bb + aa).as_float(), 1e-6);
+ BOOST_CHECK_CLOSE((aa + bb).as_float(), -0.1, 1e-6);
}
-TEST_F(LogValTest,TestSizes) {
+BOOST_AUTO_TEST_CASE(TestSizes) {
cerr << sizeof(LogVal<double>) << endl;
cerr << sizeof(LogVal<float>) << endl;
cerr << sizeof(void*) << endl;
}
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
-
diff --git a/utils/m_test.cc b/utils/m_test.cc
index c4d6a166..7851e4ac 100644
--- a/utils/m_test.cc
+++ b/utils/m_test.cc
@@ -1,20 +1,15 @@
#include "m.h"
+#define BOOST_TEST_MODULE MTest
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+
#include <iostream>
-#include <gtest/gtest.h>
#include <cassert>
using namespace std;
-class MTest : public testing::Test {
- public:
- MTest() {}
- protected:
- virtual void SetUp() { }
- virtual void TearDown() { }
-};
-
-TEST_F(MTest, Densities) {
+BOOST_AUTO_TEST_CASE(Densities) {
double px1 = Md::log_gaussian_density(1.0, 0.0, 1.0);
double px2 = Md::log_gaussian_density(-1.0, 0.0, 1.0);
double py1 = Md::log_laplace_density(1.0, 0.0, 1.0);
@@ -22,70 +17,65 @@ TEST_F(MTest, Densities) {
double pz1 = Md::log_triangle_density(1.0, -2.0, 2.0, 0.0);
double pz2 = Md::log_triangle_density(1.0, -2.0, 2.0, 0.0);
cerr << px1 << " " << py1 << " " << pz2 << endl;
- EXPECT_FLOAT_EQ(px1, px2);
- EXPECT_FLOAT_EQ(py1, py2);
- EXPECT_FLOAT_EQ(pz1, pz2);
+ BOOST_CHECK_CLOSE(px1, px2, 1e-6);
+ BOOST_CHECK_CLOSE(py1, py2, 1e-6);
+ BOOST_CHECK_CLOSE(pz1, pz2, 1e-6);
double b1 = Md::log_bivariate_gaussian_density(1.0, -1.0, 0.0, 0.0, 1.0, 1.0, -0.8);
double b2 = Md::log_bivariate_gaussian_density(-1.0, 1.0, 0.0, 0.0, 1.0, 1.0, -0.8);
cerr << b1 << " " << b2 << endl;
}
-TEST_F(MTest, Poisson) {
+BOOST_AUTO_TEST_CASE(Poisson) {
double prev = 1.0;
double tot = 0;
for (int i = 0; i < 10; ++i) {
double p = Md::log_poisson(i, 0.99);
cerr << "p(i=" << i << ") = " << exp(p) << endl;
- EXPECT_LT(p, prev);
+ assert(p < prev);
tot += exp(p);
prev = p;
}
cerr << " tot=" << tot << endl;
- EXPECT_LE(tot, 1.0);
+ assert(tot < 1.0);
}
-TEST_F(MTest, YuleSimon) {
+BOOST_AUTO_TEST_CASE(YuleSimon) {
double prev = 1.0;
double tot = 0;
for (int i = 0; i < 10; ++i) {
double p = Md::log_yule_simon(i, 1.0);
cerr << "p(i=" << i << ") = " << exp(p) << endl;
- EXPECT_LT(p, prev);
+ assert(p < prev);
tot += exp(p);
prev = p;
}
cerr << " tot=" << tot << endl;
- EXPECT_LE(tot, 1.0);
+ assert(tot < 1.0);
}
-TEST_F(MTest, LogGeometric) {
+BOOST_AUTO_TEST_CASE(LogGeometric) {
double prev = 1.0;
double tot = 0;
for (int i = 0; i < 10; ++i) {
double p = Md::log_geometric(i, 0.5);
cerr << "p(i=" << i << ") = " << exp(p) << endl;
- EXPECT_LT(p, prev);
+ assert(p < prev);
tot += exp(p);
prev = p;
}
cerr << " tot=" << tot << endl;
- EXPECT_LE(tot, 1.0);
+ assert(tot <= 1.0);
}
-TEST_F(MTest, GeneralizedFactorial) {
+BOOST_AUTO_TEST_CASE(GeneralizedFactorial) {
for (double i = 0.3; i < 10000; i += 0.4) {
double a = Md::log_generalized_factorial(1.0, i);
double b = lgamma(1.0 + i);
- EXPECT_FLOAT_EQ(a,b);
+ BOOST_CHECK_CLOSE(a,b,1e-6);
}
double gf_3_6 = 3.0 * 4.0 * 5.0 * 6.0 * 7.0 * 8.0;
- EXPECT_FLOAT_EQ(Md::log_generalized_factorial(3.0, 6.0), std::log(gf_3_6));
+ BOOST_CHECK_CLOSE(Md::log_generalized_factorial(3.0, 6.0), std::log(gf_3_6), 1e-6);
double gf_314_6 = 3.14 * 4.14 * 5.14 * 6.14 * 7.14 * 8.14;
- EXPECT_FLOAT_EQ(Md::log_generalized_factorial(3.14, 6.0), std::log(gf_314_6));
-}
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
+ BOOST_CHECK_CLOSE(Md::log_generalized_factorial(3.14, 6.0), std::log(gf_314_6), 1e-6);
}
diff --git a/utils/small_vector_test.cc b/utils/small_vector_test.cc
index d1d8dcab..cded4619 100644
--- a/utils/small_vector_test.cc
+++ b/utils/small_vector_test.cc
@@ -1,129 +1,118 @@
#include "small_vector.h"
-#include <gtest/gtest.h>
+#define BOOST_TEST_MODULE svTest
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
#include <iostream>
-#include <cassert>
#include <vector>
using namespace std;
-class SVTest : public testing::Test {
- protected:
- virtual void SetUp() { }
- virtual void TearDown() { }
-};
-
-TEST_F(SVTest, LargerThan2) {
+BOOST_AUTO_TEST_CASE(LargerThan2) {
SmallVectorInt v;
SmallVectorInt v2;
v.push_back(0);
v.push_back(1);
v.push_back(2);
- assert(v.size() == 3);
- assert(v[2] == 2);
- assert(v[1] == 1);
- assert(v[0] == 0);
+ BOOST_CHECK(v.size() == 3);
+ BOOST_CHECK(v[2] == 2);
+ BOOST_CHECK(v[1] == 1);
+ BOOST_CHECK(v[0] == 0);
v2 = v;
SmallVectorInt copy(v);
- assert(copy.size() == 3);
- assert(copy[0] == 0);
- assert(copy[1] == 1);
- assert(copy[2] == 2);
- assert(copy == v2);
+ BOOST_CHECK(copy.size() == 3);
+ BOOST_CHECK(copy[0] == 0);
+ BOOST_CHECK(copy[1] == 1);
+ BOOST_CHECK(copy[2] == 2);
+ BOOST_CHECK(copy == v2);
copy[1] = 99;
- assert(copy != v2);
- assert(v2.size() == 3);
- assert(v2[2] == 2);
- assert(v2[1] == 1);
- assert(v2[0] == 0);
+ BOOST_CHECK(copy != v2);
+ BOOST_CHECK(v2.size() == 3);
+ BOOST_CHECK(v2[2] == 2);
+ BOOST_CHECK(v2[1] == 1);
+ BOOST_CHECK(v2[0] == 0);
v2[0] = -2;
v2[1] = -1;
v2[2] = 0;
- assert(v2[2] == 0);
- assert(v2[1] == -1);
- assert(v2[0] == -2);
+ BOOST_CHECK(v2[2] == 0);
+ BOOST_CHECK(v2[1] == -1);
+ BOOST_CHECK(v2[0] == -2);
SmallVectorInt v3(1,1);
- assert(v3[0] == 1);
+ BOOST_CHECK(v3[0] == 1);
v2 = v3;
- assert(v2.size() == 1);
- assert(v2[0] == 1);
+ BOOST_CHECK(v2.size() == 1);
+ BOOST_CHECK(v2[0] == 1);
SmallVectorInt v4(10, 1);
- assert(v4.size() == 10);
- assert(v4[5] == 1);
- assert(v4[9] == 1);
+ BOOST_CHECK(v4.size() == 10);
+ BOOST_CHECK(v4[5] == 1);
+ BOOST_CHECK(v4[9] == 1);
v4 = v;
- assert(v4.size() == 3);
- assert(v4[2] == 2);
- assert(v4[1] == 1);
- assert(v4[0] == 0);
+ BOOST_CHECK(v4.size() == 3);
+ BOOST_CHECK(v4[2] == 2);
+ BOOST_CHECK(v4[1] == 1);
+ BOOST_CHECK(v4[0] == 0);
SmallVectorInt v5(10, 2);
- assert(v5.size() == 10);
- assert(v5[7] == 2);
- assert(v5[0] == 2);
- assert(v.size() == 3);
+ BOOST_CHECK(v5.size() == 10);
+ BOOST_CHECK(v5[7] == 2);
+ BOOST_CHECK(v5[0] == 2);
+ BOOST_CHECK(v.size() == 3);
v = v5;
- assert(v.size() == 10);
- assert(v[2] == 2);
- assert(v[9] == 2);
+ BOOST_CHECK(v.size() == 10);
+ BOOST_CHECK(v[2] == 2);
+ BOOST_CHECK(v[9] == 2);
SmallVectorInt cc;
for (int i = 0; i < 33; ++i)
cc.push_back(i);
for (int i = 0; i < 33; ++i)
- assert(cc[i] == i);
+ BOOST_CHECK(cc[i] == i);
cc.resize(20);
- assert(cc.size() == 20);
+ BOOST_CHECK(cc.size() == 20);
for (int i = 0; i < 20; ++i)
- assert(cc[i] == i);
+ BOOST_CHECK(cc[i] == i);
cc[0]=-1;
cc.resize(1, 999);
- assert(cc.size() == 1);
- assert(cc[0] == -1);
+ BOOST_CHECK(cc.size() == 1);
+ BOOST_CHECK(cc[0] == -1);
cc.resize(99, 99);
for (int i = 1; i < 99; ++i) {
cerr << i << " " << cc[i] << endl;
- assert(cc[i] == 99);
+ BOOST_CHECK(cc[i] == 99);
}
cc.clear();
- assert(cc.size() == 0);
+ BOOST_CHECK(cc.size() == 0);
}
-TEST_F(SVTest, Small) {
+BOOST_AUTO_TEST_CASE(Small) {
SmallVectorInt v;
SmallVectorInt v1(1,0);
SmallVectorInt v2(2,10);
SmallVectorInt v1a(2,0);
- EXPECT_TRUE(v1 != v1a);
- EXPECT_TRUE(v1 == v1);
- EXPECT_EQ(v1[0], 0);
- EXPECT_EQ(v2[1], 10);
- EXPECT_EQ(v2[0], 10);
+ BOOST_CHECK(v1 != v1a);
+ BOOST_CHECK(v1 == v1);
+ BOOST_CHECK_EQUAL(v1[0], 0);
+ BOOST_CHECK_EQUAL(v2[1], 10);
+ BOOST_CHECK_EQUAL(v2[0], 10);
++v2[1];
--v2[0];
- EXPECT_EQ(v2[0], 9);
- EXPECT_EQ(v2[1], 11);
+ BOOST_CHECK_EQUAL(v2[0], 9);
+ BOOST_CHECK_EQUAL(v2[1], 11);
SmallVectorInt v3(v2);
- assert(v3[0] == 9);
- assert(v3[1] == 11);
- assert(!v3.empty());
- assert(v3.size() == 2);
+ BOOST_CHECK(v3[0] == 9);
+ BOOST_CHECK(v3[1] == 11);
+ BOOST_CHECK(!v3.empty());
+ BOOST_CHECK(v3.size() == 2);
v3.clear();
- assert(v3.empty());
- assert(v3.size() == 0);
- assert(v3 != v2);
- assert(v2 != v3);
+ BOOST_CHECK(v3.empty());
+ BOOST_CHECK(v3.size() == 0);
+ BOOST_CHECK(v3 != v2);
+ BOOST_CHECK(v2 != v3);
v3 = v2;
- assert(v3 == v2);
- assert(v2 == v3);
- assert(v3[0] == 9);
- assert(v3[1] == 11);
- assert(!v3.empty());
- assert(v3.size() == 2);
+ BOOST_CHECK(v3 == v2);
+ BOOST_CHECK(v2 == v3);
+ BOOST_CHECK(v3[0] == 9);
+ BOOST_CHECK(v3[1] == 11);
+ BOOST_CHECK(!v3.empty());
+ BOOST_CHECK(v3.size() == 2);
cerr << sizeof(SmallVectorInt) << endl;
cerr << sizeof(vector<int>) << endl;
}
-
-int main(int argc, char** argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
-
diff --git a/utils/weights_test.cc b/utils/weights_test.cc
index 938b311f..4be4c40f 100644
--- a/utils/weights_test.cc
+++ b/utils/weights_test.cc
@@ -1,26 +1,12 @@
-#include <cassert>
-#include <iostream>
-#include <fstream>
-#include <vector>
-#include <gtest/gtest.h>
+#define BOOST_TEST_MODULE WeightsTest
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
#include "weights.h"
-#include "tdict.h"
using namespace std;
-class WeightsTest : public testing::Test {
- protected:
- virtual void SetUp() { }
- virtual void TearDown() { }
-};
-
-TEST_F(WeightsTest,Load) {
+BOOST_AUTO_TEST_CASE(Load) {
vector<weight_t> v;
Weights::InitFromFile("test_data/weights", &v);
Weights::WriteToFile("-", v);
}
-
-int main(int argc, char **argv) {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}