mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
Reduce the number of calling the numeric_limits constructor.
- Create a test module for Point. - Add test cases.
This commit is contained in:
parent
65dc5a391f
commit
49a4be2899
@ -58,6 +58,7 @@ unit-test feature_data_test : FeatureDataTest.cpp mert_lib ..//boost_unit_test_f
|
||||
unit-test data_test : DataTest.cpp mert_lib ..//boost_unit_test_framework ;
|
||||
unit-test ngram_test : NgramTest.cpp mert_lib ..//boost_unit_test_framework ;
|
||||
unit-test optimizer_factory_test : OptimizerFactoryTest.cpp mert_lib ..//boost_unit_test_framework ;
|
||||
unit-test point_test : PointTest.cpp mert_lib ..//boost_unit_test_framework ;
|
||||
unit-test reference_test : ReferenceTest.cpp mert_lib ..//boost_unit_test_framework ;
|
||||
unit-test singleton_test : SingletonTest.cpp mert_lib ..//boost_unit_test_framework ;
|
||||
unit-test timer_test : TimerTest.cpp mert_lib ..//boost_unit_test_framework ;
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
static const float kMaxFloat = numeric_limits<float>::max();
|
||||
|
||||
class Point;
|
||||
|
||||
/**
|
||||
|
@ -3,8 +3,8 @@
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include "util/check.hh"
|
||||
#include <limits>
|
||||
#include "FeatureStats.h"
|
||||
#include "Optimizer.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -84,7 +84,7 @@ Point Point::operator+(const Point& p2) const
|
||||
Res[i] += p2[i];
|
||||
}
|
||||
|
||||
Res.m_score = numeric_limits<statscore_t>::max();
|
||||
Res.m_score = kMaxFloat;
|
||||
return Res;
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ void Point::operator+=(const Point& p2)
|
||||
for (unsigned i = 0; i < size(); i++) {
|
||||
operator[](i) += p2[i];
|
||||
}
|
||||
m_score = numeric_limits<statscore_t>::max();
|
||||
m_score = kMaxFloat;
|
||||
}
|
||||
|
||||
Point Point::operator*(float l) const
|
||||
@ -103,7 +103,7 @@ Point Point::operator*(float l) const
|
||||
for (unsigned i = 0; i < size(); i++) {
|
||||
Res[i] *= l;
|
||||
}
|
||||
Res.m_score = numeric_limits<statscore_t>::max();
|
||||
Res.m_score = kMaxFloat;
|
||||
return Res;
|
||||
}
|
||||
|
||||
|
29
mert/PointTest.cpp
Normal file
29
mert/PointTest.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include "Point.h"
|
||||
|
||||
#define BOOST_TEST_MODULE MertPoint
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include "Optimizer.h"
|
||||
|
||||
BOOST_AUTO_TEST_CASE(point_operators) {
|
||||
// Test operator '+'
|
||||
{
|
||||
Point p1, p2;
|
||||
Point p3 = p1 + p2;
|
||||
BOOST_CHECK_EQUAL(p3.GetScore(), kMaxFloat);
|
||||
}
|
||||
|
||||
// Test operator '+='
|
||||
{
|
||||
Point p1, p2;
|
||||
p1 += p2;
|
||||
BOOST_CHECK_EQUAL(p1.GetScore(), kMaxFloat);
|
||||
}
|
||||
|
||||
// Test operator '*'
|
||||
{
|
||||
Point p1;
|
||||
const Point p2 = p1 * 2.0;
|
||||
BOOST_CHECK_EQUAL(p2.GetScore(), kMaxFloat);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user