summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-07-11 13:26:04 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-07-11 13:27:19 -0400
commit3c59183f5bfa22194f0287b449aaa6d882be8827 (patch)
tree2f137adeb0497a50c539113169fcbf879a6fa8b3 /sc
parent5e60674857d3d290f172b8c133c69aeba003b1ce (diff)
Add test case for matrix's double array handling & fix one bug.
Change-Id: I6cb2ff8bf536ccb53ae9f146baf6aa582f9fbcfe
Diffstat (limited to 'sc')
-rw-r--r--sc/qa/unit/ucalc.cxx45
-rw-r--r--sc/source/core/tool/scmatrix.cxx4
2 files changed, 48 insertions, 1 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 6d2d0fcaf1d7..5c3ec7bf2911 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -2145,7 +2145,7 @@ struct PartiallyFilledEmptyMatrix
void Test::testMatrix()
{
- ScMatrixRef pMat;
+ ScMatrixRef pMat, pMat2;
// First, test the zero matrix type.
pMat = new ScMatrix(0, 0, 0.0);
@@ -2226,6 +2226,49 @@ void Test::testMatrix()
pMat->PutDouble(12.5, 1, 1);
CPPUNIT_ASSERT_EQUAL(0.0, pMat->GetMinValue(false));
CPPUNIT_ASSERT_EQUAL(12.5, pMat->GetMaxValue(false));
+
+ // Convert matrix into a linear double array. String elements become NaN
+ // and empty elements become 0.
+ pMat = new ScMatrix(3, 3);
+ pMat->PutDouble(2.5, 0, 0);
+ pMat->PutDouble(1.2, 0, 1);
+ pMat->PutString("A", 1, 1);
+ pMat->PutDouble(2.3, 2, 1);
+ pMat->PutDouble(-20, 2, 2);
+
+ double fNaN;
+ rtl::math::setNan(&fNaN);
+
+ std::vector<double> aDoubles;
+ pMat->GetDoubleArray(aDoubles);
+
+ {
+ const double pChecks[] = { 2.5, 1.2, 0, 0, fNaN, 0, 0, 2.3, -20 };
+ CPPUNIT_ASSERT_EQUAL(SAL_N_ELEMENTS(pChecks), aDoubles.size());
+ for (size_t i = 0, n = aDoubles.size(); i < n; ++i)
+ {
+ if (rtl::math::isNan(pChecks[i]))
+ CPPUNIT_ASSERT_MESSAGE("NaN is expected, but it's not.", rtl::math::isNan(aDoubles[i]));
+ else
+ CPPUNIT_ASSERT_EQUAL(pChecks[i], aDoubles[i]);
+ }
+ }
+
+ pMat2 = new ScMatrix(3, 3, 10.0);
+ pMat2->PutString("B", 1, 0);
+ pMat2->MergeDoubleArray(aDoubles, ScMatrix::Mul);
+
+ {
+ const double pChecks[] = { 25, 12, 0, fNaN, fNaN, 0, 0, 23, -200 };
+ CPPUNIT_ASSERT_EQUAL(SAL_N_ELEMENTS(pChecks), aDoubles.size());
+ for (size_t i = 0, n = aDoubles.size(); i < n; ++i)
+ {
+ if (rtl::math::isNan(pChecks[i]))
+ CPPUNIT_ASSERT_MESSAGE("NaN is expected, but it's not.", rtl::math::isNan(aDoubles[i]));
+ else
+ CPPUNIT_ASSERT_EQUAL(pChecks[i], aDoubles[i]);
+ }
+ }
}
void Test::testEnterMixedMatrix()
diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index c6922383b5c2..73ed2e2c45a1 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -1063,6 +1063,8 @@ public:
*miPos = mfNaN;
}
break;
+ case mdds::mtm::element_empty:
+ std::advance(miPos, node.size);
default:
;
}
@@ -1133,6 +1135,8 @@ public:
*miPos = mfNaN;
}
break;
+ case mdds::mtm::element_empty:
+ std::advance(miPos, node.size);
default:
;
}