summaryrefslogtreecommitdiff
path: root/sc/qa
diff options
context:
space:
mode:
authorƁukasz Hryniuk <lukasz.hryniuk@wp.pl>2015-08-25 03:14:56 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-08-26 01:45:59 +0000
commit32950e9089aa323303154156c27f713ba3efdf85 (patch)
treef53d540b7c9ccdf5d5953a91c1178aeb908bc5ea /sc/qa
parent1a5b5750ed4157420bc0e0e9f384d3984dee9acd (diff)
tdf#89387 test for GCD function
Change-Id: Ia9ae1f8583948620b6f496afcadd292671cdc906 Reviewed-on: https://gerrit.libreoffice.org/18004 Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com> Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'sc/qa')
-rw-r--r--sc/qa/unit/ucalc.hxx1
-rw-r--r--sc/qa/unit/ucalc_formula.cxx82
2 files changed, 83 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index f10f838b75ac..1b93a838a319 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -188,6 +188,7 @@ public:
void testFuncFTESTBug();
void testFuncCHITEST();
void testFuncSUMX2PY2();
+ void testFuncGCD();
void testExternalRef();
void testExternalRefFunctions();
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index 20b9e33c8090..da8fc5ed2f5a 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -5795,4 +5795,86 @@ void Test::testFuncSUMX2PY2()
m_pDoc->DeleteTab(0);
}
+void Test::testFuncGCD()
+{
+ sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on.
+
+ m_pDoc->InsertTab(0, "GCDTest");
+
+ OUString aVal;
+ ScAddress aPos(4,0,0);
+
+ m_pDoc->SetString(aPos, "=GCD(A1)");
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Calculation of GCD for failed", 0.0, m_pDoc->GetValue(aPos));
+ m_pDoc->SetValue(0, 0, 0, 10.0); // A1
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Calculation of GCD for failed", 10.0, m_pDoc->GetValue(aPos));
+ m_pDoc->SetValue(0, 0, 0, -2.0); // A1
+ aVal = m_pDoc->GetString(aPos);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("GCD should return Err:502 for values less then 0",
+ OUString("Err:502"), aVal);
+ m_pDoc->SetString(0, 0, 0, "a"); // A1
+ aVal = m_pDoc->GetString(aPos);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("GCD should return #VALUE! for a single string",
+ OUString("#VALUE!"), aVal);
+
+ m_pDoc->SetString(aPos, "=GCD(A1:B2)");
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Calculation of GCD for failed", 0.0, m_pDoc->GetValue(aPos));
+ m_pDoc->SetValue(0, 1, 0, -12.0); // B1
+ aVal = m_pDoc->GetString(aPos);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("GCD should return Err:502 for a matrix with values less then 0",
+ OUString("Err:502"), aVal);
+ m_pDoc->SetValue(0, 0, 0, 15.0); // A1
+ m_pDoc->SetValue(0, 1, 0, 0.0); // B1
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Calculation of GCD for failed", 15.0, m_pDoc->GetValue(aPos));
+ m_pDoc->SetValue(1, 0, 0, 5.0); // B1
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Calculation of GCD for failed", 5.0, m_pDoc->GetValue(aPos));
+ m_pDoc->SetValue(0, 1, 0, 10.0); // A2
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Calculation of GCD for failed", 5.0, m_pDoc->GetValue(aPos));
+ m_pDoc->SetValue(1, 0, 0, 30.0); // B1
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Calculation of GCD for failed", 5.0, m_pDoc->GetValue(aPos));
+ m_pDoc->SetValue(0, 0, 0, 20.0); // A1
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Calculation of GCD for failed", 10.0, m_pDoc->GetValue(aPos));
+ m_pDoc->SetValue(1, 1, 0, 120.0); // B2
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Calculation of GCD for failed", 10.0, m_pDoc->GetValue(aPos));
+ m_pDoc->SetValue(1, 0, 0, 40.0); // B1
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Calculation of GCD for failed", 20.0, m_pDoc->GetValue(aPos));
+ m_pDoc->SetValue(1, 0, 0, 45.0); // B1
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Calculation of GCD for failed", 5.0, m_pDoc->GetValue(aPos));
+
+ // with floor
+ m_pDoc->SetValue(1, 0, 0, 45.381); // B1
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Calculation of GCD for failed", 5.0, m_pDoc->GetValue(aPos));
+ m_pDoc->SetValue(1, 1, 0, 120.895); // B2
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Calculation of GCD for failed", 5.0, m_pDoc->GetValue(aPos));
+ m_pDoc->SetValue(0, 0, 0, 20.97); // A1
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Calculation of GCD for failed", 5.0, m_pDoc->GetValue(aPos));
+ m_pDoc->SetValue(0, 1, 0, 10.15); // A2
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Calculation of GCD for failed", 5.0, m_pDoc->GetValue(aPos));
+
+ // inline array
+ m_pDoc->SetString(aPos, "=GCD({3;6;9})");
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Calculation of GCD for failed", 3.0, m_pDoc->GetValue(aPos));
+ m_pDoc->SetString(aPos, "=GCD({150;0})");
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Calculation of GCD for failed", 150.0, m_pDoc->GetValue(aPos));
+ m_pDoc->SetString(aPos, "=GCD({-3;6;9})");
+ aVal = m_pDoc->GetString(aPos);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("GCD should return Err:502 for a array with values less then 0",
+ OUString("Err:502"), aVal);
+ m_pDoc->SetString(aPos, "=GCD({\"a\";6;9})");
+ aVal = m_pDoc->GetString(aPos);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("GCD should return #VALUE! for a array with strings",
+ OUString("#VALUE!"), aVal);
+
+ // inline list of values
+ m_pDoc->SetString(aPos, "=GCD(12;24;36;48;60)");
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Calculation of GCD for failed", 12.0, m_pDoc->GetValue(aPos));
+ m_pDoc->SetString(aPos, "=GCD(0;12;24;36;48;60)");
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Calculation of GCD for failed", 12.0, m_pDoc->GetValue(aPos));
+ m_pDoc->SetString(aPos, "=GCD(\"a\";1)");
+ aVal = m_pDoc->GetString(aPos);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("GCD should return #VALUE! for a array with strings",
+ OUString("#VALUE!"), aVal);
+
+ m_pDoc->DeleteTab(0);
+}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */