Пример #1
0
    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)
Пример #2
0
    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)
Пример #3
0
    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)
Пример #4
0
    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])
Пример #5
0
    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)
Пример #6
0
    def test_max(self):
        expected_value = 10

        given_value = max(FloatRange(10, 0, -1.5))
        self.assertEqual(expected_value, given_value)
Пример #7
0
    def test_getitem_IndexError(self):
        expected_value = IndexError

        with self.assertRaises(expected_value):
            FloatRange(0, 10, 1.5)[123]
Пример #8
0
    def test_getitem_negative(self):
        expected_value = 9

        given_value = FloatRange(0, 10, 1.5)[-1]
        self.assertEqual(expected_value, given_value)
Пример #9
0
    def test_count_invalid(self):
        expected_value = 0

        given_value = FloatRange(0, 10.9, 1.6).count('a')
        self.assertEqual(expected_value, given_value)
Пример #10
0
 def test_inequality_reverse(self):
     self.assertTrue(12 != FloatRange(10))
Пример #11
0
 def test_inequality_fail(self):
     self.assertTrue(FloatRange(10) != FloatRange(9))
Пример #12
0
 def test_inequality_float(self):
     self.assertFalse(FloatRange(10) != FloatRange(10.))
Пример #13
0
 def test_equality_reverse(self):
     self.assertFalse(12 == FloatRange(10))
Пример #14
0
 def test_equality_fail(self):
     self.assertFalse(FloatRange(10) == FloatRange(9))
Пример #15
0
 def test_equality_float(self):
     self.assertTrue(FloatRange(10) == FloatRange(10.))
Пример #16
0
    def test_getitem_positive(self):
        expected_value = 1.5

        given_value = FloatRange(0, 10, 1.5)
        self.assertEqual(expected_value, given_value[1])
Пример #17
0
 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))
Пример #18
0
    def test_inequality_wrong_type(self):
        vals = ['12', 12, None]
        obj = FloatRange(51)

        for v in vals:
            self.assertTrue(obj != v)
Пример #19
0
    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)
Пример #20
0
    def test_getitem_TypeError(self):
        expected_value = TypeError

        with self.assertRaises(expected_value):
            FloatRange(0, 10, 1.5)['a']
Пример #21
0
    def test_len_non_zero(self):
        expected_value = 7

        given_value = len(FloatRange(0, 10.5, 1.5))
        self.assertEqual(expected_value, given_value)
Пример #22
0
 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)))