Kaydet (Commit) add9e14a authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Add tests for matrix's min and max values, and fix one bug.

Apparently numeric_limits<type>::min() is not to be used for signed types.

Change-Id: Ia9730328562905459eb1d3e5cfd1a023c644e219
üst 58380c11
...@@ -2562,6 +2562,25 @@ void Test::testMatrix() ...@@ -2562,6 +2562,25 @@ void Test::testMatrix()
CPPUNIT_ASSERT_EQUAL(1.5, pMat->GetDouble(0, 1)); CPPUNIT_ASSERT_EQUAL(1.5, pMat->GetDouble(0, 1));
CPPUNIT_ASSERT_EQUAL(1.5, pMat->GetDouble(1, 0)); CPPUNIT_ASSERT_EQUAL(1.5, pMat->GetDouble(1, 0));
CPPUNIT_ASSERT_MESSAGE("PutEmpty() call failed.", pMat->IsEmpty(1, 1)); CPPUNIT_ASSERT_MESSAGE("PutEmpty() call failed.", pMat->IsEmpty(1, 1));
// Max and min values.
pMat = new ScMatrix(2, 2, 0.0);
pMat->PutDouble(-10, 0, 0);
pMat->PutDouble(-12, 0, 1);
pMat->PutDouble(-8, 1, 0);
pMat->PutDouble(-25, 1, 1);
CPPUNIT_ASSERT_EQUAL(-25.0, pMat->GetMinValue(false));
CPPUNIT_ASSERT_EQUAL(-8.0, pMat->GetMaxValue(false));
pMat->PutString("Test", 0, 0);
CPPUNIT_ASSERT_EQUAL(0.0, pMat->GetMaxValue(true)); // text as zero.
CPPUNIT_ASSERT_EQUAL(-8.0, pMat->GetMaxValue(false)); // ignore text.
pMat->PutBoolean(true, 0, 0);
CPPUNIT_ASSERT_EQUAL(1.0, pMat->GetMaxValue(false));
pMat = new ScMatrix(2, 2, 10.0);
pMat->PutBoolean(false, 0, 0);
pMat->PutDouble(12.5, 1, 1);
CPPUNIT_ASSERT_EQUAL(0.0, pMat->GetMinValue(false));
CPPUNIT_ASSERT_EQUAL(12.5, pMat->GetMaxValue(false));
} }
void Test::testEnterMixedMatrix() void Test::testEnterMixedMatrix()
......
...@@ -940,7 +940,7 @@ public: ...@@ -940,7 +940,7 @@ public:
struct MaxOp struct MaxOp
{ {
static double init() { return std::numeric_limits<double>::min(); } static double init() { return -std::numeric_limits<double>::max(); }
static double compare(double left, double right) static double compare(double left, double right)
{ {
return std::max(left, right); return std::max(left, right);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment