[Libreoffice-commits] core.git: chart2/CppunitTest_chart2_trendcalculators.mk chart2/Module_chart2.mk chart2/qa

Philippe Jung phil.jung at free.fr
Mon Jun 22 02:56:12 PDT 2015


 chart2/CppunitTest_chart2_trendcalculators.mk   |  136 +++++++++++++++
 chart2/Module_chart2.mk                         |    1 
 chart2/qa/extras/chart2_trendcalculators.cxx    |  214 ++++++++++++++++++++++++
 chart2/qa/extras/data/ods/trend_calculators.ods |binary
 4 files changed, 351 insertions(+)

New commits:
commit 733f5887af46d1d5e2fbea6be93cabb2a1749752
Author: Philippe Jung <phil.jung at free.fr>
Date:   Mon Jun 22 11:41:43 2015 +0200

    Add unit tests for chart2 trend calculators
    
    Will be used to check tdf#70673 is fixed. Test will fail before the fix
    and should pass after.
    
    Change-Id: I9e0fdc696fb99ac2f0e24b04273391d526c629a6
    Reviewed-on: https://gerrit.libreoffice.org/16406
    Reviewed-by: Philippe Jung <phil.jung at free.fr>
    Tested-by: Philippe Jung <phil.jung at free.fr>

diff --git a/chart2/CppunitTest_chart2_trendcalculators.mk b/chart2/CppunitTest_chart2_trendcalculators.mk
new file mode 100644
index 0000000..5187298
--- /dev/null
+++ b/chart2/CppunitTest_chart2_trendcalculators.mk
@@ -0,0 +1,136 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,chart2_trendcalculators))
+
+$(eval $(call gb_CppunitTest_use_externals,chart2_trendcalculators, \
+	boost_headers \
+	libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,chart2_trendcalculators, \
+    chart2/qa/extras/chart2_trendcalculators \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,chart2_trendcalculators, \
+    basegfx \
+    comphelper \
+    cppu \
+    cppuhelper \
+    drawinglayer \
+    editeng \
+    for \
+    forui \
+    i18nlangtag \
+    msfilter \
+    vcl \
+    oox \
+    sal \
+    salhelper \
+    sax \
+    sb \
+    sc \
+    sw \
+    sd \
+    sfx \
+    sot \
+    svl \
+    svt \
+    svx \
+    svxcore \
+    test \
+    tl \
+    tk \
+    ucbhelper \
+    unotest \
+    utl \
+    vbahelper \
+    xo \
+    sw \
+    $(gb_UWINAPI) \
+))
+
+$(eval $(call gb_CppunitTest_set_include,chart2_trendcalculators,\
+    -I$(SRCDIR)/chart2/inc \
+    $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,chart2_trendcalculators,\
+    offapi \
+    udkapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,chart2_trendcalculators))
+$(eval $(call gb_CppunitTest_use_vcl,chart2_trendcalculators))
+
+$(eval $(call gb_CppunitTest_use_components,chart2_trendcalculators,\
+    basic/util/sb \
+    animations/source/animcore/animcore \
+    chart2/source/controller/chartcontroller \
+    chart2/source/chartcore \
+    comphelper/util/comphelp \
+    configmgr/source/configmgr \
+    dtrans/util/mcnttype \
+    embeddedobj/util/embobj \
+    eventattacher/source/evtatt \
+    filter/source/config/cache/filterconfig1 \
+    filter/source/odfflatxml/odfflatxml \
+    filter/source/storagefilterdetect/storagefd \
+    filter/source/xmlfilteradaptor/xmlfa \
+    filter/source/xmlfilterdetect/xmlfd \
+    forms/util/frm \
+    framework/util/fwk \
+    i18npool/util/i18npool \
+    linguistic/source/lng \
+    oox/util/oox \
+    package/source/xstor/xstor \
+    package/util/package2 \
+    sax/source/expatwrap/expwrap \
+    sc/util/sc \
+    sc/util/scd \
+    sc/util/scfilt \
+    sw/util/sw \
+    sw/util/swd \
+    sw/util/msword \
+    sd/util/sd \
+    sd/util/sdfilt \
+    sd/util/sdd \
+    $(call gb_Helper_optional,SCRIPTING, \
+	    sc/util/vbaobj) \
+    scaddins/source/analysis/analysis \
+    scaddins/source/datefunc/date \
+    scripting/source/basprov/basprov \
+    scripting/util/scriptframe \
+    sfx2/util/sfx \
+    sot/util/sot \
+    svl/source/fsstor/fsstorage \
+    svl/util/svl \
+    svtools/util/svt \
+    svx/util/svx \
+    svx/util/svxcore \
+    toolkit/util/tk \
+    ucb/source/core/ucb1 \
+    ucb/source/ucp/file/ucpfile1 \
+    ucb/source/ucp/tdoc/ucptdoc1 \
+    unotools/util/utl \
+    unoxml/source/rdf/unordf \
+    unoxml/source/service/unoxml \
+    writerfilter/util/writerfilter \
+    xmloff/util/xo \
+    xmlscript/util/xmlscript \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,chart2_trendcalculators))
+
+$(call gb_CppunitTest_get_target,chart2_trendcalculators): \
+    $(call gb_AllLangResTarget_get_target,sd)
+
+# vim: set noet sw=4 ts=4:
diff --git a/chart2/Module_chart2.mk b/chart2/Module_chart2.mk
index 16a74a1..de0ab12 100644
--- a/chart2/Module_chart2.mk
+++ b/chart2/Module_chart2.mk
@@ -24,6 +24,7 @@ $(eval $(call gb_Module_add_l10n_targets,chart2,\
 $(eval $(call gb_Module_add_slowcheck_targets,chart2,\
     CppunitTest_chart2_export \
     CppunitTest_chart2_import \
+    CppunitTest_chart2_trendcalculators \
 ))
 
 ifeq ($(ENABLE_CHART_TESTS),TRUE)
diff --git a/chart2/qa/extras/chart2_trendcalculators.cxx b/chart2/qa/extras/chart2_trendcalculators.cxx
new file mode 100644
index 0000000..7ddb4d8
--- /dev/null
+++ b/chart2/qa/extras/chart2_trendcalculators.cxx
@@ -0,0 +1,214 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "charttest.hxx"
+#include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
+#include <com/sun/star/chart2/XRegressionCurveCalculator.hpp>
+
+// Define the index of sheets in the test document
+#define SHEET_POTENTIAL1          0
+#define SHEET_POTENTIAL2          ( SHEET_POTENTIAL1 + 1)
+#define SHEET_POTENTIAL_LAST      ( SHEET_POTENTIAL2 )
+
+#define SHEET_LINEAR1             ( SHEET_POTENTIAL_LAST + 1 )
+#define SHEET_LINEAR_LAST         ( SHEET_LINEAR1 )
+
+#define SHEET_POLYNOMIAL1         ( SHEET_LINEAR_LAST + 1 )
+#define SHEET_POLYNOMIAL_LAST     ( SHEET_POLYNOMIAL1 )
+
+#define SHEET_EXPONENTIAL1        ( SHEET_POLYNOMIAL_LAST + 1 )
+#define SHEET_EXPONENTIAL2        ( SHEET_EXPONENTIAL1 + 1 )
+#define SHEET_EXPONENTIAL_LAST    ( SHEET_EXPONENTIAL2 )
+
+class Chart2TrendCalculators : public ChartTest
+{
+public:
+    void setUp();
+    void tearDown();
+
+    void testPotentialRegression1();
+    void testPotentialRegression2();
+    void testLinearRegression1();
+    void testPolynomialRegression1();
+    void testExponentialRegression1();
+    void testExponentialRegression2();
+
+    CPPUNIT_TEST_SUITE(Chart2TrendCalculators);
+    CPPUNIT_TEST(testPotentialRegression1);
+    CPPUNIT_TEST(testPotentialRegression2);
+    CPPUNIT_TEST(testLinearRegression1);
+    CPPUNIT_TEST(testPolynomialRegression1);
+    CPPUNIT_TEST(testExponentialRegression1);
+    CPPUNIT_TEST(testExponentialRegression2);
+    CPPUNIT_TEST_SUITE_END();
+
+private:
+
+    Reference<chart2::XRegressionCurve> m_xCurve;
+    Reference< chart2::XRegressionCurveCalculator > m_xRegressionCurveCalculator;
+
+    void loadCalculatorFromSheet(sal_Int32 nSheet);
+    void checkCalculator(
+        Sequence< double > xValues, Sequence< double > yValues,
+        OUString sExpectedFormula );
+
+};
+
+void Chart2TrendCalculators::setUp()
+{
+    ChartTest::setUp();
+    load("/chart2/qa/extras/data/ods/", "trend_calculators.ods");
+}
+
+void Chart2TrendCalculators::tearDown()
+{
+    m_xRegressionCurveCalculator.clear();
+    m_xCurve.clear();
+    ChartTest::tearDown();
+}
+
+void Chart2TrendCalculators::loadCalculatorFromSheet(sal_Int32 nSheet)
+{
+    Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(nSheet, mxComponent);
+    CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc.is());
+    CPPUNIT_ASSERT(xChartDoc.is());
+
+    Reference<chart2::XDataSeries> xDataSeries = getDataSeriesFromDoc(xChartDoc, 0);
+    CPPUNIT_ASSERT(xDataSeries.is());
+
+    Reference<chart2::XRegressionCurveContainer> xRegressionCurveContainer(xDataSeries, UNO_QUERY_THROW);
+    CPPUNIT_ASSERT( xRegressionCurveContainer.is() );
+
+    Sequence< Reference< chart2::XRegressionCurve > > xRegressionCurveSequence = xRegressionCurveContainer->getRegressionCurves();
+    CPPUNIT_ASSERT_EQUAL((sal_Int32) 1, xRegressionCurveSequence.getLength());
+
+    m_xCurve = xRegressionCurveSequence[0];
+    CPPUNIT_ASSERT(m_xCurve.is());
+
+    m_xRegressionCurveCalculator = m_xCurve->getCalculator();
+    CPPUNIT_ASSERT(m_xRegressionCurveCalculator.is());
+}
+
+void Chart2TrendCalculators::checkCalculator(
+    Sequence< double > xValues, Sequence< double > yValues,
+    OUString sExpectedFormula )
+{
+    m_xRegressionCurveCalculator->recalculateRegression( xValues, yValues );
+    OUString aRepresentation = m_xRegressionCurveCalculator->getRepresentation ();
+    CPPUNIT_ASSERT_EQUAL( sExpectedFormula, aRepresentation );
+    double r2 = m_xRegressionCurveCalculator->getCorrelationCoefficient();
+    CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, r2, 1e-8 );
+}
+
+// test y = A x ^ B
+void Chart2TrendCalculators::testPotentialRegression1()
+{
+    loadCalculatorFromSheet( SHEET_POTENTIAL1 );
+    m_xRegressionCurveCalculator->setRegressionProperties( 0, false, 0, 0 );
+    Sequence< double > xValues( 7 );
+    Sequence< double > yValues( 7 );
+    double d;
+    for (int i=0; i<7; i++)
+    {
+        d = (double) i;
+        xValues[i] = d;
+        yValues[i] = 2.0 * pow ( d, 3 );
+    }
+    checkCalculator( xValues, yValues, "f(x) = 2 x^3");
+}
+
+// test y = A x ^ B
+void Chart2TrendCalculators::testPotentialRegression2()
+{
+    loadCalculatorFromSheet( SHEET_POTENTIAL2 );
+    m_xRegressionCurveCalculator->setRegressionProperties( 0, false, 0, 0 );
+    Sequence< double > xValues( 7 );
+    Sequence< double > yValues( 7 );
+    double d;
+    for (int i=0; i<7; i++)
+    {
+        d = (double) i;
+        xValues[i] = d;
+        yValues[i] = -2.0 * pow ( d, 3 );
+    }
+    checkCalculator( xValues, yValues, "f(x) = -2 x^3");
+}
+
+// test y = - 2 X - 5
+void Chart2TrendCalculators::testLinearRegression1()
+{
+    loadCalculatorFromSheet( SHEET_LINEAR1 );
+    m_xRegressionCurveCalculator->setRegressionProperties( 1, false, 0, 0 );
+    Sequence< double > xValues( 7 );
+    Sequence< double > yValues( 7 );
+    double d;
+    for (int i=0; i<7; i++)
+    {
+        d = (double) i;
+        xValues[i] = d;
+        yValues[i] = - 2.0 * d - 5.0 ;
+    }
+    checkCalculator( xValues, yValues, "f(x) =  - 2x - 5");
+}
+
+// test y = A x ^ B
+void Chart2TrendCalculators::testPolynomialRegression1()
+{
+    loadCalculatorFromSheet( SHEET_POLYNOMIAL1 );
+    m_xRegressionCurveCalculator->setRegressionProperties( 2, false, 0, 0 );
+    Sequence< double > xValues( 7 );
+    Sequence< double > yValues( 7 );
+    double d;
+    for (int i=0; i<7; i++)
+    {
+        d = (double) i;
+        xValues[i] = d;
+        yValues[i] =  - 2.0 * d * d + 4 * d - 5;
+    }
+    checkCalculator( xValues, yValues, "f(x) =  - 2x^2 + 4x - 5");
+}
+
+void Chart2TrendCalculators::testExponentialRegression1()
+{
+    loadCalculatorFromSheet( SHEET_EXPONENTIAL1 );
+    m_xRegressionCurveCalculator->setRegressionProperties( 0, false, 0, 0 );
+    Sequence< double > xValues( 7 );
+    Sequence< double > yValues( 7 );
+    double d;
+    for (int i=0; i<7; i++)
+    {
+        d = (double) i;
+        xValues[i] = d;
+        yValues[i] = 2.0 * exp ( 0.3 * d );
+    }
+    checkCalculator( xValues, yValues, "f(x) = 2 exp( 0.3 x )");
+}
+
+void Chart2TrendCalculators::testExponentialRegression2()
+{
+    loadCalculatorFromSheet( SHEET_EXPONENTIAL2 );
+    m_xRegressionCurveCalculator->setRegressionProperties( 0, false, 0, 0 );
+    Sequence< double > xValues( 7 );
+    Sequence< double > yValues( 7 );
+    double d;
+    for (int i=0; i<7; i++)
+    {
+        d = (double) i;
+        xValues[i] = d;
+        yValues[i] = -2.0 * exp ( 0.3 * d );
+    }
+    checkCalculator( xValues, yValues, "f(x) = -2 exp( 0.3 x )");
+}
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION(Chart2TrendCalculators);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/qa/extras/data/ods/trend_calculators.ods b/chart2/qa/extras/data/ods/trend_calculators.ods
new file mode 100644
index 0000000..fdc5ea4
Binary files /dev/null and b/chart2/qa/extras/data/ods/trend_calculators.ods differ


More information about the Libreoffice-commits mailing list