[Libreoffice-commits] .: Branch 'feature/calc-matrix-rework' - 4 commits - sc/qa sc/source
Kohei Yoshida
kohei at kemper.freedesktop.org
Thu Dec 16 18:56:22 PST 2010
sc/qa/unit/ucalc.cxx | 13 +++++++
sc/source/core/tool/scmatrix.cxx | 69 ++++++++++++++++++++-------------------
2 files changed, 50 insertions(+), 32 deletions(-)
New commits:
commit 04e014bbf864e30576eb4e5c10bc87a4eafd2c10
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Thu Dec 16 21:55:48 2010 -0500
Unit test for matrix's And and Or evaluations.
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index ce8b522..77e8d5f 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -291,6 +291,8 @@ void Test::testMatrix()
pMat->Resize(4, 10);
pMat->GetDimensions(nC, nR);
CPPUNIT_ASSERT_MESSAGE("matrix size is not as expected", nC == 4 && nR == 10);
+ CPPUNIT_ASSERT_MESSAGE("both 'and' and 'or' should evaluate to false",
+ !pMat->And() && !pMat->Or());
// Resizing into a larger matrix should fill the void space with zeros.
checkMatrixElements<AllZeroMatrix>(*pMat);
@@ -298,6 +300,11 @@ void Test::testMatrix()
pMat->FillDouble(3.0, 1, 2, 2, 8);
checkMatrixElements<PartiallyFilledZeroMatrix>(*pMat);
CPPUNIT_ASSERT_MESSAGE("matrix is expected to be numeric", pMat->IsNumeric());
+ CPPUNIT_ASSERT_MESSAGE("partially non-zero matrix should evaluate false on 'and' and true on 'or",
+ !pMat->And() && pMat->Or());
+ pMat->FillDouble(5.0, 0, 0, nC-1, nR-1);
+ CPPUNIT_ASSERT_MESSAGE("fully non-zero matrix should evaluate true both on 'and' and 'or",
+ pMat->And() && pMat->Or());
}
// Now test the emtpy matrix types.
commit ce8a33e2f99049c4ec88bbcf3e378be35d7dbbab
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Thu Dec 16 21:48:30 2010 -0500
Test for empty path element type.
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 9119420..ce8b522 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -261,6 +261,11 @@ struct PartiallyFilledEmptyMatrix
CPPUNIT_ASSERT_MESSAGE("element is not of value type", rVal.nType == SC_MATVAL_STRING);
CPPUNIT_ASSERT_MESSAGE("element value is not what is expected", rVal.pS->EqualsAscii("Test"));
}
+ else if (nCol == 8 && nRow == 11)
+ {
+ CPPUNIT_ASSERT_MESSAGE("element is not of empty path type", rVal.nType == SC_MATVAL_EMPTYPATH);
+ CPPUNIT_ASSERT_MESSAGE("value of \"empty\" element is expected to be zero", rVal.fVal == 0.0);
+ }
else
{
CPPUNIT_ASSERT_MESSAGE("element is not of empty type", rVal.nType == SC_MATVAL_EMPTY);
@@ -310,6 +315,7 @@ void Test::testMatrix()
pMat->PutDouble(-12.5, 4, 5);
rtl::OUString aStr(RTL_CONSTASCII_USTRINGPARAM("Test"));
pMat->PutString(aStr, 8, 2);
+ pMat->PutEmptyPath(8, 11);
checkMatrixElements<PartiallyFilledEmptyMatrix>(*pMat);
}
}
commit 8ed18c28432bd451bee3c6fb0925191e2989c266
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Thu Dec 16 21:46:45 2010 -0500
Removed code duplication with template.
diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index efe1907..9f778e6 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -518,7 +518,7 @@ ScMatrixValue ScMatrixImpl::Get(SCSIZE nC, SCSIZE nR) const
break;
case mdds::element_empty:
// Empty path equals empty plus flag.
- aVal.nType == maMat.get_flag(nR, nC) ? SC_MATVAL_EMPTYPATH : SC_MATVAL_EMPTY;
+ aVal.nType = maMat.get_flag(nR, nC) ? SC_MATVAL_EMPTYPATH : SC_MATVAL_EMPTY;
aVal.fVal = 0.0;
default:
;
@@ -677,58 +677,63 @@ void ScMatrixImpl::CompareGreaterEqual()
compareMatrix<ElemGreaterEqual>(maMat);
}
-double ScMatrixImpl::And()
+namespace {
+
+struct AndEvaluator
{
- // All elements must be of value type.
- // True only if all the elements have non-zero values.
- pair<size_t,size_t> aDim = maMat.size();
+ bool isBadElem(double fVal) const { return fVal == 0; }
+ bool returnOnElem() const { return false; }
+ bool returnOnAllElems() const { return true; }
+};
+
+struct OrEvaluator
+{
+ bool isBadElem(double fVal) const { return fVal != 0; }
+ bool returnOnElem() const { return true; }
+ bool returnOnAllElems() const { return false; }
+};
+
+template <typename _Evaluator>
+bool EvalMatrix(const MatrixImplType& rMat)
+{
+ _Evaluator aEval;
+ pair<size_t,size_t> aDim = rMat.size();
size_t nRows = aDim.first, nCols = aDim.second;
for (size_t i = 0; i < nRows; ++i)
{
for (size_t j = 0; j < nCols; ++j)
{
- matrix_element_t eType = maMat.get_type(i, j);
+ matrix_element_t eType = rMat.get_type(i, j);
if (eType != mdds::element_numeric && eType == mdds::element_boolean)
// assuming a CompareMat this is an error
return CreateDoubleError(errIllegalArgument);
- double fVal = maMat.get_numeric(i, j);
+ double fVal = rMat.get_numeric(i, j);
if (!::rtl::math::isFinite(fVal))
// DoubleError
return fVal;
- if (fVal == 0.0)
- return false;
+ if (aEval.isBadElem(fVal))
+ return aEval.returnOnElem();
}
}
- return true;
+ return aEval.returnOnAllElems();
+}
+
+}
+
+double ScMatrixImpl::And()
+{
+ // All elements must be of value type.
+ // True only if all the elements have non-zero values.
+ return EvalMatrix<AndEvaluator>(maMat);
}
double ScMatrixImpl::Or()
{
// All elements must be of value type.
// True if at least one element has a non-zero value.
- pair<size_t,size_t> aDim = maMat.size();
- size_t nRows = aDim.first, nCols = aDim.second;
- for (size_t i = 0; i < nRows; ++i)
- {
- for (size_t j = 0; j < nCols; ++j)
- {
- matrix_element_t eType = maMat.get_type(i, j);
- if (eType != mdds::element_numeric && eType == mdds::element_boolean)
- // assuming a CompareMat this is an error
- return CreateDoubleError(errIllegalArgument);
-
- double fVal = maMat.get_numeric(i, j);
- if (!::rtl::math::isFinite(fVal))
- // DoubleError
- return fVal;
-
- if (fVal != 0.0)
- return true;
- }
- }
- return false;
+ return EvalMatrix<OrEvaluator>(maMat);
}
void ScMatrixImpl::CalcPosition(SCSIZE nIndex, SCSIZE& rC, SCSIZE& rR) const
commit 53c9ef796519212a392a4cd12e89dc9b5704ad9b
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Thu Dec 16 21:24:02 2010 -0500
Check the flag value for empty "path" element type.
diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index 9387bf5..efe1907 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -517,8 +517,8 @@ ScMatrixValue ScMatrixImpl::Get(SCSIZE nC, SCSIZE nR) const
aVal.pS = maMat.get_string(nR, nC);
break;
case mdds::element_empty:
- // TODO: Check for the flag value to differentiate from empty path.
- aVal.nType == SC_MATVAL_EMPTY;
+ // Empty path equals empty plus flag.
+ aVal.nType == maMat.get_flag(nR, nC) ? SC_MATVAL_EMPTYPATH : SC_MATVAL_EMPTY;
aVal.fVal = 0.0;
default:
;
More information about the Libreoffice-commits
mailing list