summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Francis <dennisfrancis.in@gmail.com>2015-10-24 13:16:14 +0530
committerEike Rathke <erack@redhat.com>2015-10-24 14:33:52 +0000
commitc43442dfef3f5b21bec40054b56f406efdc5a84f (patch)
tree9453125612aa63161f1da0a6e08ea9060fa7d56f
parente1e73a97b20af862f2fb914cb16a4f74c3ad31cb (diff)
unit test for MDETERM() tdf#32834
Change-Id: Icc55931f5bc64fcc2745ca68f62851ee2c59f711 Reviewed-on: https://gerrit.libreoffice.org/19569 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Eike Rathke <erack@redhat.com>
-rw-r--r--sc/qa/unit/ucalc.hxx2
-rw-r--r--sc/qa/unit/ucalc_formula.cxx40
2 files changed, 42 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 29ca1e0f7cea..b1a6af2fb1df 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -193,6 +193,7 @@ public:
void testFuncGCD();
void testFuncLCM();
void testFuncSUMSQ();
+ void testFuncMDETERM();
void testExternalRef();
void testExternalRefFunctions();
@@ -534,6 +535,7 @@ public:
CPPUNIT_TEST(testFuncGCD);
CPPUNIT_TEST(testFuncLCM);
CPPUNIT_TEST(testFuncSUMSQ);
+ CPPUNIT_TEST(testFuncMDETERM);
CPPUNIT_TEST(testExternalRef);
CPPUNIT_TEST(testExternalRangeName);
CPPUNIT_TEST(testExternalRefFunctions);
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index 8538eaed5eb3..1e0c06bbb5cc 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -6572,6 +6572,46 @@ void Test::testFuncSUMSQ()
m_pDoc->DeleteTab(0);
}
+void Test::testFuncMDETERM()
+{
+ sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on.
+
+ m_pDoc->InsertTab(0, "MDETERM_test");
+ ScAddress aPos(8,0,0);
+ OUString aColCodes("ABCDEFGH");
+ OUString aFormulaTemplate("=MDETERM(A1:B2)");
+ OUStringBuffer aFormulaBuffer(aFormulaTemplate);
+ for( SCSIZE nSize = 3; nSize <= 8; nSize++ )
+ {
+ double fVal = 1.0;
+ // Generate a singular integer matrix
+ for( SCROW nRow = 0; nRow < static_cast<SCROW>(nSize); nRow++ )
+ {
+ for( SCCOL nCol = 0; nCol < static_cast<SCCOL>(nSize); nCol++ )
+ {
+ m_pDoc->SetValue(nCol, nRow, 0, fVal);
+ fVal += 1.0;
+ }
+ }
+ aFormulaBuffer[12] = aColCodes[nSize-1];
+ aFormulaBuffer[13] = static_cast<sal_Unicode>( '0' + nSize );
+ m_pDoc->SetString(aPos, aFormulaBuffer.toString());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Calculation of MDETERM incorrect for singular integer matrix",
+ 0.0, m_pDoc->GetValue(aPos));
+ }
+
+ int aVals[] = {23, 31, 13, 12, 34, 64, 34, 31, 98, 32, 33, 63, 45, 54, 65, 76};
+ int nIdx = 0;
+ for( SCROW nRow = 0; nRow < 4; nRow++ )
+ for( SCCOL nCol = 0; nCol < 4; nCol++ )
+ m_pDoc->SetValue(nCol, nRow, 0, static_cast<double>(aVals[nIdx++]));
+ m_pDoc->SetString(aPos, "=MDETERM(A1:D4)");
+ // Following test is conservative in the sense that on Linux x86_64 the error is less that 1.0E-9
+ CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculation of MDETERM incorrect for non-singular integer matrix",
+ -180655.0, m_pDoc->GetValue(aPos), 1.0E-6);
+ m_pDoc->DeleteTab(0);
+}
+
void Test::testFormulaErrorPropagation()
{
sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on.