diff options
author | Tor Lillqvist <tml@collabora.com> | 2015-10-15 12:59:53 +0300 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2015-10-16 13:20:49 +0100 |
commit | 9db43e72088faa8326ca941b84d422726448293a (patch) | |
tree | 783bac555023dafb4ac7eebd923d691dd000dfd5 | |
parent | 127c268387e25a1f1c4b75b5991a83d383be7b92 (diff) |
tdf#94924: Add a more systematic OpenCL unit test
Avoid the horrible convention of hard-coding in a C++ unit test code
addresses of data in the spreadsheet document being tested. Instead,
mark the expected (= as calculated by Excel) and calculated (by
LibreOffice) formula results, rectangular blocks of data, so that the
C++ code can easily find it, and then compare. This is much more
flexible. No need to edit hardoded row and column numbers in the C++
code when adding more test data.
The systematic.xls file has documentation on how to maintain it.
Change-Id: I4fb088fe21831dd3b3213d21916460a708aa0842
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
-rwxr-xr-x | sc/qa/unit/data/xls/systematic.xls | bin | 0 -> 77824 bytes | |||
-rw-r--r-- | sc/qa/unit/opencl-test.cxx | 94 |
2 files changed, 94 insertions, 0 deletions
diff --git a/sc/qa/unit/data/xls/systematic.xls b/sc/qa/unit/data/xls/systematic.xls Binary files differnew file mode 100755 index 000000000000..b3427b51a956 --- /dev/null +++ b/sc/qa/unit/data/xls/systematic.xls diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx index 17b0e1198ecf..7848627cb8c6 100644 --- a/sc/qa/unit/opencl-test.cxx +++ b/sc/qa/unit/opencl-test.cxx @@ -66,6 +66,7 @@ public: virtual bool load( const OUString &rFilter, const OUString &rURL, const OUString &rUserData, SfxFilterFlags nFilterFlags, SotClipboardFormatId nClipboardID, unsigned int nFilterVersion) SAL_OVERRIDE; + void testSystematic(); void testSharedFormulaXLS(); #if 0 void testSharedFormulaXLSGroundWater(); @@ -299,6 +300,7 @@ public: void testFinancialMDurationFormula1(); CPPUNIT_TEST_SUITE(ScOpenCLTest); + CPPUNIT_TEST(testSystematic); CPPUNIT_TEST(testSharedFormulaXLS); CPPUNIT_TEST(testFinacialFormula); CPPUNIT_TEST(testStatisticalFormulaFisher); @@ -702,6 +704,98 @@ void ScOpenCLTest::testSharedFormulaXLSGroundWater() } #endif +void ScOpenCLTest::testSystematic() +{ + if(!initTestEnv("systematic.", XLS, false)) + return; + + ScDocument& rDoc = xDocSh->GetDocument(); + rDoc.CalcAll(); + + int nAVertBegin(0), nAVertEnd(0), nBVertBegin(0), nBVertEnd(0); + int nAHorEnd(0), nBHorEnd(0); + + int nRow, nCol; + for (nRow = 0; nRow < 1000; ++nRow) + { + if (rDoc.GetString(ScAddress(0, nRow, 0)) == "a") + { + nAVertBegin = nRow + 1; + + for (nCol = 0; nCol < 1000; ++nCol) + { + if (rDoc.GetString(ScAddress(nCol, nRow, 0)) != "a") + { + nAHorEnd = nCol; + break; + } + } + break; + } + } + for (; nRow < 1000; ++nRow) + { + if (rDoc.GetString(ScAddress(0, nRow, 0)) != "a") + { + nAVertEnd = nRow; + break; + } + } + + for (; nRow < 1000; ++nRow) + { + if (rDoc.GetString(ScAddress(0, nRow, 0)) == "b") + { + nBVertBegin = nRow + 1; + + for (nCol = 0; nCol < 1000; ++nCol) + { + if (rDoc.GetString(ScAddress(nCol, nRow, 0)) != "b") + { + nBHorEnd = nCol; + break; + } + } + break; + } + } + for (; nRow < 1000; ++nRow) + { + if (rDoc.GetString(ScAddress(0, nRow, 0)) != "b") + { + nBVertEnd = nRow; + break; + } + } + + assert(nAVertBegin != 0); + assert(nBVertBegin != 0); + assert(nAVertEnd > nAVertBegin + 100); + assert(nBVertEnd > nBVertBegin + 100); + assert((nAVertEnd-nAVertBegin) == (nBVertEnd-nBVertBegin)); + assert(nAHorEnd > 10); + assert(nBHorEnd > 10); + assert(nAHorEnd == nBHorEnd); + + for (SCROW i = nAVertBegin; i < nAVertEnd; ++i) + { + for (int j = 1; j < nAHorEnd; ++j) + { + double fLibre = rDoc.GetValue(ScAddress(j, i, 0)); + double fExcel = rDoc.GetValue(ScAddress(j, nBVertBegin + (i - nAVertBegin), 0)); + + const OString sFailedMessage = + OString(static_cast<sal_Char>('A'+j)) + + OString::number(i+1) + + "!=" + + OString(static_cast<sal_Char>('A'+j)) + + OString::number(nBVertBegin+(i-nAVertBegin)+1); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(sFailedMessage.getStr(), fExcel, fLibre, 1e-10); + } + } +} + + void ScOpenCLTest::testSharedFormulaXLS() { if(!initTestEnv("sum_ex.", XLS, false)) |