diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-06-28 19:37:50 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-07-01 10:29:19 -0400 |
commit | add9e14a4a45d29ac7284f9cecf762e3a075a01d (patch) | |
tree | 2359432397e7e6d0c407626f5c117ad9bfd6a482 | |
parent | 58380c11216cb9f03a98e3d53dcee702576fedb8 (diff) |
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
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 19 | ||||
-rw-r--r-- | sc/source/core/tool/scmatrix.cxx | 2 |
2 files changed, 20 insertions, 1 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index be470b129713..c7eda916cc8c 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -2562,6 +2562,25 @@ void Test::testMatrix() CPPUNIT_ASSERT_EQUAL(1.5, pMat->GetDouble(0, 1)); CPPUNIT_ASSERT_EQUAL(1.5, pMat->GetDouble(1, 0)); 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() diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx index bf3ea639c49a..b0bef2ebc701 100644 --- a/sc/source/core/tool/scmatrix.cxx +++ b/sc/source/core/tool/scmatrix.cxx @@ -940,7 +940,7 @@ public: 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) { return std::max(left, right); |