summaryrefslogtreecommitdiff
path: root/sc/qa/unit/datatransformation_test.cxx
diff options
context:
space:
mode:
authorVikas <vikasmahato0@gmail.com>2018-07-03 17:05:36 +0530
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2018-07-06 15:25:16 +0200
commit8981adda6a24a172245b8cd0dd60e31644e23c75 (patch)
treec02e2cc472fd469b8449d32ddfb9fb66fedb430d /sc/qa/unit/datatransformation_test.cxx
parentc3a732a11c320b98e31dad79f421d4d73f33a15b (diff)
Added aggregate functions for external data
- Sum, which returns the sum of values in the column. - Average, which returns the average of values in the column. - Min, which returns the minimum of the values in the column. - Max, which returns the maximum of the values in the column. Change-Id: I196eb2d367d2f8c50ceec42735f6f56e2067e401 Reviewed-on: https://gerrit.libreoffice.org/56862 Tested-by: Jenkins Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'sc/qa/unit/datatransformation_test.cxx')
-rw-r--r--sc/qa/unit/datatransformation_test.cxx80
1 files changed, 80 insertions, 0 deletions
diff --git a/sc/qa/unit/datatransformation_test.cxx b/sc/qa/unit/datatransformation_test.cxx
index 8cec163eeb43..c011941a6cb7 100644
--- a/sc/qa/unit/datatransformation_test.cxx
+++ b/sc/qa/unit/datatransformation_test.cxx
@@ -35,6 +35,10 @@ public:
void testTextToUpper();
void testTextCapitalize();
void testTextTrim();
+ void testAggregateSum();
+ void testAggregateAverage();
+ void testAggregateMin();
+ void testAggregateMax();
CPPUNIT_TEST_SUITE(ScDataTransformationTest);
CPPUNIT_TEST(testColumnRemove);
@@ -44,6 +48,10 @@ public:
CPPUNIT_TEST(testTextToUpper);
CPPUNIT_TEST(testTextCapitalize);
CPPUNIT_TEST(testTextTrim);
+ CPPUNIT_TEST(testAggregateSum);
+ CPPUNIT_TEST(testAggregateAverage);
+ CPPUNIT_TEST(testAggregateMin);
+ CPPUNIT_TEST(testAggregateMax);
CPPUNIT_TEST_SUITE_END();
private:
@@ -193,6 +201,78 @@ void ScDataTransformationTest::testTextTrim()
CPPUNIT_ASSERT_EQUAL(OUString("Paris"), m_pDoc->GetString(2, 2, 0));
}
+void ScDataTransformationTest::testAggregateSum()
+{
+ m_pDoc->SetValue(2, 0, 0, 2034);
+ m_pDoc->SetValue(2, 1, 0, 2342);
+ m_pDoc->SetValue(2, 2, 0, 57452);
+
+ m_pDoc->SetValue(4, 0, 0, 4829.98);
+ m_pDoc->SetValue(4, 1, 0, 53781.3);
+ m_pDoc->SetValue(4, 2, 0, 9876.4);
+ m_pDoc->SetValue(4, 3, 0, 0);
+
+ sc::AggregateFunction aTransform({2, 4}, sc::AGGREGATE_FUNCTION::SUM);
+ aTransform.Transform(*m_pDoc);
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(61828, m_pDoc->GetValue(2, 4, 0), 1e-10);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(68487.68, m_pDoc->GetValue(4, 4, 0), 1e-10);
+}
+
+void ScDataTransformationTest::testAggregateAverage()
+{
+ m_pDoc->SetValue(2, 0, 0, 2034);
+ m_pDoc->SetValue(2, 1, 0, 2342);
+ m_pDoc->SetValue(2, 2, 0, 57453);
+
+ m_pDoc->SetValue(3, 0, 0, 4);
+ m_pDoc->SetValue(3, 1, 0, 4);
+ m_pDoc->SetValue(3, 2, 0, 4);
+
+ sc::AggregateFunction aTransform({2, 3}, sc::AGGREGATE_FUNCTION::AVERAGE);
+ aTransform.Transform(*m_pDoc);
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(20609.6666666667, m_pDoc->GetValue(2, 3, 0), 1e-10);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(4, m_pDoc->GetValue(3, 3, 0), 1e-10);
+}
+
+void ScDataTransformationTest::testAggregateMin()
+{
+ m_pDoc->SetValue(2, 0, 0, 2034);
+ m_pDoc->SetValue(2, 1, 0, 2342);
+ m_pDoc->SetValue(2, 2, 0, 57453);
+
+ m_pDoc->SetValue(3, 0, 0, 2034);
+ m_pDoc->SetValue(3, 1, 0, -2342);
+ m_pDoc->SetValue(3, 2, 0, 57453);
+
+ sc::AggregateFunction aTransform({2, 3}, sc::AGGREGATE_FUNCTION::MIN);
+ aTransform.Transform(*m_pDoc);
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(2034, m_pDoc->GetValue(2, 3, 0), 1e-10);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(-2342, m_pDoc->GetValue(3, 3, 0), 1e-10);
+}
+
+void ScDataTransformationTest::testAggregateMax()
+{
+ m_pDoc->SetValue(2, 0, 0, 2034);
+ m_pDoc->SetValue(2, 1, 0, 2342);
+ m_pDoc->SetValue(2, 2, 0, 57453);
+ m_pDoc->SetValue(2, 3, 0, -453);
+
+ m_pDoc->SetValue(3, 0, 0, 2034);
+ m_pDoc->SetValue(3, 1, 0, -2342);
+ m_pDoc->SetValue(3, 2, 0, -57453);
+ m_pDoc->SetValue(3, 3, 0, -453);
+
+ sc::AggregateFunction aTransform({2, 3}, sc::AGGREGATE_FUNCTION::MAX);
+ aTransform.Transform(*m_pDoc);
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(57453, m_pDoc->GetValue(2, 4, 0), 1e-10);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(2034, m_pDoc->GetValue(3, 4, 0), 1e-10);
+}
+
+
ScDataTransformationTest::ScDataTransformationTest() :
ScBootstrapFixture( "sc/qa/unit/data/dataprovider" ),
m_pDoc(nullptr)