Completed
Push — master ( bd259b...7b4bdc )
by Christophe
9s
created

ImpreciseFloatTest.test___le__()   A

Complexity

Conditions 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
1
# This Python file uses the following encoding: utf-8
2
3
from unittest import TestCase
4
5
from galactic.type.number import *
6
7
8
class ImpreciseFloatTest(TestCase):
9
    def test___init__(self):
10
        infinity = ImpreciseFloat()
11
        self.assertEqual(
12
            infinity.inf,
13
            -math.inf,
14
            "The lower limit of the real line is not correct"
15
        )
16
        self.assertEqual(
17
            infinity.sup,
18
            math.inf,
19
            "The upper limit of the real line is not correct"
20
        )
21
        lower_bounded = ImpreciseFloat(inf=0)
22
        self.assertEqual(
23
            lower_bounded.inf,
24
            0,
25
            "The lower limit of the positive numbers is not correct"
26
        )
27
        upper_bounded = ImpreciseFloat(sup=0)
28
        self.assertEqual(
29
            upper_bounded.sup,
30
            0,
31
            "The upper limit of the negative numbers is not correct"
32
        )
33
        contradiction = ImpreciseFloat(inf=5, sup=0)
34
        self.assertEqual(
35
            contradiction.inf,
36
            math.inf,
37
            "The lower limit of the contradiction is not correct"
38
        )
39
        self.assertEqual(
40
            contradiction.sup,
41
            -math.inf,
42
            "The upper limit of the contradiction is not correct"
43
        )
44
45
    def test___le__(self):
46
        i_5_10 = ImpreciseFloat(inf=5, sup=10)
47
        i_5_15 = ImpreciseFloat(inf=5, sup=15)
48
        i_10_20 = ImpreciseFloat(inf=10, sup=20)
49
        self.assertTrue(
50
            i_5_10.issubset(i_5_15),
51
            "[5,10] <= [5,15]"
52
        )
53
        self.assertTrue(
54
            i_5_10.issubset(i_5_10),
55
            "[5,10] <= [5,10]"
56
        )
57
        self.assertFalse(
58
            i_5_10.issubset(i_10_20),
59
            "not [5,10] <= [10,20]"
60
        )
61
62
    def test___lt__(self):
63
        i_5_10 = ImpreciseFloat(inf=5, sup=10)
64
        i_5_15 = ImpreciseFloat(inf=5, sup=15)
65
        i_10_20 = ImpreciseFloat(inf=10, sup=20)
66
        self.assertTrue(
67
            i_5_10 < i_5_15,
68
            "[5,10] < [5,15]"
69
        )
70
        self.assertFalse(
71
            i_5_10 < i_5_10,
72
            "not [5,10] < [5,10]"
73
        )
74
        self.assertFalse(
75
            i_5_10 < i_10_20,
76
            "not [5,10] < [10,20]"
77
        )
78
79
    def test___ge__(self):
80
        i_5_10 = ImpreciseFloat(inf=5, sup=10)
81
        i_5_15 = ImpreciseFloat(inf=5, sup=15)
82
        i_10_20 = ImpreciseFloat(inf=10, sup=20)
83
        self.assertTrue(
84
            i_5_15.issuperset(i_5_10),
85
            "[5,15] >= [5,10]"
86
        )
87
        self.assertTrue(
88
            i_5_10.issuperset(i_5_10),
89
            "[5,10] >= [5,10]"
90
        )
91
        self.assertFalse(
92
            i_5_10.issuperset(i_10_20),
93
            "not [5,10] >= [10,20]"
94
        )
95
96
    def test___gt__(self):
97
        i_5_10 = ImpreciseFloat(inf=5, sup=10)
98
        i_5_15 = ImpreciseFloat(inf=5, sup=15)
99
        i_10_20 = ImpreciseFloat(inf=10, sup=20)
100
        self.assertTrue(
101
            i_5_15 > i_5_10,
102
            "[5,15] > [5,10]"
103
        )
104
        self.assertFalse(
105
            i_5_10 > i_5_10,
106
            "not [5,10] > [5,10]"
107
        )
108
        self.assertFalse(
109
            i_5_10 > i_10_20,
110
            "not [5,10] > [10,20]"
111
        )
112
113
    def test___and__(self):
114
        i_5_10 = ImpreciseFloat(inf=5, sup=10)
115
        i_5_15 = ImpreciseFloat(inf=5, sup=15)
116
        i_10_20 = ImpreciseFloat(inf=10, sup=20)
117
        self.assertEqual(
118
            i_5_15 & i_5_10,
119
            ImpreciseFloat(inf=5, sup=10),
120
            "[5,15] & [5,10] = [5,10]"
121
        )
122
        self.assertEqual(
123
            i_5_15 & i_10_20,
124
            ImpreciseFloat(inf=10, sup=15),
125
            "[5,15] & [10,20] = [10,15]"
126
        )
127
128
    def test___or__(self):
129
        i_5_10 = ImpreciseFloat(inf=5, sup=10)
130
        i_5_15 = ImpreciseFloat(inf=5, sup=15)
131
        i_10_20 = ImpreciseFloat(inf=10, sup=20)
132
        self.assertEqual(
133
            i_5_15 | i_5_10,
134
            ImpreciseFloat(inf=5, sup=15),
135
            "[5,15] | [5,10] = [5,15]"
136
        )
137
        self.assertEqual(
138
            i_5_15 | i_10_20,
139
            ImpreciseFloat(inf=5, sup=20),
140
            "[5,15] | [10,20] = [5,20]"
141
        )
142
143
    def test__isdisjoint(self):
144
        i_5_10 = ImpreciseFloat(inf=5, sup=10)
145
        i_5_15 = ImpreciseFloat(inf=5, sup=15)
146
        i_15_20 = ImpreciseFloat(inf=15, sup=20)
147
        self.assertTrue(
148
            i_5_10.isdisjoint(i_15_20),
149
            "[5,10] is disjoint of [15,20]"
150
        )
151
        self.assertFalse(
152
            i_5_15.isdisjoint(i_15_20),
153
            "[5,15] is not disjoint of [15,20]"
154
        )
155
156
    def test_union(self):
157
        i_5_10 = ImpreciseFloat(inf=5, sup=10)
158
        i_5_15 = ImpreciseFloat(inf=5, sup=15)
159
        i_10_20 = ImpreciseFloat(inf=10, sup=20)
160
        self.assertEqual(
161
            i_5_15.union(i_5_10, i_10_20),
162
            ImpreciseFloat(inf=5, sup=20),
163
            "[5,15] | [5,10] | [10,20] = [5,20]"
164
        )
165
166
    def test_intersection(self):
167
        i_5_10 = ImpreciseFloat(inf=5, sup=10)
168
        i_5_15 = ImpreciseFloat(inf=5, sup=15)
169
        i_10_20 = ImpreciseFloat(inf=10, sup=20)
170
        self.assertEqual(
171
            i_5_15.intersection(i_5_10, i_10_20),
172
            ImpreciseFloat(inf=10, sup=10),
173
            "[5,15] & [5,10] & [10,20] = [10,10]"
174
        )
175
176
    def test___repr__(self):
177
        i_5_10 = ImpreciseFloat(inf=5, sup=10)
178
        self.assertEqual(
179
            repr(i_5_10),
180
            "ImpreciseFloat(inf=5.0, sup=10.0)",
181
            "[5,15] & [5,10] & [10,20] = [10,10]"
182
        )
183
184
    def test___str__(self):
185
        i_5_10 = ImpreciseFloat(inf=5, sup=10)
186
        print(i_5_10)
187
        self.assertEqual(
188
            str(i_5_10),
189
            "[5.0:10.0]",
190
            "str(ImpreciseFloat(inf=5, sup=10)) == [5.0:10.0]"
191
        )
192
193