[Libreoffice-commits] core.git: Branch 'libreoffice-4-4' - 10 commits - sc/source

Tor Lillqvist tml at collabora.com
Mon Nov 24 10:23:36 PST 2014


 sc/source/ui/inc/docfunc.hxx           |    2 
 sc/source/ui/optdlg/calcoptionsdlg.cxx |  529 ++++++++++++++++++++++++---------
 2 files changed, 398 insertions(+), 133 deletions(-)

New commits:
commit 884da2ffaceb467a0949c175ed9c56dce58056a0
Author: Tor Lillqvist <tml at collabora.com>
Date:   Mon Nov 24 13:14:54 2014 +0200

    Reduce the amount of data by an order of magnitude
    
    Change-Id: I4a1deb2c1a0cfe67faef6a0d2e3d355b475eb9f0

diff --git a/sc/source/ui/optdlg/calcoptionsdlg.cxx b/sc/source/ui/optdlg/calcoptionsdlg.cxx
index c800726..0b0d160 100644
--- a/sc/source/ui/optdlg/calcoptionsdlg.cxx
+++ b/sc/source/ui/optdlg/calcoptionsdlg.cxx
@@ -1038,7 +1038,7 @@ struct Op : Area
        const OUString& rOp,
        double nRangeLo, double nRangeHi,
        double nEpsilon) :
-        Area(rTitle, 1000),
+        Area(rTitle, 200),
         msOp(rOp),
         mnRangeLo(nRangeLo),
         mnRangeHi(nRangeHi),
@@ -1355,31 +1355,31 @@ IMPL_LINK( ScCalcOptionsDialog, TestClickHdl, PushButton*, )
                                     return (nArg == 0);
                                 }));
 
-    pTestDocument->addTest(Reduction("Sum", "SUM", 500, 0, -1000, 1000, 3e-10,
+    pTestDocument->addTest(Reduction("Sum", "SUM", 100, 0, -1000, 1000, 3e-10,
                                      [] (double nAccum, double nArg)
                                      {
                                          return (nAccum + nArg);
                                      }));
 
-    pTestDocument->addTest(Reduction("Average", "AVERAGE", 500, 0, -1000, 1000, 3e-10,
+    pTestDocument->addTest(Reduction("Average", "AVERAGE", 100, 0, -1000, 1000, 3e-10,
                                      [] (double nAccum, double nArg)
                                      {
-                                         return (nAccum + nArg / static_cast<double>(500));
+                                         return (nAccum + nArg/100.);
                                      }));
 
-    pTestDocument->addTest(Reduction("Product", "PRODUCT", 500, 1, 0.1, 2.5, 3e-10,
+    pTestDocument->addTest(Reduction("Product", "PRODUCT", 100, 1, 0.1, 2.5, 3e-10,
                                      [] (double nAccum, double nArg)
                                      {
                                          return (nAccum * nArg);
                                      }));
 
-    pTestDocument->addTest(Reduction("Min", "MIN", 500, DBL_MAX, -1000, 1000, 0,
+    pTestDocument->addTest(Reduction("Min", "MIN", 100, DBL_MAX, -1000, 1000, 0,
                                      [] (double nAccum, double nArg)
                                      {
                                          return std::min(nAccum, nArg);
                                      }));
 
-    pTestDocument->addTest(Reduction("Max", "MAX", 500, -DBL_MAX, -1000, 1000, 0,
+    pTestDocument->addTest(Reduction("Max", "MAX", 100, -DBL_MAX, -1000, 1000, 0,
                                      [] (double nAccum, double nArg)
                                      {
                                          return std::max(nAccum, nArg);
commit 840f45193b798d75c7b72204178504b331c11f83
Author: Tor Lillqvist <tml at collabora.com>
Date:   Mon Nov 24 13:08:01 2014 +0200

    Add AVERAGE test
    
    Change-Id: I144858631f229685284622eb9975a168e61ff6c5

diff --git a/sc/source/ui/optdlg/calcoptionsdlg.cxx b/sc/source/ui/optdlg/calcoptionsdlg.cxx
index ebaf2ed..c800726 100644
--- a/sc/source/ui/optdlg/calcoptionsdlg.cxx
+++ b/sc/source/ui/optdlg/calcoptionsdlg.cxx
@@ -1361,6 +1361,12 @@ IMPL_LINK( ScCalcOptionsDialog, TestClickHdl, PushButton*, )
                                          return (nAccum + nArg);
                                      }));
 
+    pTestDocument->addTest(Reduction("Average", "AVERAGE", 500, 0, -1000, 1000, 3e-10,
+                                     [] (double nAccum, double nArg)
+                                     {
+                                         return (nAccum + nArg / static_cast<double>(500));
+                                     }));
+
     pTestDocument->addTest(Reduction("Product", "PRODUCT", 500, 1, 0.1, 2.5, 3e-10,
                                      [] (double nAccum, double nArg)
                                      {
commit 78ab2b4fb997add2ffdf4a5310008d51aef51da0
Author: Tor Lillqvist <tml at collabora.com>
Date:   Mon Nov 24 13:03:52 2014 +0200

    Add MIN and MAX tests
    
    Change-Id: Ia8d5fdeb1e03009035136edeab991442b7d91c4b

diff --git a/sc/source/ui/optdlg/calcoptionsdlg.cxx b/sc/source/ui/optdlg/calcoptionsdlg.cxx
index 1d7c6f1..ebaf2ed 100644
--- a/sc/source/ui/optdlg/calcoptionsdlg.cxx
+++ b/sc/source/ui/optdlg/calcoptionsdlg.cxx
@@ -1367,6 +1367,18 @@ IMPL_LINK( ScCalcOptionsDialog, TestClickHdl, PushButton*, )
                                          return (nAccum * nArg);
                                      }));
 
+    pTestDocument->addTest(Reduction("Min", "MIN", 500, DBL_MAX, -1000, 1000, 0,
+                                     [] (double nAccum, double nArg)
+                                     {
+                                         return std::min(nAccum, nArg);
+                                     }));
+
+    pTestDocument->addTest(Reduction("Max", "MAX", 500, -DBL_MAX, -1000, 1000, 0,
+                                     [] (double nAccum, double nArg)
+                                     {
+                                         return std::max(nAccum, nArg);
+                                     }));
+
     return 0;
 }
 
commit 7fca30bfe7c13017551d1c17ff719ed8c727b683
Author: Tor Lillqvist <tml at collabora.com>
Date:   Mon Nov 24 12:59:30 2014 +0200

    Fix fencepost errors
    
    Change-Id: I4d22d535368569631be9c016f74b7c19b9019955

diff --git a/sc/source/ui/optdlg/calcoptionsdlg.cxx b/sc/source/ui/optdlg/calcoptionsdlg.cxx
index 3a0af0e..1d7c6f1 100644
--- a/sc/source/ui/optdlg/calcoptionsdlg.cxx
+++ b/sc/source/ui/optdlg/calcoptionsdlg.cxx
@@ -1217,7 +1217,7 @@ struct Reduction : Op
     virtual void addHeader(ScDocument *pDoc, int nTab) const SAL_OVERRIDE
     {
         pDoc->SetString(ScAddress(0,0,nTab), "x");
-        pDoc->SetString(ScAddress(1,0,nTab), msOp + "(" + OUString::number(mnNum) + ")");
+        pDoc->SetString(ScAddress(1,0,nTab), msOp);
         pDoc->SetString(ScAddress(2,0,nTab), "expected");
     }
 
@@ -1231,33 +1231,39 @@ struct Reduction : Op
 
         pDoc->SetValue(ScAddress(0,1+nRow,nTab), nArg);
 
-        if (nRow >= mnNum)
+        if (nRow >= mnNum-1)
         {
-            pDoc->SetString(ScAddress(1,1+nRow,nTab),
+            pDoc->SetString(ScAddress(1,1+nRow-mnNum+1,nTab),
                             OUString("=") + msOp + "(" +
-                            ScRange(ScAddress(0,1+nRow-mnNum,nTab),
+                            ScRange(ScAddress(0,1+nRow-mnNum+1,nTab),
                                     ScAddress(0,1+nRow,nTab)).Format(SCA_VALID|SCA_TAB_3D|SCA_VALID_COL|SCA_VALID_ROW) +
                             ")");
 
             double nAccum(mnAccumInitial);
             for (int i = 0; i < mnNum; i++)
-                nAccum = mpFun(nAccum, pDoc->GetValue(ScAddress(0,1+nRow-mnNum+i,nTab)));
+                nAccum = mpFun(nAccum, pDoc->GetValue(ScAddress(0,1+nRow-mnNum+i+1,nTab)));
 
-            pDoc->SetValue(ScAddress(2,1+nRow,nTab), nAccum);
+            pDoc->SetValue(ScAddress(2,1+nRow-mnNum+1,nTab), nAccum);
 
-            pDoc->SetString(ScAddress(3,1+nRow,nTab),
-                            OUString("=IF(ABS(") + ScAddress(1,1+nRow,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) +
-                            "-" + ScAddress(2,1+nRow,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) +
-                            ")<=" + OUString::number(mnEpsilon) +
-                            ",0,1)");
+            if (mnEpsilon != 0)
+                pDoc->SetString(ScAddress(3,1+nRow-mnNum+1,nTab),
+                                OUString("=IF(ABS(") + ScAddress(1,1+nRow-mnNum+1,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) +
+                                "-" + ScAddress(2,1+nRow-mnNum+1,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) +
+                                ")<=" + OUString::number(mnEpsilon) +
+                                ",0,1)");
+            else
+                pDoc->SetString(ScAddress(3,1+nRow-mnNum+1,nTab),
+                                OUString("=IF(") + ScAddress(1,1+nRow-mnNum+1,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) +
+                                "=" + ScAddress(2,1+nRow-mnNum+1,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) +
+                                ",0,1)");
         }
     }
 
     virtual OUString getSummaryFormula(ScDocument *pDoc, int nTab) const SAL_OVERRIDE
     {
         return OUString("=SUM(") +
-            ScRange(ScAddress(3,1+mnNum,nTab),
-                    ScAddress(3,1+mnRows-1,nTab)).Format(SCA_VALID|SCA_TAB_3D|SCA_VALID_COL|SCA_VALID_ROW|SCA_VALID_TAB, pDoc) +
+            ScRange(ScAddress(3,1+0,nTab),
+                    ScAddress(3,1+mnRows-mnNum-1,nTab)).Format(SCA_VALID|SCA_TAB_3D|SCA_VALID_COL|SCA_VALID_ROW|SCA_VALID_TAB, pDoc) +
             ")";
     }
 };
commit 47ec10446d4f35d0594541c479c84cd28f88768b
Author: Tor Lillqvist <tml at collabora.com>
Date:   Mon Nov 24 12:21:52 2014 +0200

    The initial value for PRODUCT should obviously be one, not zero
    
    Change-Id: Id054d66e716fb5b176b687afc5d4121f3fa13765

diff --git a/sc/source/ui/optdlg/calcoptionsdlg.cxx b/sc/source/ui/optdlg/calcoptionsdlg.cxx
index ab52adb..3a0af0e 100644
--- a/sc/source/ui/optdlg/calcoptionsdlg.cxx
+++ b/sc/source/ui/optdlg/calcoptionsdlg.cxx
@@ -1355,7 +1355,7 @@ IMPL_LINK( ScCalcOptionsDialog, TestClickHdl, PushButton*, )
                                          return (nAccum + nArg);
                                      }));
 
-    pTestDocument->addTest(Reduction("Product", "PRODUCT", 500, 0, 0.1, 2.5, 3e-10,
+    pTestDocument->addTest(Reduction("Product", "PRODUCT", 500, 1, 0.1, 2.5, 3e-10,
                                      [] (double nAccum, double nArg)
                                      {
                                          return (nAccum * nArg);
commit 35ddf065d98acc438efeb681761b5efd947f04fa
Author: Tor Lillqvist <tml at collabora.com>
Date:   Mon Nov 24 11:16:07 2014 +0200

    cid#1255906: Unchecked return value
    
    Change-Id: I94696b3da73eb74a04b531ee8a93854208cddbec

diff --git a/sc/source/ui/optdlg/calcoptionsdlg.cxx b/sc/source/ui/optdlg/calcoptionsdlg.cxx
index 17b1ff8..ab52adb 100644
--- a/sc/source/ui/optdlg/calcoptionsdlg.cxx
+++ b/sc/source/ui/optdlg/calcoptionsdlg.cxx
@@ -1009,7 +1009,7 @@ struct OpenCLTester
         sc::AutoCalcSwitch aACSwitch(*mpDoc, true);
 
         mnTestAreas++;
-        mpDocShell->GetDocFunc().InsertTable(mnTestAreas, rArea.msTitle, false, true);
+        (void) mpDocShell->GetDocFunc().InsertTable(mnTestAreas, rArea.msTitle, false, true);
 
         rArea.addHeader(mpDoc, mnTestAreas);
 
commit e33d0bde5534b686055b33f8d6543dde265f60f3
Author: Tor Lillqvist <tml at collabora.com>
Date:   Fri Nov 21 17:36:10 2014 +0200

    Add new-style test generation for SUM and PRODUCT
    
    Intermediate commit, still a bit buggy.
    
    Also, bin the old code that was ifdeffed out.
    
    Change-Id: I747c1864e4858672f0fe0512215405885e52c3b5

diff --git a/sc/source/ui/optdlg/calcoptionsdlg.cxx b/sc/source/ui/optdlg/calcoptionsdlg.cxx
index 92653ab..17b1ff8 100644
--- a/sc/source/ui/optdlg/calcoptionsdlg.cxx
+++ b/sc/source/ui/optdlg/calcoptionsdlg.cxx
@@ -1092,7 +1092,7 @@ struct UnOp : Op
         pDoc->SetString(ScAddress(1,1+nRow,nTab),
                         OUString("=") + msOp + "(" + ScAddress(0,1+nRow,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) + ")");
 
-        pDoc->SetValue(ScAddress(2,1+nRow,nTab), (mpFun)(nArg));
+        pDoc->SetValue(ScAddress(2,1+nRow,nTab), mpFun(nArg));
 
         if (mnEpsilon < 0)
         {
@@ -1169,7 +1169,7 @@ struct BinOp : Op
                         OUString("=") + ScAddress(0,1+nRow,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) +
                         msOp + ScAddress(1,1+nRow,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW));
 
-        pDoc->SetValue(ScAddress(3,1+nRow,nTab), (mpFun)(nLhs, nRhs));
+        pDoc->SetValue(ScAddress(3,1+nRow,nTab), mpFun(nLhs, nRhs));
 
         pDoc->SetString(ScAddress(4,1+nRow,nTab),
                         OUString("=IF(ABS(") + ScAddress(2,1+nRow,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) +
@@ -1187,6 +1187,81 @@ struct BinOp : Op
     }
 };
 
+struct Reduction : Op
+{
+    int mnNum;
+    double mnAccumInitial;
+    double (*mpFun)(double nAccum, double nArg);
+    bool (*mpFilterOut)(double nArg);
+
+    Reduction(const OUString& rTitle,
+              const OUString& rOp,
+              int nNum,
+              double nAccumInitial,
+              double nRangeLo, double nRangeHi,
+              double nEpsilon,
+              double (*pFun)(double nAccum, double nArg),
+              bool (*pFilterOut)(double nArg) = nullptr) :
+        Op(rTitle, rOp, nRangeLo, nRangeHi, nEpsilon),
+        mnNum(nNum),
+        mnAccumInitial(nAccumInitial),
+        mpFun(pFun),
+        mpFilterOut(pFilterOut)
+    {
+    }
+
+    virtual ~Reduction()
+    {
+    }
+
+    virtual void addHeader(ScDocument *pDoc, int nTab) const SAL_OVERRIDE
+    {
+        pDoc->SetString(ScAddress(0,0,nTab), "x");
+        pDoc->SetString(ScAddress(1,0,nTab), msOp + "(" + OUString::number(mnNum) + ")");
+        pDoc->SetString(ScAddress(2,0,nTab), "expected");
+    }
+
+    virtual void addRow(ScDocument *pDoc, int nRow, int nTab) const SAL_OVERRIDE
+    {
+        double nArg;
+
+        do {
+            nArg = comphelper::rng::uniform_real_distribution(mnRangeLo, mnRangeHi);
+        } while (mpFilterOut != nullptr && mpFilterOut(nArg));
+
+        pDoc->SetValue(ScAddress(0,1+nRow,nTab), nArg);
+
+        if (nRow >= mnNum)
+        {
+            pDoc->SetString(ScAddress(1,1+nRow,nTab),
+                            OUString("=") + msOp + "(" +
+                            ScRange(ScAddress(0,1+nRow-mnNum,nTab),
+                                    ScAddress(0,1+nRow,nTab)).Format(SCA_VALID|SCA_TAB_3D|SCA_VALID_COL|SCA_VALID_ROW) +
+                            ")");
+
+            double nAccum(mnAccumInitial);
+            for (int i = 0; i < mnNum; i++)
+                nAccum = mpFun(nAccum, pDoc->GetValue(ScAddress(0,1+nRow-mnNum+i,nTab)));
+
+            pDoc->SetValue(ScAddress(2,1+nRow,nTab), nAccum);
+
+            pDoc->SetString(ScAddress(3,1+nRow,nTab),
+                            OUString("=IF(ABS(") + ScAddress(1,1+nRow,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) +
+                            "-" + ScAddress(2,1+nRow,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) +
+                            ")<=" + OUString::number(mnEpsilon) +
+                            ",0,1)");
+        }
+    }
+
+    virtual OUString getSummaryFormula(ScDocument *pDoc, int nTab) const SAL_OVERRIDE
+    {
+        return OUString("=SUM(") +
+            ScRange(ScAddress(3,1+mnNum,nTab),
+                    ScAddress(3,1+mnRows-1,nTab)).Format(SCA_VALID|SCA_TAB_3D|SCA_VALID_COL|SCA_VALID_ROW|SCA_VALID_TAB, pDoc) +
+            ")";
+    }
+};
+
 }
 
 IMPL_LINK( ScCalcOptionsDialog, TestClickHdl, PushButton*, )
@@ -1201,6 +1276,7 @@ IMPL_LINK( ScCalcOptionsDialog, TestClickHdl, PushButton*, )
                                  {
                                      return nLhs + nRhs;
                                  }));
+
     pTestDocument->addTest(BinOp("Minus", "-", -1000, 1000, 3e-10,
                                  [] (double nLhs, double nRhs)
                                  {
@@ -1212,6 +1288,7 @@ IMPL_LINK( ScCalcOptionsDialog, TestClickHdl, PushButton*, )
                                  {
                                      return nLhs * nRhs;
                                  }));
+
     pTestDocument->addTest(BinOp("Divided", "/", -1000, 1000, 3e-10,
                                  [] (double nLhs, double nRhs)
                                  {
@@ -1272,155 +1349,17 @@ IMPL_LINK( ScCalcOptionsDialog, TestClickHdl, PushButton*, )
                                     return (nArg == 0);
                                 }));
 
-#if 0
-
-    const double nEpsilon = 0.0000000003;
-    OUString sEpsilon(OUString::number(nEpsilon));
-
-    const int N = 1000;
-    OUString sN(OUString::number(N));
-
-    css::uno::Reference< css::uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
-    css::uno::Reference< css::frame::XDesktop2 > xComponentLoader = css::frame::Desktop::create(xContext);
-    css::uno::Reference< css::lang::XComponent > xComponent( xComponentLoader->loadComponentFromURL( "private:factory/scalc",
-                                                                                                     "_blank", 0,
-                                                                                                     css::uno::Sequence < css::beans::PropertyValue >() ) );
-    ScDocShell* pDocShell( dynamic_cast<ScDocShell*>(SfxObjectShell::GetShellFromComponent(xComponent)) );
-
-    auto pDoc = &pDocShell->GetDocument();
-
-    sc::AutoCalcSwitch aACSwitch(*pDoc, true);
-
-    pDoc->SetString(ScAddress(0,0,0), "=IF(SUM(A2:A5)=0,\"PASS\",\"FAIL\")");
-
-    // RAND sheet
-    pDoc->InsertTab(1, "RAND");
-
-    for (int i = 0; i < N; ++i)
-    {
-#if 0 // While our RAND OpenCL implementation is broken...
-        pDoc->SetString(ScAddress(0,i,1), "=RAND()");
-#else
-        pDoc->SetValue(ScAddress(0,i,1), (i%13)/13.);
-#endif
-        double nLarge = comphelper::rng::uniform_real_distribution(0, 1000);
-        pDoc->SetValue(ScAddress(1,i,1), nLarge);
-        // The [0.1,2.5) interval is carefully chosen to keep the product of them likely "sane"
-        double nSmall = comphelper::rng::uniform_real_distribution(0.1, 2.5);
-        pDoc->SetValue(ScAddress(6,i,1), nSmall);
-        pDoc->SetString(ScAddress(10,i,1), OUString("=IF(AND(A") + OUString::number(i+1) + ">= 0,A" + OUString::number(i+1) + "<= 1),0,1)");
-
-        pDoc->SetString(ScAddress(20,i,1), OUString("=B") + OUString::number(i+1) + "+G" + OUString::number(i+1));
-        pDoc->SetString(ScAddress(21,i,1), OUString("=B") + OUString::number(i+1) + "-G" + OUString::number(i+1));
-        pDoc->SetString(ScAddress(22,i,1), OUString("=B") + OUString::number(i+1) + "*G" + OUString::number(i+1));
-        pDoc->SetString(ScAddress(23,i,1), OUString("=B") + OUString::number(i+1) + "/G" + OUString::number(i+1));
-
-        pDoc->SetString(ScAddress(30,i,1),
-                        OUString("=IF(ABS(U") + OUString::number(i+1) + "-" + OUString::number(nLarge+nSmall) + ")<" + sEpsilon + ",0,1)");
-        pDoc->SetString(ScAddress(31,i,1),
-                        OUString("=IF(ABS(V") + OUString::number(i+1) + "-" + OUString::number(nLarge-nSmall) + ")<" + sEpsilon +",0,1)");
-        pDoc->SetString(ScAddress(32,i,1),
-                        OUString("=IF(ABS(W") + OUString::number(i+1) + "-" + OUString::number(nLarge*nSmall) + ")<" + sEpsilon + ",0,1)");
-        pDoc->SetString(ScAddress(33,i,1),
-                        OUString("=IF(ABS(X") + OUString::number(i+1) + "-" + OUString::number(nLarge/nSmall) + ")<" + sEpsilon + ",0,1)");
-    }
-
-    pDoc->SetString(ScAddress(0,1,0), OUString("=SUM(RAND.K1:RAND.K") + sN + ")");
-    pDoc->SetString(ScAddress(0,2,0), OUString("=SUM(RAND.AE1:RAND.AH") + sN + ")");
-
-    for (int i = 0; i < N/3; ++i)
-    {
-        pDoc->SetString(ScAddress(2,i,1), OUString("=SUM(B") + OUString::number(i+1) + ":B" + OUString::number(i+N/2) + ")");
-        pDoc->SetString(ScAddress(3,i,1), OUString("=AVERAGE(B") + OUString::number(i+1) + ":B" + OUString::number(i+N/2) + ")");
-        pDoc->SetString(ScAddress(4,i,1), OUString("=MIN(B") + OUString::number(i+1) + ":B" + OUString::number(i+N/2) + ")");
-        pDoc->SetString(ScAddress(5,i,1), OUString("=MAX(B") + OUString::number(i+1) + ":B" + OUString::number(i+N/2) + ")");
-        pDoc->SetString(ScAddress(7,i,1), OUString("=PRODUCT(G") + OUString::number(i+1) + ":G" + OUString::number(i+N/2) + ")");
-
-        double nSum(0), nMin(DBL_MAX), nMax(-DBL_MAX), nProduct(1);
-        for (int j = 0; j < N/2; ++j)
-        {
-            nSum += pDoc->GetValue(ScAddress(1,i+j,1));
-            nMin = std::min(nMin, pDoc->GetValue(ScAddress(1,i+j,1)));
-            nMax = std::max(nMax, pDoc->GetValue(ScAddress(1,i+j,1)));
-            nProduct *= pDoc->GetValue(ScAddress(6,i+j,1));
-        }
-
-        pDoc->SetString(ScAddress(12,i,1),
-                        OUString("=IF(C") + OUString::number(i+1) + "-" + OUString::number(nSum) + "<" + sEpsilon + ",0,1");
-        pDoc->SetString(ScAddress(13,i,1),
-                        OUString("=IF(D") + OUString::number(i+1) + "-" + OUString::number(nSum/(N/2)) + "<" + sEpsilon + ",0,1");
-        pDoc->SetString(ScAddress(14,i,1),
-                        OUString("=IF(E") + OUString::number(i+1) + "-" + OUString::number(nMin) + "<" + sEpsilon + ",0,1");
-        pDoc->SetString(ScAddress(15,i,1),
-                        OUString("=IF(F") + OUString::number(i+1) + "-" + OUString::number(nMax) + "<" + sEpsilon + ",0,1");
-        pDoc->SetString(ScAddress(16,i,1),
-                        OUString("=IF((H") + OUString::number(i+1) + "-" + OUString::number(nProduct) + ")/H" + OUString::number(i+1) + "<" + sEpsilon + ",0,1");
-    }
-
-    pDoc->SetString(ScAddress(0,3,0), OUString("=SUM(RAND.M1:RAND.Q") + OUString::number(N/3) + ")");
-
-    // MISCMATH sheet
-    pDoc->InsertTab(2, "MISCMATH");
-
-    for (int i = 0; i < 1000; ++i)
-    {
-        OUString is(OUString::number(i+1));
-        double d;
-        if (i <= 16)
-            d = M_PI*(i/4.0);
-        else
-            d = comphelper::rng::uniform_real_distribution(0, 10);
-        pDoc->SetValue(ScAddress(0,i,2), d);
-        pDoc->SetValue(ScAddress(1,i,2), sin(d));
-        pDoc->SetValue(ScAddress(2,i,2), cos(d));
-        pDoc->SetValue(ScAddress(3,i,2), tan(d));
-        pDoc->SetValue(ScAddress(4,i,2), sqrt(d));
-        pDoc->SetValue(ScAddress(5,i,2), exp(d));
-        pDoc->SetValue(ScAddress(6,i,2), log(d));
-        pDoc->SetValue(ScAddress(7,i,2), atan(tan(d)));
-
-        pDoc->SetString(ScAddress(11,i,2), OUString("=SIN(A") + is + ")");
-        pDoc->SetString(ScAddress(12,i,2), OUString("=COS(A") + is + ")");
-        pDoc->SetString(ScAddress(13,i,2), OUString("=TAN(A") + is + ")");
-        pDoc->SetString(ScAddress(14,i,2), OUString("=SQRT(A") + is + ")");
-        pDoc->SetString(ScAddress(15,i,2), OUString("=EXP(A") + is + ")");
-        pDoc->SetString(ScAddress(16,i,2), OUString("=LN(A") + is + ")");
-        pDoc->SetString(ScAddress(17,i,2), OUString("=ATAN(D") + is + ")");
-
-        pDoc->SetString(ScAddress(21,i,2),
-                        OUString("=IF(ABS(B") + is + "-L" + is + ")<" + sEpsilon + ",0,1)");
-        pDoc->SetString(ScAddress(22,i,2),
-                        OUString("=IF(ABS(C") + is + "-M" + is + ")<" + sEpsilon + ",0,1)");
-
-        // Handle TAN undefinedness. Use a relative epsilon for larger TAN values
-        if (i <= 16 && i % 4 == 2)
-            pDoc->SetValue(ScAddress(23,i,2), 0);
-        else if (std::abs(tan(d)) < 10)
-            pDoc->SetString(ScAddress(23,i,2),
-                            OUString("=IF(ABS(D") + is + "-N" + is + ")<" + sEpsilon + ",0,1)");
-        else
-            pDoc->SetString(ScAddress(23,i,2),
-                            OUString("=IF(ABS((D") + is + "-N" + is + ")/D" + is + ")<" + sEpsilon + ",0,1)");
-
-        pDoc->SetString(ScAddress(24,i,2),
-                        OUString("=IF(ABS(E") + is + "-O" + is + ")<" + sEpsilon + ",0,1)");
-        pDoc->SetString(ScAddress(25,i,2),
-                        OUString("=IF(ABS(F") + is + "-P" + is + ")<" + sEpsilon + ",0,1)");
-
-        // Handle LN undefinedness
-        if (i == 0)
-            pDoc->SetValue(ScAddress(26,i,2), 0);
-        else
-            pDoc->SetString(ScAddress(26,i,2),
-                            OUString("=IF(ABS(G") + is + "-Q" + is + ")<" + sEpsilon + ",0,1)");
-
-        pDoc->SetString(ScAddress(27,i,2),
-                        OUString("=IF(ABS(H") + is + "-r" + is + ")<" + sEpsilon + ",0,1)");
-    }
-
-    pDoc->SetString(ScAddress(0,4,0), "=SUM(MISCMATH.V1:MISCMATH.AB1000)");
-
-#endif
+    pTestDocument->addTest(Reduction("Sum", "SUM", 500, 0, -1000, 1000, 3e-10,
+                                     [] (double nAccum, double nArg)
+                                     {
+                                         return (nAccum + nArg);
+                                     }));
+
+    pTestDocument->addTest(Reduction("Product", "PRODUCT", 500, 0, 0.1, 2.5, 3e-10,
+                                     [] (double nAccum, double nArg)
+                                     {
+                                         return (nAccum * nArg);
+                                     }));
 
     return 0;
 }
commit 5bf0091a6363f6502e6101aedb599c9110db39c0
Author: Tor Lillqvist <tml at collabora.com>
Date:   Fri Nov 21 02:29:06 2014 +0200

    Some of our supported compilers still don't have 'override' it seems
    
    Change-Id: Ie3ca1636657b90fd5bc193aa7595f95f44d43915

diff --git a/sc/source/ui/optdlg/calcoptionsdlg.cxx b/sc/source/ui/optdlg/calcoptionsdlg.cxx
index 89f596e..92653ab 100644
--- a/sc/source/ui/optdlg/calcoptionsdlg.cxx
+++ b/sc/source/ui/optdlg/calcoptionsdlg.cxx
@@ -1072,14 +1072,14 @@ struct UnOp : Op
     {
     }
 
-    virtual void addHeader(ScDocument *pDoc, int nTab) const override
+    virtual void addHeader(ScDocument *pDoc, int nTab) const SAL_OVERRIDE
     {
         pDoc->SetString(ScAddress(0,0,nTab), "arg");
         pDoc->SetString(ScAddress(1,0,nTab), msOp + "(arg)");
         pDoc->SetString(ScAddress(2,0,nTab), "expected");
     }
 
-    virtual void addRow(ScDocument *pDoc, int nRow, int nTab) const override
+    virtual void addRow(ScDocument *pDoc, int nRow, int nTab) const SAL_OVERRIDE
     {
         double nArg;
 
@@ -1115,7 +1115,7 @@ struct UnOp : Op
         }
     }
 
-    virtual OUString getSummaryFormula(ScDocument *pDoc, int nTab) const override
+    virtual OUString getSummaryFormula(ScDocument *pDoc, int nTab) const SAL_OVERRIDE
     {
         return OUString("=SUM(") +
             ScRange(ScAddress(3,1,nTab),
@@ -1145,7 +1145,7 @@ struct BinOp : Op
     {
     }
 
-    virtual void addHeader(ScDocument *pDoc, int nTab) const override
+    virtual void addHeader(ScDocument *pDoc, int nTab) const SAL_OVERRIDE
     {
         pDoc->SetString(ScAddress(0,0,nTab), "lhs");
         pDoc->SetString(ScAddress(1,0,nTab), "rhs");
@@ -1153,7 +1153,7 @@ struct BinOp : Op
         pDoc->SetString(ScAddress(3,0,nTab), "expected");
     }
 
-    virtual void addRow(ScDocument *pDoc, int nRow, int nTab) const override
+    virtual void addRow(ScDocument *pDoc, int nRow, int nTab) const SAL_OVERRIDE
     {
         double nLhs, nRhs;
 
@@ -1178,7 +1178,7 @@ struct BinOp : Op
                         ",0,1)");
     }
 
-    virtual OUString getSummaryFormula(ScDocument *pDoc, int nTab) const override
+    virtual OUString getSummaryFormula(ScDocument *pDoc, int nTab) const SAL_OVERRIDE
     {
         return OUString("=SUM(") +
             ScRange(ScAddress(4,1,nTab),
commit 30b07074f27f3e9816e4b049f46e6a6186be8ce6
Author: Tor Lillqvist <tml at collabora.com>
Date:   Fri Nov 21 01:52:57 2014 +0200

    Re-factor the OpenCL quality test spreadsheet generating code
    
    Be more elegant, avoid hardcoding stuff, use more C++ features.
    
    (Not complete yet. Only did the math and trig functions and arithmetic ops so
    far. New style test generation for AVERAGE, SUM etc not yet done. Old code
    still left in #if 0 for reference.)
    
    Change-Id: I50068852eacf7f0212b2a7ea077021713c8e9978

diff --git a/sc/source/ui/optdlg/calcoptionsdlg.cxx b/sc/source/ui/optdlg/calcoptionsdlg.cxx
index acf9318..89f596e 100644
--- a/sc/source/ui/optdlg/calcoptionsdlg.cxx
+++ b/sc/source/ui/optdlg/calcoptionsdlg.cxx
@@ -14,10 +14,12 @@
 
 #include "calcconfig.hxx"
 #include "calcoptionsdlg.hxx"
+#include "docfunc.hxx"
 #include "docsh.hxx"
 #include "sc.hrc"
 #include "scresid.hxx"
 #include "scopetools.hxx"
+#include "viewdata.hxx"
 
 #include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/frame/XDesktop2.hpp>
@@ -954,26 +956,324 @@ IMPL_LINK( ScCalcOptionsDialog, ListDeleteClickHdl, PushButton*, )
     return 0;
 }
 
-#if 0 // Can't decide whether to use this or just hardcode column
-      // names when constructing the formulae below...
-
 namespace {
 
-OUString col(int nCol)
+struct Area
 {
-    ScAddress aAddr(nCol, 0, 0);
-    return aAddr.Format(SCA_VALID_COL);
-}
+    OUString msTitle;
+    int mnRows;
 
-}
+    Area(const OUString& rTitle, int nRows) :
+        msTitle(rTitle),
+        mnRows(nRows)
+    {
+    }
 
-#endif
+    virtual ~Area()
+    {
+    }
+
+    virtual void addHeader(ScDocument *pDoc, int nTab) const = 0;
+
+    virtual void addRow(ScDocument *pDoc, int nRow, int nTab) const = 0;
+
+    virtual OUString getSummaryFormula(ScDocument *pDoc, int nTab) const = 0;
+};
+
+struct OpenCLTester
+{
+    int mnTestAreas;
+    ScDocShell* mpDocShell;
+    ScDocument *mpDoc;
+
+    OpenCLTester() :
+        mnTestAreas(0)
+    {
+        css::uno::Reference< css::uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
+        css::uno::Reference< css::frame::XDesktop2 > xComponentLoader = css::frame::Desktop::create(xContext);
+        css::uno::Reference< css::lang::XComponent >
+            xComponent( xComponentLoader->loadComponentFromURL( "private:factory/scalc",
+                                                                "_blank", 0,
+                                                                css::uno::Sequence < css::beans::PropertyValue >() ) );
+        mpDocShell = dynamic_cast<ScDocShell*>(SfxObjectShell::GetShellFromComponent(xComponent));
+
+        assert(mpDocShell);
+
+        mpDoc = &mpDocShell->GetDocument();
+
+        mpDoc->SetString(ScAddress(0,0,0), "Result:");
+    }
+
+    void addTest(const Area &rArea)
+    {
+        sc::AutoCalcSwitch aACSwitch(*mpDoc, true);
+
+        mnTestAreas++;
+        mpDocShell->GetDocFunc().InsertTable(mnTestAreas, rArea.msTitle, false, true);
+
+        rArea.addHeader(mpDoc, mnTestAreas);
+
+        for (int i = 0; i < rArea.mnRows; ++i)
+            rArea.addRow(mpDoc, i, mnTestAreas);
+
+        mpDoc->SetString(ScAddress(0,1+mnTestAreas-1,0), rArea.msTitle + ":");
+        mpDoc->SetString(ScAddress(1,1+mnTestAreas-1,0), rArea.getSummaryFormula(mpDoc, mnTestAreas));
+
+        mpDoc->SetString(ScAddress(1,0,0),
+                        OUString("=IF(SUM(") +
+                        ScRange(ScAddress(1,1,0),
+                                ScAddress(1,1+mnTestAreas-1,0)).Format(SCA_VALID|SCA_VALID_COL|SCA_VALID_ROW) +
+                        ")=0,\"PASS\",\"FAIL\")");
+    }
+};
+
+struct Op : Area
+{
+    OUString msOp;
+    double mnRangeLo;
+    double mnRangeHi;
+    double mnEpsilon;
+
+    Op(const OUString& rTitle,
+       const OUString& rOp,
+       double nRangeLo, double nRangeHi,
+       double nEpsilon) :
+        Area(rTitle, 1000),
+        msOp(rOp),
+        mnRangeLo(nRangeLo),
+        mnRangeHi(nRangeHi),
+        mnEpsilon(nEpsilon)
+    {
+    }
+
+    virtual ~Op()
+    {
+    }
+};
+
+struct UnOp : Op
+{
+    double (*mpFun)(double nArg);
+    bool (*mpFilterOut)(double nArg);
+
+    UnOp(const OUString& rTitle,
+         const OUString& rOp,
+         double nRangeLo, double nRangeHi,
+         double nEpsilon,
+         double (*pFun)(double nArg),
+         bool (*pFilterOut)(double nArg) = nullptr) :
+        Op(rTitle, rOp, nRangeLo, nRangeHi, nEpsilon),
+        mpFun(pFun),
+        mpFilterOut(pFilterOut)
+    {
+    }
+
+    virtual ~UnOp()
+    {
+    }
+
+    virtual void addHeader(ScDocument *pDoc, int nTab) const override
+    {
+        pDoc->SetString(ScAddress(0,0,nTab), "arg");
+        pDoc->SetString(ScAddress(1,0,nTab), msOp + "(arg)");
+        pDoc->SetString(ScAddress(2,0,nTab), "expected");
+    }
+
+    virtual void addRow(ScDocument *pDoc, int nRow, int nTab) const override
+    {
+        double nArg;
+
+        do {
+            nArg = comphelper::rng::uniform_real_distribution(mnRangeLo, mnRangeHi);
+        } while (mpFilterOut != nullptr && mpFilterOut(nArg));
+
+        pDoc->SetValue(ScAddress(0,1+nRow,nTab), nArg);
+
+        pDoc->SetString(ScAddress(1,1+nRow,nTab),
+                        OUString("=") + msOp + "(" + ScAddress(0,1+nRow,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) + ")");
+
+        pDoc->SetValue(ScAddress(2,1+nRow,nTab), (mpFun)(nArg));
+
+        if (mnEpsilon < 0)
+        {
+            // relative epsilon
+            pDoc->SetString(ScAddress(3,1+nRow,nTab),
+                            OUString("=IF(ABS((") + ScAddress(1,1+nRow,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) +
+                            "-" + ScAddress(2,1+nRow,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) +
+                            ")/" + ScAddress(2,1+nRow,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) +
+                            ")<=" + OUString::number(-mnEpsilon) +
+                            ",0,1)");
+        }
+        else
+        {
+            // absolute epsilon
+            pDoc->SetString(ScAddress(3,1+nRow,nTab),
+                            OUString("=IF(ABS(") + ScAddress(1,1+nRow,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) +
+                            "-" + ScAddress(2,1+nRow,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) +
+                            ")<=" + OUString::number(mnEpsilon) +
+                            ",0,1)");
+        }
+    }
+
+    virtual OUString getSummaryFormula(ScDocument *pDoc, int nTab) const override
+    {
+        return OUString("=SUM(") +
+            ScRange(ScAddress(3,1,nTab),
+                    ScAddress(3,1+mnRows-1,nTab)).Format(SCA_VALID|SCA_TAB_3D|SCA_VALID_COL|SCA_VALID_ROW|SCA_VALID_TAB, pDoc) +
+            ")";
+    }
+};
+
+struct BinOp : Op
+{
+    double (*mpFun)(double nLhs, double nRhs);
+    bool (*mpFilterOut)(double nLhs, double nRhs);
+
+    BinOp(const OUString& rTitle,
+          const OUString& rOp,
+          double nRangeLo, double nRangeHi,
+          double nEpsilon,
+          double (*pFun)(double nLhs, double nRhs),
+          bool (*pFilterOut)(double nLhs, double nRhs) = nullptr) :
+        Op(rTitle, rOp, nRangeLo, nRangeHi, nEpsilon),
+        mpFun(pFun),
+        mpFilterOut(pFilterOut)
+    {
+    }
+
+    virtual ~BinOp()
+    {
+    }
+
+    virtual void addHeader(ScDocument *pDoc, int nTab) const override
+    {
+        pDoc->SetString(ScAddress(0,0,nTab), "lhs");
+        pDoc->SetString(ScAddress(1,0,nTab), "rhs");
+        pDoc->SetString(ScAddress(2,0,nTab), OUString("lhs") + msOp + "rhs");
+        pDoc->SetString(ScAddress(3,0,nTab), "expected");
+    }
+
+    virtual void addRow(ScDocument *pDoc, int nRow, int nTab) const override
+    {
+        double nLhs, nRhs;
+
+        do {
+            nLhs = comphelper::rng::uniform_real_distribution(mnRangeLo, mnRangeHi);
+            nRhs = comphelper::rng::uniform_real_distribution(mnRangeLo, mnRangeHi);
+        } while (mpFilterOut != nullptr && mpFilterOut(nLhs, nRhs));
+
+        pDoc->SetValue(ScAddress(0,1+nRow,nTab), nLhs);
+        pDoc->SetValue(ScAddress(1,1+nRow,nTab), nRhs);
+
+        pDoc->SetString(ScAddress(2,1+nRow,nTab),
+                        OUString("=") + ScAddress(0,1+nRow,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) +
+                        msOp + ScAddress(1,1+nRow,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW));
+
+        pDoc->SetValue(ScAddress(3,1+nRow,nTab), (mpFun)(nLhs, nRhs));
+
+        pDoc->SetString(ScAddress(4,1+nRow,nTab),
+                        OUString("=IF(ABS(") + ScAddress(2,1+nRow,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) +
+                        "-" + ScAddress(3,1+nRow,nTab).Format(SCA_VALID_COL|SCA_VALID_ROW) +
+                        ")<=" + OUString::number(mnEpsilon) +
+                        ",0,1)");
+    }
+
+    virtual OUString getSummaryFormula(ScDocument *pDoc, int nTab) const override
+    {
+        return OUString("=SUM(") +
+            ScRange(ScAddress(4,1,nTab),
+                    ScAddress(4,1+mnRows-1,nTab)).Format(SCA_VALID|SCA_TAB_3D|SCA_VALID_COL|SCA_VALID_ROW|SCA_VALID_TAB, pDoc) +
+            ")";
+    }
+};
+
+}
 
 IMPL_LINK( ScCalcOptionsDialog, TestClickHdl, PushButton*, )
 {
     // Automatically test the current implementation of OpenCL. If it
     // seems good, whitelist it. If it seems bad, blacklist it.
 
+    auto pTestDocument = new OpenCLTester();
+
+    pTestDocument->addTest(BinOp("Plus", "+", -1000, 1000, 3e-10,
+                                 [] (double nLhs, double nRhs)
+                                 {
+                                     return nLhs + nRhs;
+                                 }));
+    pTestDocument->addTest(BinOp("Minus", "-", -1000, 1000, 3e-10,
+                                 [] (double nLhs, double nRhs)
+                                 {
+                                     return nLhs - nRhs;
+                                 }));
+
+    pTestDocument->addTest(BinOp("Times", "*", -1000, 1000, 3e-10,
+                                 [] (double nLhs, double nRhs)
+                                 {
+                                     return nLhs * nRhs;
+                                 }));
+    pTestDocument->addTest(BinOp("Divided", "/", -1000, 1000, 3e-10,
+                                 [] (double nLhs, double nRhs)
+                                 {
+                                     return nLhs / nRhs;
+                                 },
+                                 [] (double, double nRhs)
+                                 {
+                                     return (nRhs == 0);
+                                 }));
+
+    pTestDocument->addTest(UnOp("Sin", "SIN", -10, 10, 3e-10,
+                                [] (double nArg)
+                                {
+                                    return sin(nArg);
+                                }));
+
+    pTestDocument->addTest(UnOp("Cos", "COS", -10, 10, 3e-10,
+                                [] (double nArg)
+                                {
+                                    return cos(nArg);
+                                }));
+
+    pTestDocument->addTest(UnOp("Tan", "TAN", 0, 10, -3e-10,
+                                [] (double nArg)
+                                {
+                                    return tan(nArg);
+                                },
+                                [] (double nArg)
+                                {
+                                    return (std::fmod(nArg, M_PI) == M_PI/2);
+                                }));
+
+    pTestDocument->addTest(UnOp("Atan", "ATAN", -10, 10, 3e-10,
+                                [] (double nArg)
+                                {
+                                    return atan(nArg);
+                                }));
+
+    pTestDocument->addTest(UnOp("Sqrt", "SQRT", 0, 1000, 3e-10,
+                                [] (double nArg)
+                                {
+                                    return sqrt(nArg);
+                                }));
+
+    pTestDocument->addTest(UnOp("Exp", "EXP", 0, 10, 3e-10,
+                                [] (double nArg)
+                                {
+                                    return exp(nArg);
+                                }));
+
+    pTestDocument->addTest(UnOp("Ln", "LN", 0, 1000, 3e-10,
+                                [] (double nArg)
+                                {
+                                    return log(nArg);
+                                },
+                                [] (double nArg)
+                                {
+                                    return (nArg == 0);
+                                }));
+
+#if 0
+
     const double nEpsilon = 0.0000000003;
     OUString sEpsilon(OUString::number(nEpsilon));
 
@@ -1120,6 +1420,8 @@ IMPL_LINK( ScCalcOptionsDialog, TestClickHdl, PushButton*, )
 
     pDoc->SetString(ScAddress(0,4,0), "=SUM(MISCMATH.V1:MISCMATH.AB1000)");
 
+#endif
+
     return 0;
 }
 
commit 9d0247d7fa6a9d428630023901d3e6691ed3b4ad
Author: Tor Lillqvist <tml at collabora.com>
Date:   Fri Nov 21 01:52:48 2014 +0200

    Mark InsertTable SC_DLLPUBLIC, will need it in next commit
    
    Change-Id: Ia105bc5348c3745398ea0e90cb142c3282d688f5

diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx
index 6f970eb..9ed1ed0 100644
--- a/sc/source/ui/inc/docfunc.hxx
+++ b/sc/source/ui/inc/docfunc.hxx
@@ -132,7 +132,7 @@ public:
     bool            MoveBlock( const ScRange& rSource, const ScAddress& rDestPos,
                                        bool bCut, bool bRecord, bool bPaint, bool bApi );
 
-    bool            InsertTable( SCTAB nTab, const OUString& rName, bool bRecord, bool bApi );
+    SC_DLLPUBLIC bool InsertTable( SCTAB nTab, const OUString& rName, bool bRecord, bool bApi );
     bool            RenameTable( SCTAB nTab, const OUString& rName, bool bRecord, bool bApi );
     bool            DeleteTable( SCTAB nTab, bool bRecord, bool bApi );
 


More information about the Libreoffice-commits mailing list