1from pytest import mark
2
3from intervals import IntInterval
4
5
6class TestArithmeticOperators(object):
7    @mark.parametrize(('first', 'second', 'result'), (
8        (IntInterval([1, 3]), IntInterval([1, 2]), [2, 5]),
9        (IntInterval([1, 3]), 1, [2, 4]),
10        (1, IntInterval([1, 3]), [2, 4]),
11        ([1, 2], IntInterval([1, 2]), [2, 4])
12    ))
13    def test_add_operator(self, first, second, result):
14        assert first + second == IntInterval(result)
15
16    @mark.parametrize(('first', 'second', 'result'), (
17        (IntInterval([1, 3]), IntInterval([1, 2]), [-1, 2]),
18        (IntInterval([1, 3]), 1, [0, 2]),
19        (1, IntInterval([1, 3]), [-2, 0])
20    ))
21    def test_sub_operator(self, first, second, result):
22        assert first - second == IntInterval(result)
23
24    def test_isub_operator(self):
25        range_ = IntInterval([1, 3])
26        range_ -= IntInterval([1, 2])
27        assert range_ == IntInterval([-1, 2])
28
29    def test_iadd_operator(self):
30        range_ = IntInterval([1, 2])
31        range_ += IntInterval([1, 2])
32        assert range_ == IntInterval([2, 4])
33
34
35class TestArithmeticFunctions(object):
36    @mark.parametrize(('first', 'second', 'result'), (
37        (IntInterval([1, 3]), IntInterval([1, 2]), [1, 2]),
38        (IntInterval([-2, 2]), 1, [-2, 1])
39    ))
40    def test_glb(self, first, second, result):
41        assert first.glb(second) == IntInterval(result)
42
43    @mark.parametrize(('first', 'second', 'result'), (
44        (IntInterval([1, 3]), IntInterval([1, 2]), [1, 3]),
45        (IntInterval([-2, 2]), 1, [1, 2])
46    ))
47    def test_lub(self, first, second, result):
48        assert first.lub(second) == IntInterval(result)
49
50    @mark.parametrize(('first', 'second', 'result'), (
51        (IntInterval([1, 3]), IntInterval([1, 2]), [1, 2]),
52        (IntInterval([-2, 2]), 1, [1, 1])
53    ))
54    def test_inf(self, first, second, result):
55        assert first.inf(second) == IntInterval(result)
56
57    @mark.parametrize(('first', 'second', 'result'), (
58        (IntInterval([1, 3]), IntInterval([1, 2]), [1, 3]),
59        (IntInterval([-2, 2]), 1, [-2, 2])
60    ))
61    def test_sup(self, first, second, result):
62        assert first.sup(second) == IntInterval(result)
63