summaryrefslogtreecommitdiff
path: root/mteval
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 /mteval
parent721ff772038c117da8746836533609eda7737443 (diff)
remove dependency on gtest, remove all-static
Diffstat (limited to 'mteval')
-rw-r--r--mteval/Makefile.am6
-rw-r--r--mteval/scorer_test.cc81
2 files changed, 40 insertions, 47 deletions
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()