def test_rate_from_str_unknown_char_fails(self): with self.assertRaises(ValueError): rate_from_str('unknown', 30)
def test_rate_from_str_multiple_of(self): self.assertEqual(rate_from_str('1x', 23.976), 23.976) self.assertEqual(rate_from_str('1.1x', 23.976), 23.976 * 1.1) self.assertEqual(rate_from_str('0.9x', 23.976), 23.976 * 0.9)
def test_rate_from_str_less_than_equal_to_zero_fails(self): with self.assertRaises(ValueError): rate_from_str('0', 30) with self.assertRaises(ValueError): rate_from_str('-1', 30)
def test_rate_from_str_fractional(self): self.assertEqual(rate_from_str('24000/1001', 30), 24000 * 1.0 / 1001)
def test_rate_from_str_non_rational_fraction(self): self.assertEqual(rate_from_str('24.0/1001', 30), 24 * 1.0 / 1001) self.assertEqual(rate_from_str('24/1.001', 30), 24 * 1.0 / 1.001) self.assertEqual(rate_from_str('24.0/1.001', 30), 24 * 1.0 / 1.001)
def test_rate_from_str_is_none(self): self.assertEqual(rate_from_str(None, 30), 30)
def test_rate_from_str_integer_or_float(self): self.assertEqual(rate_from_str('24', 30), 24) self.assertEqual(rate_from_str('25.0', 30), 25)
def test_rate_from_str_multiple_of(self): self.assertEqual(rate_from_str('1x', 23.976), 23.976) self.assertEqual(rate_from_str('1.1x', 23.976), 23.976*1.1) self.assertEqual(rate_from_str('0.9x', 23.976), 23.976*0.9)
def test_rate_from_str_non_rational_fraction(self): self.assertEqual(rate_from_str('24.0/1001', 30), 24*1.0/1001) self.assertEqual(rate_from_str('24/1.001', 30), 24*1.0/1.001) self.assertEqual(rate_from_str('24.0/1.001', 30), 24*1.0/1.001)
def test_rate_from_str_fractional(self): self.assertEqual(rate_from_str('24000/1001', 30), 24000*1.0/1001)