#ifndef XPATHIC_ARITHMETIC_TEST_H #define XPATHIC_ARITHMETIC_TEST_H #include "../CppUnit/framework/TestCase.h" #include "../CppUnit/framework/TestSuite.h" #include "../CppUnit/framework/TestCaller.h" #include template class ArithmeticTest : public TestCase { public: ArithmeticTest(const std::string& name) : TestCase(name) { } // ArithmeticTest void setUp() { } // setUp void test1() { using namespace Arabica::XPath; XPathExpression* p1 = new NumericValue(1); XPathExpression* p2 = new NumericValue(2); XPathExpressionPtr add(new impl::PlusOperator(p1, p2)); add->evaluate(dummy_); assertEquals(3.0, add->evaluateAsNumber(dummy_), 0.0); } // test1 void test2() { using namespace Arabica::XPath; XPathExpression* p1 = new NumericValue(1); XPathExpression* p2 = new NumericValue(2); XPathExpressionPtr minus(new impl::MinusOperator(p1, p2)); assertEquals(-1.0, minus->evaluateAsNumber(dummy_), 0.0); } // test2 void test3() { using namespace Arabica::XPath; XPathExpression* p1 = new NumericValue(3); XPathExpression* p2 = new NumericValue(2); XPathExpressionPtr mult(new impl::MultiplyOperator(p1, p2)); assertEquals(6, mult->evaluateAsNumber(dummy_), 0.0); } // test3 void test4() { using namespace Arabica::XPath; XPathExpression* mult = new impl::MultiplyOperator(new NumericValue(4), new NumericValue(2)); XPathExpressionPtr minus(new impl::MinusOperator(mult, new NumericValue(2))); assertEquals(8, mult->evaluateAsNumber(dummy_), 0.0); assertEquals(6, minus->evaluateAsNumber(dummy_), 0.0); } // test4 void test5() { using namespace Arabica::XPath; XPathExpression* p1 = new NumericValue(12); XPathExpression* p2 = new NumericValue(2); XPathExpressionPtr div(new impl::DivideOperator(p1, p2)); assertEquals(6, div->evaluateAsNumber(dummy_), 0.0); } // test5 void test6() { using namespace Arabica::XPath; XPathExpression* p1 = new NumericValue(12); XPathExpression* p2 = new NumericValue(2); XPathExpressionPtr mod(new impl::ModOperator(p1, p2)); assertEquals(0, mod->evaluateAsNumber(dummy_), 0.0); } // test6 void test7() { using namespace Arabica::XPath; XPathExpression* p1 = new NumericValue(11); XPathExpression* p2 = new NumericValue(2); XPathExpressionPtr div(new impl::DivideOperator(p1, p2)); assertEquals(5.5, div->evaluateAsNumber(dummy_), 0.0); } // test7 void test8() { using namespace Arabica::XPath; XPathExpression* p1 = new NumericValue(11); XPathExpression* p2 = new NumericValue(4); XPathExpressionPtr mod(new impl::ModOperator(p1, p2)); assertEquals(3, mod->evaluateAsNumber(dummy_), 0.0); } // test8 void test9() { using namespace Arabica::XPath; XPathExpression* p1 = new NumericValue(5); XPathExpression* p2 = new NumericValue(2); XPathExpressionPtr mod(new impl::ModOperator(p1, p2)); assertEquals(1.0, mod->evaluateAsNumber(dummy_), 0.0); } // test9 void test10() { using namespace Arabica::XPath; XPathExpression* p1 = new NumericValue(5); XPathExpression* p2 = new NumericValue(-2); XPathExpressionPtr mod(new impl::ModOperator(p1, p2)); assertEquals(1.00, mod->evaluateAsNumber(dummy_), 0.0); } // test10 void test11() { using namespace Arabica::XPath; XPathExpression* p1 = new NumericValue(-5); XPathExpression* p2 = new NumericValue(2); XPathExpressionPtr mod(new impl::ModOperator(p1, p2)); assertEquals(-1.0, mod->evaluateAsNumber(dummy_), 0.0); } // test11 void test12() { using namespace Arabica::XPath; XPathExpression* p1 = new NumericValue(-5); XPathExpression* p2 = new NumericValue(-2); XPathExpressionPtr mod(new impl::ModOperator(p1, p2)); assertEquals(-1.0, mod->evaluateAsNumber(dummy_), 0.0); } // test12 void test13() { using namespace Arabica::XPath; XPathExpression* p1 = new NumericValue(5); XPathExpressionPtr p2(new impl::UnaryNegative(p1)); assertEquals(-5.0, p2->evaluateAsNumber(dummy_), 0.0); } // test13 void test14() { using namespace Arabica::XPath; XPathExpression* p1 = new NumericValue(-5); XPathExpressionPtr p2(new impl::UnaryNegative(p1)); assertEquals(5.0, p2->evaluateAsNumber(dummy_), 0.0); } // test14 private: Arabica::DOM::Node dummy_; }; // ArithmeticTest template TestSuite* ArithmeticTest_suite() { TestSuite *suiteOfTests = new TestSuite; suiteOfTests->addTest(new TestCaller >("test1", &ArithmeticTest::test1)); suiteOfTests->addTest(new TestCaller >("test2", &ArithmeticTest::test2)); suiteOfTests->addTest(new TestCaller >("test3", &ArithmeticTest::test3)); suiteOfTests->addTest(new TestCaller >("test4", &ArithmeticTest::test4)); suiteOfTests->addTest(new TestCaller >("test5", &ArithmeticTest::test5)); suiteOfTests->addTest(new TestCaller >("test6", &ArithmeticTest::test6)); suiteOfTests->addTest(new TestCaller >("test7", &ArithmeticTest::test7)); suiteOfTests->addTest(new TestCaller >("test8", &ArithmeticTest::test8)); suiteOfTests->addTest(new TestCaller >("test9", &ArithmeticTest::test9)); suiteOfTests->addTest(new TestCaller >("test10", &ArithmeticTest::test10)); suiteOfTests->addTest(new TestCaller >("test11", &ArithmeticTest::test11)); suiteOfTests->addTest(new TestCaller >("test12", &ArithmeticTest::test12)); suiteOfTests->addTest(new TestCaller >("test13", &ArithmeticTest::test13)); suiteOfTests->addTest(new TestCaller >("test14", &ArithmeticTest::test14)); return suiteOfTests; } // ArithmeticTest_suite #endif