diff options
author | Tor Lillqvist <tml@collabora.com> | 2015-10-15 12:59:53 +0300 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2015-10-15 13:45:45 +0300 |
commit | f10be151884d72b632547b570812759a67fd5c46 (patch) | |
tree | b0e13b63bb16938e5abc3043cea228581563f008 /sc | |
parent | 03eae494cfdb0c75188e6c2c85a4b59acba0ef12 (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
Diffstat (limited to 'sc')
-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 5bc34e3ba9de..2627003d802f 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) 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)) |