Example #1
0
 def test_adding(self):
     sixty_five = RomanNumeral("LXV")
     eighty_seven = RomanNumeral("LXXXVII")
     self.assertEqual(int(sixty_five + eighty_seven), 152)
     self.assertEqual(type(sixty_five + eighty_seven), RomanNumeral)
     self.assertEqual(int(sixty_five + 87), 152)
     self.assertEqual(type(sixty_five + 87), RomanNumeral)
     self.assertEqual(str(sixty_five + 87), str("CLII"))
Example #2
0
    def test_conversion_of_one(self):
        """Verify 1 is converted to I."""
        r = RomanNumeral()

        self.assertEqual(r.convert(1), 'I')
        self.assertEqual(r.convert(2), 'II')
        self.assertEqual(r.convert(3), 'III')
        self.assertEqual(r.convert(4), 'IV')
        self.assertEqual(r.convert(5), 'V')
        self.assertEqual(r.convert(9), 'IX')
        self.assertEqual(r.convert(10), 'X')
 def test_numerals(self):
     for arabic, roman in self.numerals.items():
         self.assertEqual(roman, str(RomanNumeral(arabic)))
Example #4
0
 def verify(self, integer, numeral):
     self.assertEqual(int(RomanNumeral(numeral)), integer)
     self.assertNotEqual(int(RomanNumeral(numeral)), integer + 1)
     self.assertNotEqual(int(RomanNumeral(numeral)), integer - 1)
Example #5
0
 def test_from_int_and_string_representation(self):
     self.assertEqual(str(RomanNumeral("I")), "I")
     self.assertEqual(repr(RomanNumeral("CD")), "RomanNumeral('CD')")
     self.assertEqual(str(RomanNumeral.from_int(1)), str(RomanNumeral("I")))
     self.assertEqual(str(RomanNumeral.from_int(10)), "X")
     self.assertEqual(str(RomanNumeral.from_int(21)), "XXI")
     self.assertEqual(str(RomanNumeral.from_int(600)), "DC")
     self.assertEqual(str(RomanNumeral.from_int(2000)), "MM")
     self.assertEqual(str(RomanNumeral.from_int(12)), "XII")
     self.assertEqual(str(RomanNumeral.from_int(25)), "XXV")
     self.assertEqual(str(RomanNumeral.from_int(6)), "VI")
     self.assertEqual(str(RomanNumeral.from_int(4)), "IV")
     self.assertEqual(str(RomanNumeral.from_int(9)), "IX")
     self.assertEqual(str(RomanNumeral.from_int(14)), "XIV")
     self.assertEqual(str(RomanNumeral.from_int(1888)), "MDCCCLXXXVIII")
     self.assertEqual(str(RomanNumeral.from_int(1999)), "MCMXCIX")
     self.assertEqual(str(RomanNumeral.from_int(1948)), "MCMXLVIII")
Example #6
0
 def test_equality_and_ordering(self):
     self.assertEqual(RomanNumeral("I"), 1)
     self.assertNotEqual(RomanNumeral("I"), 2)
     self.assertEqual(RomanNumeral("I"), "I")
     self.assertEqual(RomanNumeral.from_int(10), "X")
     self.assertEqual(RomanNumeral.from_int(21), "XXI")
     self.assertEqual(RomanNumeral.from_int(600), "DC")
     self.assertEqual(RomanNumeral.from_int(2000), "MM")
     self.assertEqual(RomanNumeral.from_int(12), "XII")
     self.assertEqual(RomanNumeral.from_int(25), "XXV")
     self.assertEqual(RomanNumeral.from_int(6), "VI")
     self.assertEqual(RomanNumeral.from_int(4), "IV")
     self.assertEqual(RomanNumeral.from_int(9), "IX")
     self.assertEqual(RomanNumeral.from_int(14), "XIV")
     self.assertEqual(RomanNumeral.from_int(1888), "MDCCCLXXXVIII")
     self.assertEqual(RomanNumeral.from_int(1999), "MCMXCIX")
     self.assertEqual(RomanNumeral.from_int(1948), "MCMXLVIII")
     self.assertLess(RomanNumeral("MCMXLVIII"), RomanNumeral("MCMXCIX"))
     self.assertGreater(RomanNumeral("MCMXCIX"), RomanNumeral("MCMXLVIII"))
     self.assertGreaterEqual(RomanNumeral("IX"), RomanNumeral("III"))
     self.assertLessEqual(RomanNumeral("III"), RomanNumeral("IX"))
     self.assertGreaterEqual(RomanNumeral("X"), RomanNumeral("X"))
     self.assertLessEqual(RomanNumeral("IIII"), RomanNumeral("IV"))
     self.assertFalse(RomanNumeral("V") < RomanNumeral("IV"))
     self.assertFalse(RomanNumeral("V") > RomanNumeral("IX"))
     self.assertFalse(RomanNumeral("V") <= RomanNumeral("IV"))
     self.assertFalse(RomanNumeral("V") >= RomanNumeral("IX"))
     with self.assertRaises(TypeError):
         RomanNumeral("X") < "XX"
     with self.assertRaises(TypeError):
         RomanNumeral("X") <= "XX"
     with self.assertRaises(TypeError):
         RomanNumeral("X") > "XX"
     with self.assertRaises(TypeError):
         RomanNumeral("X") >= "XX"
     self.assertFalse(RomanNumeral("V") < 4)
     self.assertFalse(RomanNumeral("V") > 9)
     self.assertFalse(RomanNumeral("V") <= 4)
     self.assertFalse(RomanNumeral("V") >= 9)
     with self.assertRaises(TypeError):
         RomanNumeral("X") < "XX"
     with self.assertRaises(TypeError):
         RomanNumeral("X") <= "XX"
     with self.assertRaises(TypeError):
         RomanNumeral("X") > "XX"
     with self.assertRaises(TypeError):
         RomanNumeral("X") >= "XX"