Ejemplo n.º 1
0
    def test_multiplication_with_expression(self):
        factory = self.factory

        with self.assertRaises(OperatorError):
            factory.dollar(5) * int
        with self.assertRaises(OperatorError):
            factory.dollar(10) * factory.franc(2)
        with self.assertRaises(OperatorError):
            (factory.dollar(3) + factory.franc(2)) * "a"
        with self.assertRaises(OperatorError):
            (factory.dollar(10) - factory.franc(2)) * "a"

        res = factory.dollar(5) * 2
        bank = Bank()
        reduced = bank.reduce(res, "USD")
        self.assertEqual(factory.dollar(10), reduced)

        res = (factory.dollar(2) + factory.franc(8)) * 2
        bank = Bank()
        reduced = bank.reduce(res, "USD")
        self.assertEqual(factory.dollar(12), reduced)

        res = (factory.dollar(10) - factory.franc(4)) * 2
        reduced = bank.reduce(res, "USD")
        self.assertEqual(factory.dollar(16), reduced)

        res2 = factory.dollar(5) * 0
        reduced = bank.reduce(res2, "USD")
        self.assertEqual(factory.dollar(0), reduced)
Ejemplo n.º 2
0
    def test_divplication_with_expression(self):
        factory = self.factory

        with self.assertRaises(OperatorError):
            factory.dollar(5) / "aadf"
        with self.assertRaises(OperatorError):
            factory.dollar(10) / factory.franc(2)
        with self.assertRaises(OperatorError):
            (factory.dollar(3) + factory.franc(2)) / "a"
        with self.assertRaises(OperatorError):
            (factory.dollar(10) - factory.franc(2)) / "bcd"

        res = factory.dollar(5) - factory.franc(10)
        bank = Bank()
        bank.add_rate("CHF", "USD", 2)
        reduced = bank.reduce(res, "USD")
        self.assertEqual(factory.dollar(0), reduced)

        res2 = factory.dollar(5) - factory.dollar(5)
        reduced = bank.reduce(res2, "USD")
        self.assertEqual(factory.dollar(0), reduced)
Ejemplo n.º 3
0
    def test_multiplication_with_expression(self):
        factory = self.factory

        with self.assertRaises(OperatorError):
            factory.dollar(5) * int
        with self.assertRaises(OperatorError):
            factory.dollar(10) * factory.franc(2)
        with self.assertRaises(OperatorError):
            (factory.dollar(3) + factory.franc(2)) * "a"
        with self.assertRaises(OperatorError):
            (factory.dollar(10) - factory.franc(2)) * "a"

        res = factory.dollar(5) * 2
        bank = Bank()
        reduced = bank.reduce(res, "USD")
        self.assertEqual(factory.dollar(10), reduced)

        res = (factory.dollar(2) + factory.franc(8)) * 2
        bank = Bank()
        reduced = bank.reduce(res, "USD")
        self.assertEqual(factory.dollar(12), reduced)

        res = (factory.dollar(10) - factory.franc(4)) * 2
        reduced = bank.reduce(res, "USD")
        self.assertEqual(factory.dollar(16), reduced)

        res2 = factory.dollar(5) * 0
        reduced = bank.reduce(res2, "USD")
        self.assertEqual(factory.dollar(0), reduced)
Ejemplo n.º 4
0
    def test_divplication_with_expression(self):
        factory = self.factory

        with self.assertRaises(OperatorError):
            factory.dollar(5) / "aadf"
        with self.assertRaises(OperatorError):
            factory.dollar(10) / factory.franc(2)
        with self.assertRaises(OperatorError):
            (factory.dollar(3) + factory.franc(2)) / "a"
        with self.assertRaises(OperatorError):
            (factory.dollar(10) - factory.franc(2)) / "bcd"

        res = factory.dollar(5) - factory.franc(10)
        bank = Bank()
        bank.add_rate("CHF", "USD", 2)
        reduced = bank.reduce(res, "USD")
        self.assertEqual(factory.dollar(0), reduced)

        res2 = factory.dollar(5) - factory.dollar(5)
        reduced = bank.reduce(res2, "USD")
        self.assertEqual(factory.dollar(0), reduced)
Ejemplo n.º 5
0
 def test_mixed_addition(self):
     factory = self.factory
     expr2 = factory.dollar(5) + factory.franc(10)
     bank = Bank()
     reduced2 = bank.reduce(expr2, "USD")
     self.assertEqual(factory.dollar(10), reduced2)
Ejemplo n.º 6
0
 def test_simple_addition(self):
     factory = self.factory
     expr = factory.dollar(5) + factory.dollar(5)
     bank = Bank()
     reduced = bank.reduce(expr, "USD")
     self.assertEqual(factory.dollar(10), reduced)
Ejemplo n.º 7
0
 def test_mixed_addition(self):
     factory = self.factory
     expr2 = factory.dollar(5) + factory.franc(10)
     bank = Bank()
     reduced2 = bank.reduce(expr2, "USD")
     self.assertEqual(factory.dollar(10), reduced2)
Ejemplo n.º 8
0
 def test_simple_addition(self):
     factory = self.factory
     expr = factory.dollar(5) + factory.dollar(5)
     bank = Bank()
     reduced = bank.reduce(expr, "USD")
     self.assertEqual(factory.dollar(10), reduced)