diff options
author | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-03-18 00:58:40 +0400 |
---|---|---|
committer | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-03-18 00:58:40 +0400 |
commit | 6b95a19eda818fb772767a0037c70a7bbb6c32e5 (patch) | |
tree | e1b7d608005bcc33ee00646263583e83d03a53a2 /mert/ReferenceTest.cpp | |
parent | 918bcafb808fe3067a4d689607bffb7dbbf0a914 (diff) |
Create Reference class to clean up BleuScorer.
- Add an unit test for Reference.
- Move functions to calculate the reference length from
BleuScorer to Reference.
Diffstat (limited to 'mert/ReferenceTest.cpp')
-rw-r--r-- | mert/ReferenceTest.cpp | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/mert/ReferenceTest.cpp b/mert/ReferenceTest.cpp new file mode 100644 index 000000000..454768195 --- /dev/null +++ b/mert/ReferenceTest.cpp @@ -0,0 +1,116 @@ +#include "Reference.h" + +#define BOOST_TEST_MODULE MertReference +#include <boost/test/unit_test.hpp> + +BOOST_AUTO_TEST_CASE(refernece_count) { + Reference ref; + BOOST_CHECK(ref.get_counts() != NULL); +} + +BOOST_AUTO_TEST_CASE(refernece_length_iterator) { + Reference ref; + ref.push_back(4); + ref.push_back(2); + BOOST_REQUIRE(ref.num_references() == 2); + + Reference::iterator it = ref.begin(); + BOOST_CHECK_EQUAL(*it, 4); + ++it; + BOOST_CHECK_EQUAL(*it, 2); + ++it; + BOOST_CHECK(it == ref.end()); +} + +BOOST_AUTO_TEST_CASE(refernece_length_average) { + { + Reference ref; + ref.push_back(4); + ref.push_back(1); + BOOST_CHECK_EQUAL(2, ref.CalcAverage()); + } + + { + Reference ref; + ref.push_back(4); + ref.push_back(3); + BOOST_CHECK_EQUAL(3, ref.CalcAverage()); + } + + { + Reference ref; + ref.push_back(4); + ref.push_back(3); + ref.push_back(4); + ref.push_back(5); + BOOST_CHECK_EQUAL(4, ref.CalcAverage()); + } +} + +BOOST_AUTO_TEST_CASE(refernece_length_closest) { + { + Reference ref; + ref.push_back(4); + ref.push_back(1); + BOOST_REQUIRE(ref.num_references() == 2); + + BOOST_CHECK_EQUAL(1, ref.CalcClosest(2)); + BOOST_CHECK_EQUAL(1, ref.CalcClosest(1)); + BOOST_CHECK_EQUAL(4, ref.CalcClosest(3)); + BOOST_CHECK_EQUAL(4, ref.CalcClosest(4)); + BOOST_CHECK_EQUAL(4, ref.CalcClosest(5)); + } + + { + Reference ref; + ref.push_back(4); + ref.push_back(3); + BOOST_REQUIRE(ref.num_references() == 2); + + BOOST_CHECK_EQUAL(3, ref.CalcClosest(1)); + BOOST_CHECK_EQUAL(3, ref.CalcClosest(2)); + BOOST_CHECK_EQUAL(3, ref.CalcClosest(3)); + BOOST_CHECK_EQUAL(4, ref.CalcClosest(4)); + BOOST_CHECK_EQUAL(4, ref.CalcClosest(5)); + } + + { + Reference ref; + ref.push_back(4); + ref.push_back(3); + ref.push_back(4); + ref.push_back(5); + BOOST_REQUIRE(ref.num_references() == 4); + + BOOST_CHECK_EQUAL(3, ref.CalcClosest(1)); + BOOST_CHECK_EQUAL(3, ref.CalcClosest(2)); + BOOST_CHECK_EQUAL(3, ref.CalcClosest(3)); + BOOST_CHECK_EQUAL(4, ref.CalcClosest(4)); + BOOST_CHECK_EQUAL(5, ref.CalcClosest(5)); + } +} + +BOOST_AUTO_TEST_CASE(refernece_length_shortest) { + { + Reference ref; + ref.push_back(4); + ref.push_back(1); + BOOST_CHECK_EQUAL(1, ref.CalcShortest()); + } + + { + Reference ref; + ref.push_back(4); + ref.push_back(3); + BOOST_CHECK_EQUAL(3, ref.CalcShortest()); + } + + { + Reference ref; + ref.push_back(4); + ref.push_back(3); + ref.push_back(4); + ref.push_back(5); + BOOST_CHECK_EQUAL(3, ref.CalcShortest()); + } +} |