summaryrefslogtreecommitdiff
path: root/decoder
diff options
context:
space:
mode:
authorPatrick Simianer <simianer@cl.uni-heidelberg.de>2012-05-02 15:03:24 +0200
committerPatrick Simianer <simianer@cl.uni-heidelberg.de>2012-05-02 15:03:24 +0200
commit45cb0f7426de97cc181079daf3ca04dbc52dee3c (patch)
treeabd2158a559480504525082760a618c78847fcf7 /decoder
parent5a8ef8ba65b244837e9cedbd64793b82bf284f93 (diff)
parent1c32f3e2831aefdf50fd226d3e1b314c804afc3b (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'decoder')
-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
9 files changed, 108 insertions, 208 deletions
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);
}