def test_contains_false(self): expected_value = False given_value = 1.6 in FloatRange(0, 10, 1.5) self.assertEqual(expected_value, given_value) given_value = 0 in FloatRange(10, 0, -1.5) self.assertEqual(expected_value, given_value)
def test_index(self): expected_value = 1 given_value = FloatRange(0, 10, 1.5).index(1.5) self.assertEqual(expected_value, given_value) given_value = FloatRange(10, 0, -1.5).index(8.5) self.assertEqual(expected_value, given_value)
def test_contains_true(self): expected_value = True given_value = 10 in FloatRange(10, 0, -1.5) self.assertEqual(expected_value, given_value) given_value = 8.5 in FloatRange(10, 0, -1.5) self.assertEqual(expected_value, given_value)
def test_repr_decimal(self): cases = [ ('FloatRange(0, 10.0, 1)', str(FloatRange(10.))), ('FloatRange(0, 10.12, 1)', str(FloatRange(10.12))), ('FloatRange(10.0, 20.0, 1)', str(FloatRange(10., 20.))), ('FloatRange(10, 20, 3.2)', str(FloatRange(10, 20, 3.2))), ] for case in cases: self.assertEqual(case[0], case[1])
def test_valid_number(self): expected_value = 1 given_value = FloatRange._precision(12354.2) self.assertEqual(expected_value, given_value) expected_value = 2 given_value = FloatRange._precision(.22) self.assertEqual(expected_value, given_value) expected_value = 1 given_value = FloatRange._precision(22.) self.assertEqual(expected_value, given_value)
def test_max(self): expected_value = 10 given_value = max(FloatRange(10, 0, -1.5)) self.assertEqual(expected_value, given_value)
def test_getitem_IndexError(self): expected_value = IndexError with self.assertRaises(expected_value): FloatRange(0, 10, 1.5)[123]
def test_getitem_negative(self): expected_value = 9 given_value = FloatRange(0, 10, 1.5)[-1] self.assertEqual(expected_value, given_value)
def test_count_invalid(self): expected_value = 0 given_value = FloatRange(0, 10.9, 1.6).count('a') self.assertEqual(expected_value, given_value)
def test_inequality_reverse(self): self.assertTrue(12 != FloatRange(10))
def test_inequality_fail(self): self.assertTrue(FloatRange(10) != FloatRange(9))
def test_inequality_float(self): self.assertFalse(FloatRange(10) != FloatRange(10.))
def test_equality_reverse(self): self.assertFalse(12 == FloatRange(10))
def test_equality_fail(self): self.assertFalse(FloatRange(10) == FloatRange(9))
def test_equality_float(self): self.assertTrue(FloatRange(10) == FloatRange(10.))
def test_getitem_positive(self): expected_value = 1.5 given_value = FloatRange(0, 10, 1.5) self.assertEqual(expected_value, given_value[1])
def test_inequality_multi_args(self): self.assertTrue(FloatRange(1, 5) != FloatRange(5, 1)) self.assertFalse(FloatRange(1, 5) != FloatRange(1, 5)) self.assertFalse(FloatRange(1, 5, 2) != FloatRange(1, 5, 2))
def test_inequality_wrong_type(self): vals = ['12', 12, None] obj = FloatRange(51) for v in vals: self.assertTrue(obj != v)
def test_count_zero(self): expected_value = 0 given_value = FloatRange(0, 10.9, 1.6).count(1.5) self.assertEqual(expected_value, given_value)
def test_getitem_TypeError(self): expected_value = TypeError with self.assertRaises(expected_value): FloatRange(0, 10, 1.5)['a']
def test_len_non_zero(self): expected_value = 7 given_value = len(FloatRange(0, 10.5, 1.5)) self.assertEqual(expected_value, given_value)
def test_repr_simple(self): self.assertEqual('FloatRange(0, 10, 1)', str(FloatRange(10))) self.assertEqual('FloatRange(10, 20, 1)', str(FloatRange(10, 20))) self.assertEqual('FloatRange(10, 20, 3)', str(FloatRange(10, 20, 3)))