[Libreoffice-commits] core.git: 3 commits - sc/qa sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Mon Apr 28 10:45:28 PDT 2014


 sc/qa/unit/ucalc.hxx             |    2 +
 sc/qa/unit/ucalc_formula.cxx     |   50 +++++++++++++++++++++++++++++++++++++++
 sc/source/core/tool/scmatrix.cxx |   12 +++++++--
 3 files changed, 62 insertions(+), 2 deletions(-)

New commits:
commit 5233971396b2ed8e280ad68912e1a55e803f3856
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Mon Apr 28 13:44:18 2014 -0400

    Add a bit more test code to test the normal use cases of MIN.
    
    Change-Id: Iad1e120dff49d569e5fb66905e5fe28462759c5a

diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index de1fd11..1ecc5d2 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -2292,6 +2292,18 @@ void Test::testFuncMIN()
     CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(ScAddress(2,0,0)));
     CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(ScAddress(2,1,0)));
 
+    // Inline array input (A4).
+    m_pDoc->SetString(ScAddress(0,3,0), "=MIN({-2;4;3})");
+    CPPUNIT_ASSERT_EQUAL(-2.0, m_pDoc->GetValue(ScAddress(0,3,0)));
+
+    // Add more values to B3:B4.
+    m_pDoc->SetValue(ScAddress(1,2,0),  20.0);
+    m_pDoc->SetValue(ScAddress(1,3,0), -20.0);
+
+    // Get the MIN of B1:B4.
+    m_pDoc->SetString(ScAddress(2,4,0), "=MIN(B1:B4)");
+    CPPUNIT_ASSERT_EQUAL(-20.0, m_pDoc->GetValue(ScAddress(2,4,0)));
+
     m_pDoc->DeleteTab(0);
 }
 
commit 453ea919e70fa9832f11e3ef042bb80cd86892cc
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Mon Apr 28 13:33:08 2014 -0400

    fdo#77969: Return 0 in case of matrix consisting of all empty elements.
    
    Change-Id: I225d50445d7f84a17c0b9492c17247e4c1c9ef44

diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index 32da95a..f21baed 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -1235,12 +1235,14 @@ class CalcMaxMinValue : std::unary_function<MatrixImplType::element_block_type,
 {
     double mfVal;
     bool mbTextAsZero;
+    bool mbHasValue;
 public:
     CalcMaxMinValue( bool bTextAsZero ) :
         mfVal(_Op::init()),
-        mbTextAsZero(bTextAsZero) {}
+        mbTextAsZero(bTextAsZero),
+        mbHasValue(false) {}
 
-    double getValue() const { return mfVal; }
+    double getValue() const { return mbHasValue ? mfVal : 0.0; }
 
     void operator() (const MatrixImplType::element_block_node_type& node)
     {
@@ -1255,6 +1257,8 @@ public:
                 block_type::const_iterator itEnd = block_type::end(*node.data);
                 for (; it != itEnd; ++it)
                     mfVal = _Op::compare(mfVal, *it);
+
+                mbHasValue = true;
             }
             break;
             case mdds::mtm::element_boolean:
@@ -1265,6 +1269,7 @@ public:
                 block_type::const_iterator itEnd = block_type::end(*node.data);
                 double fVal = _Op::boolValue(it, itEnd);
                 mfVal = _Op::compare(mfVal, fVal);
+                mbHasValue = true;
             }
             break;
             case mdds::mtm::element_string:
@@ -1272,7 +1277,10 @@ public:
             {
                 // empty elements are treated as empty strings.
                 if (mbTextAsZero)
+                {
                     mfVal = _Op::compare(mfVal, 0.0);
+                    mbHasValue = true;
+                }
             }
             break;
             default:
commit a4a5f67008a931508a9d963f6b95db9cb9d45aef
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Mon Apr 28 13:23:12 2014 -0400

    fdo#77969: Write test for this corner case.
    
    Change-Id: Iac8a3d0693456a380d3290c7be06136b04b50390

diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 71b33a7..9a81c5e 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -130,6 +130,7 @@ public:
     void testFuncSUM();
     void testFuncPRODUCT();
     void testFuncSUMPRODUCT();
+    void testFuncMIN();
     void testFuncN();
     void testFuncCOUNTIF();
     void testFuncNUMBERVALUE();
@@ -381,6 +382,7 @@ public:
     CPPUNIT_TEST(testFuncSUM);
     CPPUNIT_TEST(testFuncPRODUCT);
     CPPUNIT_TEST(testFuncSUMPRODUCT);
+    CPPUNIT_TEST(testFuncMIN);
     CPPUNIT_TEST(testFuncN);
     CPPUNIT_TEST(testFuncCOUNTIF);
     CPPUNIT_TEST(testFuncNUMBERVALUE);
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index b2caf22..de1fd11 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -2257,6 +2257,44 @@ void Test::testFuncSUMPRODUCT()
     m_pDoc->DeleteTab(0);
 }
 
+void Test::testFuncMIN()
+{
+    sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn on auto recalc.
+    m_pDoc->InsertTab(0, "Formula");
+
+    // A1:A2
+    m_pDoc->SetString(ScAddress(0,0,0), "a");
+    m_pDoc->SetString(ScAddress(0,1,0), "b");
+
+    // B1:B2
+    m_pDoc->SetValue(ScAddress(1,0,0), 1.0);
+    m_pDoc->SetValue(ScAddress(1,1,0), 2.0);
+
+    // Matrix in C1:C2.
+    ScMarkData aMark;
+    aMark.SelectOneTable(0);
+    m_pDoc->InsertMatrixFormula(2, 0, 2, 1, aMark, "=MIN(IF(A1:A2=\"c\";B1:B2))");
+
+    // Formula cell in C1:C2 should be a 1x2 matrix array.
+    ScFormulaCell* pFC = m_pDoc->GetFormulaCell(ScAddress(2,0,0));
+    CPPUNIT_ASSERT(pFC);
+    CPPUNIT_ASSERT_MESSAGE("This formula should be an array.", pFC->GetMatrixFlag() == MM_FORMULA);
+
+    SCCOL nCols;
+    SCROW nRows;
+    pFC->GetMatColsRows(nCols, nRows);
+    CPPUNIT_ASSERT_EQUAL(static_cast<SCCOL>(1), nCols);
+    CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(2), nRows);
+
+    CPPUNIT_ASSERT_MESSAGE("Formula in C1 is invalid.", m_pDoc->GetErrCode(ScAddress(2,0,0)) == 0);
+    CPPUNIT_ASSERT_MESSAGE("Formula in C2 is invalid.", m_pDoc->GetErrCode(ScAddress(2,1,0)) == 0);
+
+    CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(ScAddress(2,0,0)));
+    CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(ScAddress(2,1,0)));
+
+    m_pDoc->DeleteTab(0);
+}
+
 void Test::testFuncN()
 {
     OUString aTabName("foo");


More information about the Libreoffice-commits mailing list