Completed
Push — master ( 13587c...ae872b )
by Christophe
11s
created

ImpreciseIntegerTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 35
Duplicated Lines 97.14 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 34
loc 35
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B test___init__() 34 34 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 View Code Duplication
    def test___init__(self):
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
10
        infinity = ImpreciseFloat()
11
        self.assertEqual(
12
            infinity.lower,
13
            -math.inf,
14
            "The lower limit of the real line is not correct"
15
        )
16
        self.assertEqual(
17
            infinity.upper,
18
            math.inf,
19
            "The upper limit of the real line is not correct"
20
        )
21
        lower_bounded = ImpreciseFloat(lower=0)
22
        self.assertEqual(
23
            lower_bounded.lower,
24
            0,
25
            "The lower limit of the positive numbers is not correct"
26
        )
27
        upper_bounded = ImpreciseFloat(upper=0)
28
        self.assertEqual(
29
            upper_bounded.upper,
30
            0,
31
            "The upper limit of the negative numbers is not correct"
32
        )
33
        contradiction = ImpreciseFloat(lower=5, upper=0)
34
        self.assertEqual(
35
            contradiction.lower,
36
            math.inf,
37
            "The lower limit of the contradiction is not correct"
38
        )
39
        self.assertEqual(
40
            contradiction.upper,
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(lower=5, upper=10)
47
        i_5_15 = ImpreciseFloat(lower=5, upper=15)
48
        i_10_20 = ImpreciseFloat(lower=10, upper=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(lower=5, upper=10)
64
        i_5_15 = ImpreciseFloat(lower=5, upper=15)
65
        i_10_20 = ImpreciseFloat(lower=10, upper=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(lower=5, upper=10)
81
        i_5_15 = ImpreciseFloat(lower=5, upper=15)
82
        i_10_20 = ImpreciseFloat(lower=10, upper=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(lower=5, upper=10)
98
        i_5_15 = ImpreciseFloat(lower=5, upper=15)
99
        i_10_20 = ImpreciseFloat(lower=10, upper=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(lower=5, upper=10)
115
        i_5_15 = ImpreciseFloat(lower=5, upper=15)
116
        i_10_20 = ImpreciseFloat(lower=10, upper=20)
117
        self.assertEqual(
118
            i_5_15 & i_5_10,
119
            ImpreciseFloat(lower=5, upper=10),
120
            "[5,15] & [5,10] = [5,10]"
121
        )
122
        self.assertEqual(
123
            i_5_15 & i_10_20,
124
            ImpreciseFloat(lower=10, upper=15),
125
            "[5,15] & [10,20] = [10,15]"
126
        )
127
128
    def test___or__(self):
129
        i_5_10 = ImpreciseFloat(lower=5, upper=10)
130
        i_5_15 = ImpreciseFloat(lower=5, upper=15)
131
        i_10_20 = ImpreciseFloat(lower=10, upper=20)
132
        self.assertEqual(
133
            i_5_15 | i_5_10,
134
            ImpreciseFloat(lower=5, upper=15),
135
            "[5,15] | [5,10] = [5,15]"
136
        )
137
        self.assertEqual(
138
            i_5_15 | i_10_20,
139
            ImpreciseFloat(lower=5, upper=20),
140
            "[5,15] | [10,20] = [5,20]"
141
        )
142
143
    def test__isdisjoint(self):
144
        i_5_10 = ImpreciseFloat(lower=5, upper=10)
145
        i_5_15 = ImpreciseFloat(lower=5, upper=15)
146
        i_15_20 = ImpreciseFloat(lower=15, upper=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(lower=5, upper=10)
158
        i_5_15 = ImpreciseFloat(lower=5, upper=15)
159
        i_10_20 = ImpreciseFloat(lower=10, upper=20)
160
        self.assertEqual(
161
            i_5_15.union(i_5_10, i_10_20),
162
            ImpreciseFloat(lower=5, upper=20),
163
            "[5,15] | [5,10] | [10,20] = [5,20]"
164
        )
165
166
    def test_intersection(self):
167
        i_5_10 = ImpreciseFloat(lower=5, upper=10)
168
        i_5_15 = ImpreciseFloat(lower=5, upper=15)
169
        i_10_20 = ImpreciseFloat(lower=10, upper=20)
170
        self.assertEqual(
171
            i_5_15.intersection(i_5_10, i_10_20),
172
            ImpreciseFloat(lower=10, upper=10),
173
            "[5,15] & [5,10] & [10,20] = [10,10]"
174
        )
175
176
    def test___repr__(self):
177
        i_5_10 = ImpreciseFloat(lower=5, upper=10)
178
        self.assertEqual(
179
            repr(i_5_10),
180
            "ImpreciseFloat(lower=5.0, upper=10.0)",
181
            "[5,15] & [5,10] & [10,20] = [10,10]"
182
        )
183
184
    def test___str__(self):
185
        i_5_10 = ImpreciseFloat(lower=5, upper=10)
186
        print(i_5_10)
187
        self.assertEqual(
188
            str(i_5_10),
189
            "[5.0:10.0]",
190
            "str(ImpreciseFloat(lower=5, upper=10)) == [5.0:10.0]"
191
        )
192
193
class ImpreciseIntegerTest(TestCase):
194 View Code Duplication
    def test___init__(self):
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
195
        infinity = ImpreciseInteger()
196
        self.assertEqual(
197
            infinity.lower,
198
            -sys.maxsize,
199
            "The lower limit of the real line is not correct"
200
        )
201
        self.assertEqual(
202
            infinity.upper,
203
            sys.maxsize,
204
            "The upper limit of the real line is not correct"
205
        )
206
        lower_bounded = ImpreciseInteger(lower=0)
207
        self.assertEqual(
208
            lower_bounded.lower,
209
            0,
210
            "The lower limit of the positive numbers is not correct"
211
        )
212
        upper_bounded = ImpreciseInteger(upper=0)
213
        self.assertEqual(
214
            upper_bounded.upper,
215
            0,
216
            "The upper limit of the negative numbers is not correct"
217
        )
218
        contradiction = ImpreciseInteger(lower=5, upper=0)
219
        self.assertEqual(
220
            contradiction.lower,
221
            sys.maxsize,
222
            "The lower limit of the contradiction is not correct"
223
        )
224
        self.assertEqual(
225
            contradiction.upper,
226
            -sys.maxsize,
227
            "The upper limit of the contradiction is not correct"
228
        )
229