Kaydet (Commit) f10be151 authored tarafından Tor Lillqvist's avatar Tor Lillqvist

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
üst 03eae494
...@@ -66,6 +66,7 @@ public: ...@@ -66,6 +66,7 @@ public:
virtual bool load( const OUString &rFilter, const OUString &rURL, virtual bool load( const OUString &rFilter, const OUString &rURL,
const OUString &rUserData, SfxFilterFlags nFilterFlags, const OUString &rUserData, SfxFilterFlags nFilterFlags,
SotClipboardFormatId nClipboardID, unsigned int nFilterVersion) override; SotClipboardFormatId nClipboardID, unsigned int nFilterVersion) override;
void testSystematic();
void testSharedFormulaXLS(); void testSharedFormulaXLS();
#if 0 #if 0
void testSharedFormulaXLSGroundWater(); void testSharedFormulaXLSGroundWater();
...@@ -299,6 +300,7 @@ public: ...@@ -299,6 +300,7 @@ public:
void testFinancialMDurationFormula1(); void testFinancialMDurationFormula1();
CPPUNIT_TEST_SUITE(ScOpenCLTest); CPPUNIT_TEST_SUITE(ScOpenCLTest);
CPPUNIT_TEST(testSystematic);
CPPUNIT_TEST(testSharedFormulaXLS); CPPUNIT_TEST(testSharedFormulaXLS);
CPPUNIT_TEST(testFinacialFormula); CPPUNIT_TEST(testFinacialFormula);
CPPUNIT_TEST(testStatisticalFormulaFisher); CPPUNIT_TEST(testStatisticalFormulaFisher);
...@@ -702,6 +704,98 @@ void ScOpenCLTest::testSharedFormulaXLSGroundWater() ...@@ -702,6 +704,98 @@ void ScOpenCLTest::testSharedFormulaXLSGroundWater()
} }
#endif #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() void ScOpenCLTest::testSharedFormulaXLS()
{ {
if(!initTestEnv("sum_ex.", XLS, false)) if(!initTestEnv("sum_ex.", XLS, false))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment