diff options
author | Ćukasz Hryniuk <lukasz.hryniuk@wp.pl> | 2015-08-11 23:18:28 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2015-08-12 10:22:38 +0000 |
commit | 0a726cb29936b61b8f05b0863e24db212a0e6166 (patch) | |
tree | 2a06344e691fa2795a2cea165f8038a51f956467 | |
parent | 7ca9a8e9cfbf5d38ac37b74198325493f9236554 (diff) |
tdf#89387 test for CHITEST function
Change-Id: Ifff9367e56c357f3d5026ecbf7e984368428e074
Reviewed-on: https://gerrit.libreoffice.org/17658
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
-rw-r--r-- | sc/qa/unit/ucalc.hxx | 2 | ||||
-rw-r--r-- | sc/qa/unit/ucalc_formula.cxx | 106 |
2 files changed, 108 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index 4bfd78949f8a..79d30a97a19c 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -186,6 +186,7 @@ public: void testFuncTableRef(); void testFuncFTEST(); void testFuncFTESTBug(); + void testFuncCHITEST(); void testExternalRef(); void testExternalRefFunctions(); @@ -518,6 +519,7 @@ public: CPPUNIT_TEST(testFuncTableRef); CPPUNIT_TEST(testFuncFTEST); CPPUNIT_TEST_FAIL(testFuncFTESTBug); + CPPUNIT_TEST(testFuncCHITEST); CPPUNIT_TEST(testExternalRef); CPPUNIT_TEST(testExternalRefFunctions); CPPUNIT_TEST(testCopyToDocument); diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx index c6f4acd1459e..fdcdbcc7605d 100644 --- a/sc/qa/unit/ucalc_formula.cxx +++ b/sc/qa/unit/ucalc_formula.cxx @@ -5596,4 +5596,110 @@ void Test::testFuncFTESTBug() m_pDoc->DeleteTab(0); } +void Test::testFuncCHITEST() +{ + sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on. + + m_pDoc->InsertTab(0, "ChiTest"); + + ScAddress aPos(6,0,0); + // 2x2 matrices test + m_pDoc->SetString(aPos, "=CHITEST(A1:B2;D1:E2)"); + OUString aVal = m_pDoc->GetString(aPos); + CPPUNIT_ASSERT_MESSAGE("CHITEST should return Err:502 for matrices with empty cells", + OUString::createFromAscii("Err:502") == aVal); + + m_pDoc->SetValue(0, 0, 0, 1.0); // A1 + m_pDoc->SetValue(0, 1, 0, 2.0); // A2 + m_pDoc->SetValue(1, 0, 0, 2.0); // B1 + m_pDoc->SetValue(1, 1, 0, 1.0); // B2 + aVal = m_pDoc->GetString(aPos); + CPPUNIT_ASSERT_MESSAGE("CHITEST should return Err:502 for matrices with different size", + OUString::createFromAscii("Err:502") == aVal); + + m_pDoc->SetValue(3, 0, 0, 2.0); // D1 + m_pDoc->SetValue(3, 1, 0, 3.0); // D2 + aVal = m_pDoc->GetString(aPos); + CPPUNIT_ASSERT_MESSAGE("CHITEST should return Err:502 for matrices with different size", + OUString::createFromAscii("Err:502") == aVal); + m_pDoc->SetValue(4, 0, 0, 2.0); // E1 + m_pDoc->SetValue(4, 1, 0, 1.0); // E2 + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculation of CHITEST failed", 0.3613, m_pDoc->GetValue(aPos), 10e-4); + m_pDoc->SetValue(4, 0, 0, 3.0); // E1 + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculation of CHITEST failed", 0.2801, m_pDoc->GetValue(aPos), 10e-4); + m_pDoc->SetValue(1, 1, 0, 0.0); // B2 + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculation of CHITEST failed", 0.1410, m_pDoc->GetValue(aPos), 10e-4); + + // 3x3 matrices test + m_pDoc->SetString(aPos, "=CHITEST(A1:C3;D1:F3)"); + aVal = m_pDoc->GetString(aPos); + CPPUNIT_ASSERT_MESSAGE("CHITEST should return Err:502 for matrices with empty", + OUString::createFromAscii("Err:502") == aVal); + + m_pDoc->SetValue(2, 0, 0, 3.0); // C1 + m_pDoc->SetValue(2, 1, 0, 2.0); // C2 + m_pDoc->SetValue(2, 2, 0, 3.0); // C3 + m_pDoc->SetValue(0, 2, 0, 4.0); // A3 + m_pDoc->SetValue(1, 2, 0, 2.0); // B3 + m_pDoc->SetValue(5, 0, 0, 1.0); // F1 + m_pDoc->SetValue(5, 1, 0, 2.0); // F2 + m_pDoc->SetValue(5, 2, 0, 3.0); // F3 + m_pDoc->SetValue(3, 2, 0, 3.0); // D3 + m_pDoc->SetValue(4, 2, 0, 1.0); // E3 + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculation of CHITEST failed", 0.1117, m_pDoc->GetValue(aPos), 10e-4); + m_pDoc->SetValue(4, 1, 0, 5.0); // E2 + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculation of CHITEST failed", 0.0215, m_pDoc->GetValue(aPos), 10e-4); + m_pDoc->SetValue(1, 2, 0, 1.0); // B3 + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculation of CHITEST failed", 0.0328, m_pDoc->GetValue(aPos), 10e-4); + m_pDoc->SetValue(5, 0, 0, 3.0); // F1 + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculation of CHITEST failed", 0.1648, m_pDoc->GetValue(aPos), 10e-4); + m_pDoc->SetValue(0, 1, 0, 3.0); // A2 + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculation of CHITEST failed", 0.1870, m_pDoc->GetValue(aPos), 10e-4); + m_pDoc->SetValue(3, 1, 0, 5.0); // D2 + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculation of CHITEST failed", 0.1377, m_pDoc->GetValue(aPos), 10e-4); + m_pDoc->SetValue(3, 2, 0, 4.0); // D3 + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculation of CHITEST failed", 0.1566, m_pDoc->GetValue(aPos), 10e-4); + + m_pDoc->SetValue(0, 0, 0, 0.0); // A1 + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculation of CHITEST failed", 0.0868, m_pDoc->GetValue(aPos), 10e-4); + + // no convergence error + m_pDoc->SetValue(4, 0, 0, 0.0); // E1 + aVal = m_pDoc->GetString(aPos); + CPPUNIT_ASSERT(OUString::createFromAscii("Err:523") == aVal); + m_pDoc->SetValue(4, 0, 0, 3.0); // E1 + + // zero in all cells + m_pDoc->SetValue(0, 1, 0, 0.0); // A2 + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculation of CHITEST failed", 0.0150, m_pDoc->GetValue(aPos), 10e-4); + m_pDoc->SetValue(0, 2, 0, 0.0); // A3 + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculation of CHITEST failed", 0.0026, m_pDoc->GetValue(aPos), 10e-4); + m_pDoc->SetValue(1, 0, 0, 0.0); // B1 + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculation of CHITEST failed", 0.00079, m_pDoc->GetValue(aPos), 10e-5); + m_pDoc->SetValue(1, 2, 0, 0.0); // B3 + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculation of CHITEST failed", 0.0005, m_pDoc->GetValue(aPos), 10e-4); + m_pDoc->SetValue(2, 0, 0, 0.0); // C1 + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculation of CHITEST failed", 0.0001, m_pDoc->GetValue(aPos), 10e-4); + m_pDoc->SetValue(2, 1, 0, 0.0); // C2 + m_pDoc->SetValue(2, 2, 0, 0.0); // C3 + m_pDoc->SetValue(3, 0, 0, 0.0); // D1 + aVal = m_pDoc->GetString(aPos); + CPPUNIT_ASSERT_MESSAGE("CHITEST should return #VALUE! for matrices with empty", + OUString::createFromAscii("#VALUE!") == aVal); + m_pDoc->SetValue(3, 1, 0, 0.0); // D2 + m_pDoc->SetValue(3, 2, 0, 0.0); // D3 + m_pDoc->SetValue(4, 0, 0, 0.0); // E1 + m_pDoc->SetValue(4, 1, 0, 0.0); // E2 + m_pDoc->SetValue(4, 2, 0, 0.0); // E3 + m_pDoc->SetValue(5, 0, 0, 0.0); // F1 + m_pDoc->SetValue(5, 1, 0, 0.0); // F2 + m_pDoc->SetValue(5, 2, 0, 0.0); // F3 + aVal = m_pDoc->GetString(aPos); + CPPUNIT_ASSERT_MESSAGE("CHITEST should return #VALUE! for matrices with empty", + OUString::createFromAscii("#VALUE!") == aVal); + + m_pDoc->DeleteTab(0); +} + + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |