From a7f1df962c1c6cb0e1d51d8a67f0190c64962544 Mon Sep 17 00:00:00 2001 From: Winfried Donkers Date: Wed, 29 Mar 2017 18:24:33 +0200 Subject: tdf#106796 Make CHITEST and CHISQ.TEST comply with ODFF1.2 and improve interoperability with Excel. Note: the functions now don't accept empty datasets, just like Excel. This is not fully compliant with ODFF1.2. A change request to make ODFF reflect this behaviour would be appropiate. Change-Id: I70225a4dc8e20a035d25af4290137714cda95624 Reviewed-on: https://gerrit.libreoffice.org/35864 Reviewed-by: Eike Rathke Tested-by: Jenkins --- .../functions/statistical/fods/chisq.test.fods | 609 +++++++++++-------- .../data/functions/statistical/fods/chitest.fods | 659 ++++++++++++--------- sc/qa/unit/ucalc_formula.cxx | 26 +- sc/source/core/tool/interpr3.cxx | 34 +- 4 files changed, 753 insertions(+), 575 deletions(-) (limited to 'sc') diff --git a/sc/qa/unit/data/functions/statistical/fods/chisq.test.fods b/sc/qa/unit/data/functions/statistical/fods/chisq.test.fods index 1e4ba54e961b..9eac30114eb7 100644 --- a/sc/qa/unit/data/functions/statistical/fods/chisq.test.fods +++ b/sc/qa/unit/data/functions/statistical/fods/chisq.test.fods @@ -1,13 +1,13 @@ - 2017-02-24T19:11:51.019270939P0D1LibreOfficeDev/5.4.0.0.alpha0$Linux_X86_64 LibreOffice_project/36de6c50684c8241969a2064d30aff41e0bc5d97 + 2017-02-24T19:11:51.019270939P0D1LibreOfficeDev/5.4.0.0.alpha1$Linux_X86_64 LibreOffice_project/6d424f07701bf26d8fb173563b567d5f097c33e2 0 0 98520 - 12262 + 16164 view1 @@ -31,8 +31,8 @@ false - 4 - 1 + 2 + 29 0 0 0 @@ -50,7 +50,7 @@ Sheet2 - 1241 + 1048 0 100 60 @@ -91,10 +91,12 @@ true true true + true + true false 12632256 false - Lexmark-E352dn + Generic Printer cs @@ -125,14 +127,12 @@ - true - true 3 1 true 1 true - sgH+/0xleG1hcmstRTM1MmRuAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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zm false 0 @@ -3334,33 +3334,33 @@ - + - + - + - + - + - + @@ -3374,7 +3374,7 @@ - + @@ -3445,19 +3445,12 @@ - + - - - - - - - - - - + + + @@ -3466,6 +3459,9 @@ + + + @@ -3499,6 +3495,9 @@ + + + @@ -3548,6 +3547,18 @@ + + + + + + + + + + + + @@ -3563,15 +3574,15 @@ - ??? (???) + ???(???) - 00/00/0000, 00:00:00 + 00/00/0000, 00:00:00 - Page 1 / 99 + Page 1/ 99 @@ -3792,7 +3803,7 @@ 1.16440189336067E-29 - + TRUE @@ -3855,7 +3866,7 @@ 9.03490480352966E-10 - + TRUE @@ -3923,7 +3934,7 @@ 1.34423459890025E-09 - + TRUE @@ -3989,7 +4000,7 @@ 0 - + TRUE @@ -4047,7 +4058,7 @@ 1.12896923737676E-11 - + TRUE @@ -4110,7 +4121,7 @@ 0.997916658208002 - + TRUE @@ -4173,7 +4184,7 @@ 0.001549713633046 - + TRUE @@ -4229,19 +4240,21 @@ - - Err:502 + + 2.02524730723578E-002 - - Err:502 + + 0.020252473072358 - + TRUE =CHISQ.TEST(L4:L10,M4:M10) - + + tdf106786 + 0.16 @@ -4293,7 +4306,7 @@ 1.66789802691649E-16 - + TRUE @@ -4345,7 +4358,7 @@ 0 - + TRUE @@ -4390,7 +4403,7 @@ 0.000308192017008 - + TRUE @@ -4422,7 +4435,7 @@ 0.816527699624637 - + TRUE @@ -4453,14 +4466,24 @@ 0.87928370831036 - + TRUE =CHISQ.TEST(F2:I2,F3:I3) - - + + + 12 + + + 14 + + + + 11 + + @@ -4484,7 +4507,7 @@ 0.911826184650631 - + TRUE @@ -4500,8 +4523,17 @@ 1 - - + + + 17 + + + + 14 + + + 0 + @@ -4518,16 +4550,21 @@ 0.9314883584606 - + TRUE =CHISQ.TEST(F4:I4,F5:I5) - + + + 18 + - + + 18 + @@ -4544,16 +4581,26 @@ 0.944539492146675 - + TRUE =CHISQ.TEST(F5:I5,F6:I6) - + + + 24 + + + 34 + - - + + 19 + + + 35 + @@ -4570,7 +4617,7 @@ 0.953774634535083 - + TRUE @@ -4578,10 +4625,20 @@ - + + + 45 + + + 47 + - - + + 44 + + + 0 + @@ -4598,7 +4655,7 @@ 0.960619865110165 - + TRUE @@ -4624,7 +4681,7 @@ 0.965875482278625 - + TRUE @@ -4650,7 +4707,7 @@ 0.970023721006623 - + TRUE @@ -4676,7 +4733,7 @@ 0.973371683412022 - + TRUE @@ -4695,11 +4752,85 @@ - + + + Err:502 + + + Err:502 + + + TRUE + + + =CHISQ.TEST(F18:H19,F20:H21) + + + + 2017-03-28T00:00:00 + Not (yet) in ODFF1.2, but Excel has error (#DIV/0!) as result and use case is purely imaginary (statistic functions with data have no use). + + tdf106786, empty datasets not allowed + + + + + + + - - - + + + + + + + + + 0.726644540598389 + + + 0.726644540598389 + + + TRUE + + + =CHISQ.TEST(I13:J17,L13:M17) + + + tdf106786 + + + + + + + + + + + + + + + + + 0.722466013915364 + + + 0.722466013915364 + + + TRUE + + + =CHISQ.TEST(I14:J18,L14:M18) + + + tdf106786 + + @@ -4713,13 +4844,82 @@ + + 0.721391783070078 + + + 0.721391783070078 + + + TRUE + + + =CHISQ.TEST(J13:K17,M13:N17) + + + tdf106786 + + + + + + + + + + + + + + + + #DIV/0! + + + #DIV/0! + + + TRUE + + + =CHISQ.TEST(J14:K18,M14:N18) + + + tdf106786, expected value cannot be 0 + + + - - - + + + + + + + + + + + + + 0.999898925814582 + + + 0.999898925814582 + + + TRUE + + + =CHISQ.TEST(K13:L17,N13:O17) + + + tdf106786 + + - + @@ -4730,10 +4930,39 @@ - + + + #DIV/0! + + + #DIV/0! + + + TRUE + + + =CHISQ.TEST(K14:L18,N14:O18) + + + tdf106786, expected value cannot be 0 + + + + + + + + + + + + + + + - + @@ -4751,7 +4980,7 @@ - + @@ -4769,7 +4998,7 @@ - + @@ -4787,7 +5016,7 @@ - + @@ -4805,7 +5034,7 @@ - + @@ -4825,7 +5054,7 @@ - + @@ -4843,7 +5072,7 @@ - + @@ -4861,7 +5090,7 @@ - + @@ -4879,7 +5108,7 @@ - + @@ -4897,7 +5126,7 @@ - + @@ -4915,7 +5144,7 @@ - + @@ -4933,7 +5162,7 @@ - + @@ -4949,7 +5178,7 @@ - + @@ -4965,7 +5194,7 @@ - + @@ -4979,7 +5208,7 @@ - + @@ -4993,7 +5222,7 @@ - + @@ -5006,10 +5235,24 @@ - + + + + + + + + + + + + + + + - + @@ -5023,7 +5266,7 @@ - + @@ -5037,7 +5280,7 @@ - + @@ -5051,7 +5294,7 @@ - + @@ -5065,7 +5308,7 @@ - + @@ -5078,7 +5321,7 @@ - + @@ -5090,7 +5333,7 @@ - + @@ -5102,7 +5345,7 @@ - + @@ -5113,19 +5356,7 @@ - - - - - - - - - - - - - + @@ -5169,150 +5400,10 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + diff --git a/sc/qa/unit/data/functions/statistical/fods/chitest.fods b/sc/qa/unit/data/functions/statistical/fods/chitest.fods index ba453d750f54..62e3ab0f53b3 100644 --- a/sc/qa/unit/data/functions/statistical/fods/chitest.fods +++ b/sc/qa/unit/data/functions/statistical/fods/chitest.fods @@ -1,13 +1,13 @@ - 2017-02-24T19:13:49.043725059P0D1LibreOfficeDev/5.4.0.0.alpha0$Linux_X86_64 LibreOffice_project/36de6c50684c8241969a2064d30aff41e0bc5d97 + 2017-02-24T19:13:49.043725059P0D1LibreOfficeDev/5.4.0.0.alpha1$Linux_X86_64 LibreOffice_project/6d424f07701bf26d8fb173563b567d5f097c33e2 0 0 98520 - 12262 + 16164 view1 @@ -32,7 +32,7 @@ 2 - 9 + 29 0 0 0 @@ -50,7 +50,7 @@ Sheet2 - 1241 + 1048 0 100 60 @@ -91,10 +91,12 @@ true true true + true + true false 12632256 false - Lexmark-E352dn + Generic Printer c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ERhdGEKUGFnZVNpemU6TGV0dGVyAER1cGxleDpOb25lAAASAENPTVBBVF9EVVBMRVhfTU9ERQ8ARHVwbGV4TW9kZTo6T2Zm false 0 @@ -3325,9 +3325,6 @@ - - - @@ -3337,47 +3334,42 @@ - - - - - - + - + - + - + - + - + - + @@ -3386,42 +3378,47 @@ - + + + + + + - + - + - + - + - + - + @@ -3448,19 +3445,12 @@ - + - - - - - - - - - - + + + @@ -3469,6 +3459,9 @@ + + + @@ -3502,6 +3495,9 @@ + + + @@ -3551,6 +3547,18 @@ + + + + + + + + + + + + @@ -3566,15 +3574,15 @@ - ??? (???) + ???(???) - 00/00/0000, 00:00:00 + 00/00/0000, 00:00:00 - Page 1 / 99 + Page 1/ 99 @@ -3609,10 +3617,10 @@ - + - + CHITEST Function @@ -3621,10 +3629,10 @@ - + Result - + TRUE @@ -3633,13 +3641,13 @@ - + Sheet - + Result - + Description @@ -3647,7 +3655,7 @@ 1 - + TRUE @@ -3656,37 +3664,37 @@ - + - - + + - + - + - + - + - + @@ -3712,7 +3720,7 @@ - + @@ -3795,7 +3803,7 @@ 1.16440189336067E-29 - + TRUE @@ -3858,7 +3866,7 @@ 9.03490480352966E-10 - + TRUE @@ -3926,7 +3934,7 @@ 1.34423459890025E-09 - + TRUE @@ -3992,7 +4000,7 @@ 0 - + TRUE @@ -4050,7 +4058,7 @@ 1.12896923737676E-11 - + TRUE @@ -4113,7 +4121,7 @@ 0.997916658208002 - + TRUE @@ -4176,7 +4184,7 @@ 0.001549713633046 - + TRUE @@ -4232,19 +4240,21 @@ - - Err:502 + + 2.02524730723578E-002 - - Err:502 + + 0.020252473072358 - + TRUE =CHITEST(L4:L10,M4:M10) - + + tdf106786 + 0.16 @@ -4296,7 +4306,7 @@ 1.66789802691649E-16 - + TRUE @@ -4348,7 +4358,7 @@ 0 - + TRUE @@ -4393,7 +4403,7 @@ 0.000308192017008 - + TRUE @@ -4425,7 +4435,7 @@ 0.816527699624637 - + TRUE @@ -4456,14 +4466,24 @@ 0.87928370831036 - + TRUE =CHITEST(F2:I2,F3:I3) - - + + + 12 + + + 14 + + + + 11 + + @@ -4487,7 +4507,7 @@ 0.911826184650631 - + TRUE @@ -4503,8 +4523,17 @@ 1 - - + + + 17 + + + + 14 + + + 0 + @@ -4521,16 +4550,21 @@ 0.9314883584606 - + TRUE =CHITEST(F4:I4,F5:I5) - + + + 18 + - + + 18 + @@ -4547,16 +4581,26 @@ 0.944539492146675 - + TRUE =CHITEST(F5:I5,F6:I6) - + + + 24 + + + 34 + - - + + 19 + + + 35 + @@ -4573,7 +4617,7 @@ 0.953774634535083 - + TRUE @@ -4581,10 +4625,20 @@ - + + + 45 + + + 47 + - - + + 44 + + + 0 + @@ -4601,7 +4655,7 @@ 0.960619865110165 - + TRUE @@ -4627,7 +4681,7 @@ 0.965875482278625 - + TRUE @@ -4653,7 +4707,7 @@ 0.970023721006623 - + TRUE @@ -4679,7 +4733,7 @@ 0.973371683412022 - + TRUE @@ -4698,11 +4752,27 @@ - - - - - + + + Err:502 + + + Err:502 + + + TRUE + + + =CHITEST(F18:H19,F20:H21) + + + + 2017-03-28T00:00:00 + Not (yet) in ODFF1.2, but Excel has error (#DIV/0!) as result and use case is purely imaginary (statistic functions with data have no use). + + tdf106786, empty datasets not allowed + + @@ -4716,10 +4786,51 @@ + + 0.726644540598389 + + + 0.726644540598389 + + + TRUE + + + =CHITEST(I13:J17,L13:M17) + + + tdf106786 + + + + + + + - - - + + + + + + + + + 0.722466013915364 + + + 0.722466013915364 + + + TRUE + + + =CHITEST(I14:J18,L14:M18) + + + tdf106786 + + @@ -4733,13 +4844,82 @@ + + 0.721391783070078 + + + 0.721391783070078 + + + TRUE + + + =CHITEST(J13:K17,M13:N17) + + + tdf106786 + + + + + + + + + + + + + + + + #DIV/0! + + + #DIV/0! + + + TRUE + + + =CHITEST(J14:K18,M14:N18) + + + tdf106786, expected value cannot be 0 + + + - - - + + + + + + + + + + + + + 0.999898925814582 + + + 0.999898925814582 + + + TRUE + + + =CHITEST(K13:L17,N13:O17) + + + tdf106786 + + - + @@ -4750,10 +4930,39 @@ - + + + #DIV/0! + + + #DIV/0! + + + TRUE + + + =CHITEST(K14:L18,N14:O18) + + + tdf106786, expected value cannot be 0 + + + + + + + + + + + + + + + - + @@ -4771,7 +4980,7 @@ - + @@ -4789,7 +4998,7 @@ - + @@ -4807,7 +5016,7 @@ - + @@ -4825,7 +5034,7 @@ - + @@ -4845,7 +5054,7 @@ - + @@ -4863,7 +5072,7 @@ - + @@ -4881,7 +5090,7 @@ - + @@ -4899,7 +5108,7 @@ - + @@ -4917,7 +5126,7 @@ - + @@ -4935,7 +5144,7 @@ - + @@ -4953,7 +5162,7 @@ - + @@ -4969,7 +5178,7 @@ - + @@ -4985,7 +5194,7 @@ - + @@ -4999,7 +5208,7 @@ - + @@ -5013,7 +5222,7 @@ - + @@ -5026,10 +5235,24 @@ - + - + + + + + + + + + + + + + + + @@ -5043,7 +5266,7 @@ - + @@ -5057,7 +5280,7 @@ - + @@ -5071,7 +5294,7 @@ - + @@ -5085,7 +5308,7 @@ - + @@ -5098,7 +5321,7 @@ - + @@ -5110,7 +5333,7 @@ - + @@ -5122,7 +5345,7 @@ - + @@ -5133,19 +5356,7 @@ - - - - - - - - - - - - - + @@ -5189,150 +5400,10 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx index 9ddf37d4f765..9603934f3b52 100644 --- a/sc/qa/unit/ucalc_formula.cxx +++ b/sc/qa/unit/ucalc_formula.cxx @@ -6718,27 +6718,27 @@ void Test::testFuncCHITEST() 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_EQUAL_MESSAGE("CHITEST should return Err:502 for matrices with different size", + CPPUNIT_ASSERT_EQUAL_MESSAGE("CHITEST should return Err:502 for matrix with empty cells", OUString("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_EQUAL_MESSAGE("CHITEST should return Err:502 for matrices with different size", - OUString("Err:502"), aVal); - m_pDoc->SetValue(4, 0, 0, 2.0); // E1 + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculation of CHITEST failed", 0.3613, m_pDoc->GetValue(aPos), 10e-4); + 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(4, 0, 0, 0.0); // E1 + aVal = m_pDoc->GetString(aPos); + CPPUNIT_ASSERT_EQUAL_MESSAGE("CHITEST should return #DIV/0 for expected values of 0", OUString("#DIV/0!"), aVal); + m_pDoc->SetValue(4, 0, 0, 3.0); // E1 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_EQUAL_MESSAGE("CHITEST should return Err:502 for matrices with empty", - OUString("Err:502"), aVal); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculation of CHITEST failed", 0.7051, m_pDoc->GetValue(aPos), 10e-4); m_pDoc->SetValue(2, 0, 0, 3.0); // C1 m_pDoc->SetValue(2, 1, 0, 2.0); // C2 @@ -6785,7 +6785,7 @@ void Test::testFuncCHITEST() 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 + m_pDoc->SetValue(4, 0, 0, 1.0E308); // E1 aVal = m_pDoc->GetString(aPos); CPPUNIT_ASSERT_EQUAL(OUString("Err:523"), aVal); m_pDoc->SetValue(4, 0, 0, 3.0); // E1 @@ -6805,8 +6805,8 @@ void Test::testFuncCHITEST() 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_EQUAL_MESSAGE("CHITEST should return #VALUE! for matrices with empty", - OUString("#VALUE!"), aVal); + CPPUNIT_ASSERT_EQUAL_MESSAGE("CHITEST should return #DIV/0! for matrices with empty", + OUString("#DIV/0!"), 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 @@ -6816,8 +6816,8 @@ void Test::testFuncCHITEST() 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_EQUAL_MESSAGE("CHITEST should return #VALUE! for matrices with empty", - OUString("#VALUE!"), aVal); + CPPUNIT_ASSERT_EQUAL_MESSAGE("CHITEST should return #DIV/0! for matrices with empty", + OUString("#DIV/0!"), aVal); m_pDoc->DeleteTab(0); } diff --git a/sc/source/core/tool/interpr3.cxx b/sc/source/core/tool/interpr3.cxx index 2ed998b836bb..950648694db6 100644 --- a/sc/source/core/tool/interpr3.cxx +++ b/sc/source/core/tool/interpr3.cxx @@ -2805,23 +2805,39 @@ void ScInterpreter::ScChiTest() return; } double fChi = 0.0; + bool bEmpty = true; for (SCSIZE i = 0; i < nC1; i++) { for (SCSIZE j = 0; j < nR1; j++) { - if (!pMat1->IsString(i,j) && !pMat2->IsString(i,j)) - { - double fValX = pMat1->GetDouble(i,j); - double fValE = pMat2->GetDouble(i,j); - fChi += sc::divide( (fValX - fValE) * (fValX - fValE), fValE); - } - else + if (!(pMat1->IsEmpty(i,j) || pMat2->IsEmpty(i,j))) { - PushIllegalArgument(); - return; + bEmpty = false; + if (!pMat1->IsString(i,j) && !pMat2->IsString(i,j)) + { + double fValX = pMat1->GetDouble(i,j); + double fValE = pMat2->GetDouble(i,j); + if ( fValE == 0.0 ) + { + PushError(FormulaError::DivisionByZero); + return; + } + fChi += sc::divide( (fValX - fValE) * (fValX - fValE), fValE); + } + else + { + PushIllegalArgument(); + return; + } } } } + if ( bEmpty ) + { + // not in ODFF1.2, but for interoperability with Excel + PushIllegalArgument(); + return; + } double fDF; if (nC1 == 1 || nR1 == 1) { -- cgit