Ejemplo n.º 1
0
 def test_set_metal_value_invalid_repeat_L(self):
     """ Tests LLV """
     with self.assertRaises(exception.InvalidCurrencyRule) as context:
         util.get_net_value([50, 50, 5])
     self.assertEqual('"L" can never be repeated',
                      context.exception.args[0])
     self.assertEqual(exception.InvalidCurrencyRule,
                      context.exception.__class__)
Ejemplo n.º 2
0
 def test_set_metal_value_invalid_D(self):
     """ Tests DM """
     with self.assertRaises(exception.InvalidCurrencyRule) as context:
         util.get_net_value([500, 1000])
     self.assertEqual('"D" can never be subtracted',
                      context.exception.args[0])
     self.assertEqual(exception.InvalidCurrencyRule,
                      context.exception.__class__)
Ejemplo n.º 3
0
 def test_set_metal_value_invalid_I1(self):
     """ Tests MID """
     with self.assertRaises(exception.InvalidCurrencyRule) as context:
         util.get_net_value([1000, 1, 500])
     self.assertEqual('"I" can be subtracted from "V" and "X" only',
                      context.exception.args[0])
     self.assertEqual(exception.InvalidCurrencyRule,
                      context.exception.__class__)
Ejemplo n.º 4
0
 def test_set_metal_value_invalid_repeat_M(self):
     """ Tests MMMM """
     with self.assertRaises(exception.InvalidCurrencyRule) as context:
         util.get_net_value([1000, 1000, 1000, 1000])
     self.assertEqual('"M" can be repeated 3 times max',
                      context.exception.args[0])
     self.assertEqual(exception.InvalidCurrencyRule,
                      context.exception.__class__)
Ejemplo n.º 5
0
    def parse_message(self, line):
        line = line.strip().lower()

        response = self.parse_message_with_rule1(line)
        if response:
            self.calculate_roman_value(response)
            return

        response = self.parse_message_with_rule2(line)
        if response:
            self.calculate_metal_cost(response)
            return

        response = self.parse_message_with_rule3(line)
        if response:
            self.currency.set_currency_value(response[0], response[1])
            return

        response = self.parse_message_with_rule4(line)
        if response:
            metal, cost, currency_codes = response
            try:
                roman_values = self.currency.parse_currency(currency_codes)
                unit = util.get_net_value(roman_values)
                self.metal.set_metal_value(metal, cost, unit)
            except (exception.InvalidCurrency, exception.InvalidCost) as e:
                print(e.args[0])
            return
        else:
            print(messages.NO_IDEA)
Ejemplo n.º 6
0
 def calculate_roman_value(self, currency_codes):
     try:
         roman_values = self.currency.parse_currency(currency_codes)
         net_value = util.get_net_value(roman_values)
     except (exception.InvalidCurrency, exception.InvalidCurrencyRule) as e:
         print(e.args[0])
     else:
         print(" ".join(currency_codes), "is", net_value)
Ejemplo n.º 7
0
 def calculate_metal_cost(self, words):
     metal = words.pop()
     try:
         roman_values = self.currency.parse_currency(words)
         calculated_unit = util.get_net_value(roman_values)
         metal_value = self.metal.get_metal_value(metal)
     except (exception.InvalidCurrency, exception.InvalidMetal) as e:
         print(e.args[0])
     else:
         print(
             " ".join(words),
             metal.title(),
             "is",
             int(calculated_unit * metal_value),
             "Credits"
         )
Ejemplo n.º 8
0
 def test_get_net_value_with_subtraction(self):
     """ Tests MMVI """
     response = util.get_net_value([1000, 1000, 5, 1])
     self.assertEqual(2006, response)
Ejemplo n.º 9
0
 def test_set_metal_value_mixed(self):
     """ Tests MCMXLIV """
     response = util.get_net_value([1000, 100, 1000, 10, 50, 1, 5])
     self.assertEqual(1944, response)
Ejemplo n.º 10
0
 def test_set_metal_value(self):
     """ Tests III """
     response = util.get_net_value([1, 1, 1])
     self.assertEqual(3, response)
Ejemplo n.º 11
0
 def test_get_net_value_with_subtraction1(self):
     """ Tests XXXIX """
     response = util.get_net_value([10, 10, 10, 1, 10])
     self.assertEqual(39, response)