codac4matlab 2.0.0.dev14__cp313-cp313-win32.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. codac4matlab/__init__.py +4 -0
  2. codac4matlab/_core.cp313-win32.pyd +0 -0
  3. codac4matlab/_graphics.cp313-win32.pyd +0 -0
  4. codac4matlab/_unsupported.cp313-win32.pyd +0 -0
  5. codac4matlab/core/__init__.py +340 -0
  6. codac4matlab/graphics/__init__.py +1 -0
  7. codac4matlab/tests/__init__.py +1 -0
  8. codac4matlab/tests/test_AnalyticFunction.py +419 -0
  9. codac4matlab/tests/test_AnalyticTraj.py +63 -0
  10. codac4matlab/tests/test_Approx.py +27 -0
  11. codac4matlab/tests/test_BoolInterval.py +40 -0
  12. codac4matlab/tests/test_Color.py +79 -0
  13. codac4matlab/tests/test_ConvexPolygon.py +207 -0
  14. codac4matlab/tests/test_CtcAction.py +30 -0
  15. codac4matlab/tests/test_CtcCartProd.py +39 -0
  16. codac4matlab/tests/test_CtcCtcBoundary.py +48 -0
  17. codac4matlab/tests/test_CtcFixpoint.py +65 -0
  18. codac4matlab/tests/test_CtcInter.py +39 -0
  19. codac4matlab/tests/test_CtcInverse.py +157 -0
  20. codac4matlab/tests/test_CtcInverseNotIn.py +129 -0
  21. codac4matlab/tests/test_CtcLazy.py +50 -0
  22. codac4matlab/tests/test_CtcPolygon.py +91 -0
  23. codac4matlab/tests/test_CtcSegment.py +104 -0
  24. codac4matlab/tests/test_Ellipsoid.py +20 -0
  25. codac4matlab/tests/test_IntFullPivLU.py +57 -0
  26. codac4matlab/tests/test_Interval.py +230 -0
  27. codac4matlab/tests/test_IntervalMatrix.py +664 -0
  28. codac4matlab/tests/test_IntervalVector.py +657 -0
  29. codac4matlab/tests/test_Interval_operations.py +293 -0
  30. codac4matlab/tests/test_Matrix.py +68 -0
  31. codac4matlab/tests/test_OctaSym.py +32 -0
  32. codac4matlab/tests/test_Polygon.py +108 -0
  33. codac4matlab/tests/test_SampledTraj.py +113 -0
  34. codac4matlab/tests/test_Segment.py +123 -0
  35. codac4matlab/tests/test_SepCartProd.py +34 -0
  36. codac4matlab/tests/test_SepCtcBoundary.py +52 -0
  37. codac4matlab/tests/test_SepInverse.py +104 -0
  38. codac4matlab/tests/test_SepPolygon.py +102 -0
  39. codac4matlab/tests/test_SepProj.py +39 -0
  40. codac4matlab/tests/test_SepTransform.py +41 -0
  41. codac4matlab/tests/test_Vector.py +41 -0
  42. codac4matlab/tests/test_arithmetic_add.py +54 -0
  43. codac4matlab/tests/test_arithmetic_div.py +46 -0
  44. codac4matlab/tests/test_arithmetic_mul.py +114 -0
  45. codac4matlab/tests/test_arithmetic_sub.py +54 -0
  46. codac4matlab/tests/test_capd.py +19 -0
  47. codac4matlab/tests/test_cart_prod.py +37 -0
  48. codac4matlab/tests/test_eigen.py +19 -0
  49. codac4matlab/tests/test_geometry.py +136 -0
  50. codac4matlab/tests/test_hull.py +35 -0
  51. codac4matlab/tests/test_ibex.py +19 -0
  52. codac4matlab/tests/test_inversion.py +57 -0
  53. codac4matlab/tests/test_linear_ctc.py +77 -0
  54. codac4matlab/tests/test_operators.py +348 -0
  55. codac4matlab/tests/test_transformations.py +61 -0
  56. codac4matlab/unsupported/__init__.py +1 -0
  57. codac4matlab/version.py +1 -0
  58. codac4matlab-2.0.0.dev14.dist-info/METADATA +23 -0
  59. codac4matlab-2.0.0.dev14.dist-info/RECORD +61 -0
  60. codac4matlab-2.0.0.dev14.dist-info/WHEEL +5 -0
  61. codac4matlab-2.0.0.dev14.dist-info/top_level.txt +1 -0
@@ -0,0 +1,293 @@
1
+ #!/usr/bin/env python
2
+
3
+ # Codac tests
4
+ #
5
+ # Most of these tests come from the IBEX library (Gilles Chabert)
6
+ # See more: https://ibex-lib.readthedocs.io
7
+ # They have been revised to fit with Codac (v2)
8
+ #
9
+ # ----------------------------------------------------------------------------
10
+ # \date 2024
11
+ # \author Gilles Chabert, Simon Rohou
12
+ # \copyright Copyright 2024 Codac Team
13
+ # \license GNU Lesser General Public License (LGPL)
14
+
15
+ import unittest
16
+ from codac import *
17
+ import sys
18
+ import math
19
+
20
+ MAX_DOUBLE = sys.float_info.max
21
+
22
+ class TestInterval_operations(unittest.TestCase):
23
+
24
+ def CHECK_add(self, x, y, expected):
25
+ self.assertTrue((x + y) == expected)
26
+ self.assertTrue((y + x) == expected) # symmetrical case
27
+ x_ = Interval(x); x_ += y
28
+ self.assertTrue(x_ == expected) # +=operator
29
+ y_ = Interval(y); y_ += x
30
+ self.assertTrue(y_ == expected) # +=operator in the other direction
31
+ self.assertTrue(((-x)-y) == -expected) # substraction
32
+ self.assertTrue(((-y)-x) == -expected) # symmetrical case
33
+ x_ = Interval(-x); x_ -= y
34
+ self.assertTrue(x_ == -expected) # -=operator
35
+ y_ = Interval(-y); y_ -= x
36
+ self.assertTrue(y_ == -expected) # -=operator in the other direction
37
+
38
+ def CHECK_add_scalar(self, x, y, expected):
39
+ self.assertTrue((x+y) == expected)
40
+ self.assertTrue((y+x) == expected)
41
+ x_ = Interval(x); x_ += y
42
+ self.assertTrue(x_ == expected) # test the +=operator
43
+ self.assertTrue(((-x)-y) == -expected)
44
+ self.assertTrue(((-y)-x) == -expected)
45
+ x_ = Interval(-x); x_ -= y
46
+ self.assertTrue(x_ == -expected) # test the -=operator
47
+
48
+ def CHECK_mul(self, x, y, expected):
49
+ self.assertTrue(x * y == expected)
50
+ self.assertTrue(y * x == expected) # symmetrical case
51
+ x_ = Interval(x); x_ *= y
52
+ self.assertTrue(x_ == expected) # *=operator
53
+
54
+ def CHECK_mul_scalar(self, x, y, expected):
55
+ self.assertTrue(x * y == expected)
56
+ self.assertTrue(y * x == expected) # symmetrical case
57
+ x_ = Interval(x); x_ *= y
58
+ self.assertTrue(x_ == expected) # *=operator
59
+
60
+ def CHECK_div(self, x, y, expected):
61
+ self.assertTrue(x / Interval(y) == expected)
62
+ self.assertTrue(Interval(x) / y == expected)
63
+ x_ = Interval(x); x_ /= y
64
+ self.assertTrue(x_ == expected) # /=operator
65
+
66
+ def CHECK_div_scalar(self, x, y, expected):
67
+ self.assertTrue(x / y == expected)
68
+ x_ = Interval(x); x_ /= y
69
+ self.assertTrue(x_ == expected) # /=operator
70
+
71
+ def CHECK_trigo(self, x, expected):
72
+ self.assertTrue(Approx(sin(x), 1e-9) == expected)
73
+ self.assertTrue(Approx(sin(Interval.pi()-x), 1e-9) == expected)
74
+ self.assertTrue(Approx(sin(x+Interval.two_pi()), 1e-9) == expected)
75
+ self.assertTrue(Approx(sin(-x), 1e-9) == -expected)
76
+ self.assertTrue(Approx(cos(x-Interval.half_pi()), 1e-9) == expected)
77
+ self.assertTrue(Approx(cos(Interval.half_pi()-x), 1e-9) == expected)
78
+ self.assertTrue(Approx(cos(x+Interval.half_pi()), 1e-9) == -expected)
79
+ self.assertTrue(Approx(cos(x+Interval.two_pi()-Interval.half_pi()), 1e-9) == expected)
80
+
81
+ def CHECK_pow(self, x, p, expected, eps = 0.):
82
+ self.assertTrue(Approx(pow(x,p),eps) == expected)
83
+ if p%2==0:
84
+ self.assertTrue(Approx(pow(-x,p),eps) == expected)
85
+ else:
86
+ self.assertTrue(Approx(pow(-x,p),eps) == -expected)
87
+
88
+ def tests_interval_operations(self):
89
+
90
+ self.assertTrue(0 < next_float(0))
91
+ self.assertTrue(0 > previous_float(0))
92
+ self.assertTrue(1 < next_float(1))
93
+ self.assertTrue(1 > previous_float(1))
94
+ self.assertTrue(oo == next_float(oo))
95
+ self.assertTrue(-oo == previous_float(-oo))
96
+ self.assertTrue(-MAX_DOUBLE >= next_float(-oo))
97
+ self.assertTrue(MAX_DOUBLE <= previous_float(oo))
98
+ self.assertTrue(oo > MAX_DOUBLE)
99
+ self.assertTrue(-oo < -MAX_DOUBLE)
100
+ self.assertTrue(-Interval(0,1) == Interval(-1,0))
101
+ self.assertTrue(-Interval(-oo,oo) == Interval(-oo,oo))
102
+ self.assertTrue(-Interval(-oo,0) == Interval(0,oo))
103
+ self.assertTrue(-Interval(-oo,1) == Interval(-1,oo))
104
+
105
+ self.CHECK_add(Interval.empty(), Interval(0,1), Interval.empty())
106
+ self.CHECK_add(Interval(0,1), Interval.empty(), Interval.empty())
107
+ self.CHECK_add(Interval(-oo,1), Interval(0,1), Interval(-oo, 2))
108
+ self.CHECK_add(Interval(1,oo), Interval(0,1), Interval(1,oo))
109
+ self.CHECK_add(Interval(-oo,oo), Interval(0,1), Interval(-oo,oo))
110
+ self.CHECK_add(Interval(MAX_DOUBLE,oo), 1, Interval(MAX_DOUBLE,oo))
111
+ self.CHECK_add(Interval(MAX_DOUBLE,oo), -1, Interval(previous_float(MAX_DOUBLE),oo))
112
+ self.CHECK_add(Interval(MAX_DOUBLE,oo), Interval(MAX_DOUBLE,oo), Interval(MAX_DOUBLE,oo))
113
+ self.CHECK_add(Interval(MAX_DOUBLE,oo), -oo, Interval.empty())
114
+ self.CHECK_add(Interval(MAX_DOUBLE,oo), oo, Interval.empty())
115
+ self.CHECK_add(Interval(-oo,-MAX_DOUBLE), 1, Interval(-oo,next_float(-MAX_DOUBLE)))
116
+ self.CHECK_add(Interval(-oo,-MAX_DOUBLE), -1, Interval(-oo,-MAX_DOUBLE))
117
+ self.CHECK_add(Interval(-oo,-MAX_DOUBLE), Interval(-oo,-MAX_DOUBLE), Interval(-oo,-MAX_DOUBLE))
118
+
119
+ self.CHECK_add_scalar(Interval.empty(), oo, Interval.empty())
120
+ self.CHECK_add_scalar(Interval.empty(), 0, Interval.empty())
121
+ self.CHECK_add_scalar(Interval(0,1), 1, Interval(1,2))
122
+ self.CHECK_add_scalar(Interval(0,1), -oo, Interval.empty())
123
+ self.CHECK_add_scalar(Interval(0,1), oo, Interval.empty())
124
+ self.CHECK_add_scalar(Interval(-oo,1), 1, Interval(-oo,2))
125
+
126
+ self.CHECK_mul(Interval.empty(), Interval(0,1), Interval.empty())
127
+ self.CHECK_mul(0, Interval(-oo,oo), 0)
128
+ self.CHECK_mul(Interval(-1,1), Interval(-oo,0), Interval(-oo,oo))
129
+ self.CHECK_mul(Interval(-oo,-1), Interval(-1,0), Interval(0,oo))
130
+ self.CHECK_mul(Interval(-oo, 1), Interval(-1,0), Interval(-1,oo))
131
+ self.CHECK_mul(Interval(0, 1), Interval(1,oo), Interval(0,oo))
132
+ self.CHECK_mul(Interval(0, 1), Interval(-1,oo), Interval(-1,oo))
133
+ self.CHECK_mul(Interval(-oo,-1), Interval(0,1), Interval(-oo,0))
134
+ self.CHECK_mul(Interval(-oo, 1), Interval(0,1), Interval(-oo,1))
135
+ self.CHECK_mul(Interval(0, 1), Interval(-oo,-1), Interval(-oo,0))
136
+ self.CHECK_mul(Interval(0, 1), Interval(-oo,1), Interval(-oo,1))
137
+ self.CHECK_mul(Interval(1,oo), Interval(0,1), Interval(0,oo))
138
+ self.CHECK_mul(Interval(-1,oo), Interval(0,1), Interval(-1,oo))
139
+ self.CHECK_mul(Interval(1,2), Interval(1,2), Interval(1,4))
140
+ self.CHECK_mul(Interval(1,2), Interval(-2,3), Interval(-4,6))
141
+ self.CHECK_mul(Interval(-1,1), Interval(-2,3), Interval(-3,3))
142
+ self.CHECK_mul_scalar(Interval(1,2), -oo, Interval.empty())
143
+ self.CHECK_mul_scalar(Interval(1,2), oo, Interval.empty())
144
+ self.CHECK_mul_scalar(Interval(1,2), -1, Interval(-2,-1))
145
+
146
+ self.CHECK_div(Interval.empty(), Interval(0,1), Interval.empty())
147
+ self.CHECK_div(0, 0, Interval.empty())
148
+ self.CHECK_div(Interval(1,2), 0, Interval.empty())
149
+ self.CHECK_div(Interval(-oo,oo), 0, Interval.empty())
150
+ self.CHECK_div(0, Interval(0,1), 0)
151
+ self.CHECK_div(0, Interval(-oo,oo), 0)
152
+ self.CHECK_div(Interval(6,12), Interval(2,3), Interval(2,6))
153
+ self.CHECK_div(Interval(6,12), Interval(-3,-2), Interval(-6,-2))
154
+ self.CHECK_div(Interval(6,12), Interval(-2,3), Interval(-oo,oo))
155
+ self.CHECK_div(Interval(-oo,-1), Interval(-1,0), Interval(1,oo))
156
+ self.CHECK_div(Interval(-oo,-1), Interval(0,1), Interval(-oo,-1))
157
+ self.CHECK_div(Interval(1,oo), Interval(-1,0), Interval(-oo,-1))
158
+ self.CHECK_div(Interval(1,oo), Interval(0,1), Interval(1,oo))
159
+ self.CHECK_div(Interval(-1,1), Interval(-1,1), Interval(-oo,oo))
160
+ self.CHECK_div_scalar(Interval(1,2), -oo, Interval.empty())
161
+ self.CHECK_div_scalar(Interval(1,2), oo, Interval.empty())
162
+ self.CHECK_div_scalar(Interval(1,2), -1, Interval(-2,-1))
163
+
164
+ self.assertTrue(sqrt(Interval(-oo,oo)) == Interval(0,oo))
165
+ self.assertTrue(sqrt(Interval(-oo,0)) == 0)
166
+ self.assertTrue(sqrt(Interval(-9,4)) == Interval(0,2))
167
+ self.assertTrue(sqrt(Interval(4,9)) == Interval(2,3))
168
+ self.assertTrue(sqrt(Interval(-9,-4)) == Interval.empty())
169
+ self.assertTrue(sqrt(Interval(-9,oo)) == Interval(0,oo))
170
+
171
+ self.assertTrue(log(Interval.empty()) == Interval.empty())
172
+ self.assertTrue(log(Interval(-oo,oo)) == Interval(-oo,oo))
173
+ self.assertTrue(log(Interval(0,oo)) == Interval(-oo,oo))
174
+ self.assertTrue(log(Interval(-oo,0)) == Interval.empty())
175
+ self.assertTrue(Approx(log(Interval(1,2))) == Interval(0,math.log(2)))
176
+ self.assertTrue(Approx(log(Interval(-1,1))) == Interval(-oo,0))
177
+ self.assertTrue(Approx(log(Interval(0,1))) == Interval(-oo,0))
178
+ self.assertTrue(Approx(log(Interval(1,oo))) == Interval(0,oo))
179
+ self.assertTrue(log(Interval(0)) == Interval.empty())
180
+ self.assertTrue(log(Interval(-2,-1)) == Interval.empty())
181
+ self.assertTrue((log(Interval(0,next_float(0)))).ub() > -744.5)
182
+
183
+ self.assertTrue(exp(Interval.empty()) == Interval.empty())
184
+ self.assertTrue(exp(Interval(-oo,oo)) == Interval(0,oo))
185
+ self.assertTrue(Approx(exp(Interval(0,oo))) == Interval(1,oo))
186
+ self.assertTrue(Approx(exp(Interval(-oo,0))) == Interval(0,1))
187
+ self.assertTrue(Approx(exp(Interval(0,2))) == Interval(1,math.exp(2)))
188
+ self.assertTrue(Approx(exp(Interval(-1,1))) == Interval(math.exp(-1),math.exp(1)))
189
+ self.assertTrue(exp(Interval(1.e100,1.e111)) == Interval(MAX_DOUBLE,oo))
190
+ self.assertTrue(exp(Interval(MAX_DOUBLE,oo)) == Interval(MAX_DOUBLE,oo))
191
+ self.assertTrue(Approx(exp(Interval(0,MAX_DOUBLE))) == Interval(1,oo))
192
+
193
+ pi_lb = Interval.pi().lb()
194
+ pi_ub = Interval.pi().ub()
195
+
196
+ self.CHECK_trigo(Interval(-oo,oo), Interval(-1,1))
197
+ self.CHECK_trigo(Interval.empty(), Interval.empty())
198
+ self.CHECK_trigo(Interval(0,pi_ub/2.0), Interval(0,1))
199
+ self.CHECK_trigo(Interval(0,pi_ub), Interval(0,1))
200
+ self.CHECK_trigo(Interval(0,3*pi_ub/2.0), Interval(-1,1))
201
+ self.CHECK_trigo(Interval(pi_lb,3*pi_ub/2.0), Interval(-1,0))
202
+ self.CHECK_trigo(Interval(0.5,1.5), Interval(math.sin(0.5),math.sin(1.5)))
203
+ self.CHECK_trigo(Interval(1.5,3), Interval(math.sin(3.0),1))
204
+ self.CHECK_trigo(Interval(3,4), Interval(math.sin(4.0),math.sin(3.0)))
205
+ self.CHECK_trigo(Interval(3,5), Interval(-1,math.sin(3.0)))
206
+ self.CHECK_trigo(Interval(3,2*pi_ub+1.5), Interval(-1,math.sin(1.5)))
207
+ self.CHECK_trigo(Interval(5,2*pi_ub+1.5), Interval(math.sin(5.0),math.sin(1.5)))
208
+ self.CHECK_trigo(Interval(5,2*pi_ub+3), Interval(math.sin(5.0),1))
209
+
210
+ self.assertTrue(floor(Interval.empty()) == Interval.empty())
211
+ self.assertTrue(floor(Interval(-oo,-0.000001)) == Interval(-oo,-1))
212
+ self.assertTrue(floor(Interval(0.00000001,oo)) == Interval(0,oo))
213
+ self.assertTrue(floor(Interval(-oo,oo)) == Interval(-oo,oo))
214
+ self.assertTrue(floor(Interval(0.01,2.99)) == Interval(0,2))
215
+ self.assertTrue(floor(Interval(-0.01,2.99)) == Interval(-1,2))
216
+ self.assertTrue(floor(Interval(1.000000001,1.9999999999)) == 1.)
217
+ self.assertTrue(floor(Interval(1e8, MAX_DOUBLE)) == Interval(1e8,MAX_DOUBLE))
218
+
219
+ self.assertTrue(ceil(Interval.empty()) == Interval.empty())
220
+ self.assertTrue(ceil(Interval(-oo,-0.000001)) == Interval(-oo,0))
221
+ self.assertTrue(ceil(Interval(0.00000001,oo)) == Interval(1.0,oo))
222
+ self.assertTrue(ceil(Interval(-oo,oo)) == Interval(-oo,oo))
223
+ self.assertTrue(ceil(Interval(0.01,2.99)) == Interval(1,3))
224
+ self.assertTrue(ceil(Interval(-0.01,2.99)) == Interval(0,3))
225
+ self.assertTrue(ceil(Interval(1.000000001,1.9999999999)) == Interval(2,2))
226
+ self.assertTrue(ceil(Interval(1e8, MAX_DOUBLE)) == Interval(1e8,MAX_DOUBLE))
227
+
228
+ self.assertTrue(integer(Interval.empty()) == Interval.empty())
229
+ self.assertTrue(integer(Interval(-oo,-0.000001)) == Interval(-oo,-1))
230
+ self.assertTrue(integer(Interval(0.00000001,oo)) == Interval(1.0,oo))
231
+ self.assertTrue(integer(Interval(-oo,oo)) == Interval(-oo,oo))
232
+ self.assertTrue(integer(Interval(0.01,2.99)) == Interval(1,2))
233
+ self.assertTrue(integer(Interval(-0.01,2.99)) == Interval(0,2))
234
+ self.assertTrue(integer(Interval(1.000000001,1.9999999999)) == Interval.empty())
235
+ self.assertTrue(integer(Interval(1e8, MAX_DOUBLE)) == Interval(1e8,MAX_DOUBLE))
236
+
237
+ self.assertTrue(tan(Interval.pi()/2.0) == Interval(-oo,oo))
238
+ x = tan(-Interval.pi())
239
+ self.assertTrue(x.diam() < 1e-8)
240
+ self.assertTrue(x.contains(0.))
241
+
242
+ self.assertTrue(Approx(tan((3*Interval.pi()/4.0)|(5*Interval.pi()/4.0))) == Interval(-1,1))
243
+ self.assertTrue(tan(Interval(-oo,oo)) == Interval(-oo,oo))
244
+ self.assertTrue(Approx(tan((-Interval.pi()/4.0)|(Interval.pi()/4.0))) == Interval(-1,1))
245
+
246
+ # tan(pi/4,pi/2)=[1,+oo)
247
+ x = Interval(pi_lb/4.0,(1-1e-10)*pi_lb/2.0)
248
+ y = tan(x)
249
+ self.assertTrue(Approx(Interval(y.lb())) == Interval(1.0))
250
+ self.assertTrue(y.ub() > 1000)
251
+
252
+ # tan(-pi/2,pi/4)=(-oo,1]
253
+ y = tan(Interval(-(1-1e-10)*pi_lb/2.0,pi_lb/4.0))
254
+ self.assertTrue(y.lb() < -1000)
255
+ self.assertTrue(y.ub() == 1.0)
256
+
257
+ self.assertTrue(atan2(Interval(-oo,oo),Interval.empty()) == Interval.empty())
258
+ self.assertTrue(Approx(atan2(Interval(1),1)) == Interval.pi()/4.0)
259
+ self.assertTrue(Approx(atan2(Interval(-1),-1)) == -3*Interval.pi()/4.0)
260
+ self.assertTrue(Approx(atan2(Interval(-1),1)) == -Interval.pi()/4.0)
261
+ self.assertTrue(Approx(atan2(Interval(1),-1)) == 3*Interval.pi()/4.0)
262
+ self.assertTrue(Approx(atan2(Interval(0,oo),Interval(0,oo))) == Interval(0,1)*Interval.half_pi())
263
+ self.assertTrue(Approx(atan2(Interval(-oo,previous_float(0.0)),Interval(-oo,0))) == -(Interval.half_pi() | Interval.pi()))
264
+ self.assertTrue(Approx(atan2(Interval(-oo,0),Interval(0,oo))) == Interval(-1,0)*Interval.half_pi())
265
+ self.assertTrue(Approx(atan2(Interval(0,oo),Interval(-oo,0))) == (Interval.half_pi() | Interval.pi()))
266
+ self.assertTrue(Approx(atan2(Interval(1,oo),Interval(-1,1))) == (Interval.pi()/4.0 | 3*Interval.pi()/4.0))
267
+ self.assertTrue(Approx(atan2(Interval(-oo,-1),Interval(-1,1))) == -(Interval.pi()/4.0 | 3*Interval.pi()/4.0))
268
+ self.assertTrue(atan2(Interval(-1,1),Interval(1,oo)) == Interval(-1,1)*Interval.pi()/4.0)
269
+ self.assertTrue(atan2(Interval(-1,1),Interval(-oo,-1)) == Interval(-1,1)*Interval.pi())
270
+ self.assertTrue(atan2(Interval(-oo,oo),Interval(-oo,oo)) == Interval(-1,1)*Interval.pi())
271
+ self.assertTrue(atan2(Interval(0),0) == Interval.empty())
272
+
273
+ self.CHECK_pow(Interval(-oo,oo), 4, Interval(0,oo))
274
+ self.CHECK_pow(Interval.empty(), 4, Interval.empty())
275
+ self.CHECK_pow(Interval(2,3), 4, Interval(16,81))
276
+ self.CHECK_pow(Interval(-2,3), 4, Interval(0,81))
277
+ self.CHECK_pow(Interval(-3,2), 4, Interval(0,81))
278
+ self.CHECK_pow(Interval(2,oo), 4, Interval(16,oo))
279
+ self.CHECK_pow(Interval(-oo,oo), 3, Interval(-oo,oo))
280
+ self.CHECK_pow(Interval.empty(), 3, Interval.empty())
281
+ self.CHECK_pow(Interval(2,3), 3, Interval(8,27))
282
+ self.CHECK_pow(Interval(-2,3), 3, Interval(-8,27))
283
+ self.CHECK_pow(Interval(-3,2), 3, Interval(-27,8))
284
+ self.CHECK_pow(Interval(2,oo), 3, Interval(8,oo))
285
+ self.CHECK_pow(Interval(-10,10), -2, Interval(1.0/100,oo), sys.float_info.epsilon)
286
+
287
+ self.assertTrue(root(Interval(0,1),-1) == Interval(1.0,oo))
288
+ self.assertTrue(Approx(root(Interval(-27,-8),3)) == Interval(-3,-2))
289
+ self.assertTrue(root(Interval(-4,1),2) == Interval(0,1))
290
+ self.assertTrue(Approx(root(Interval(-8,1),3)) == Interval(-2,1))
291
+
292
+ if __name__ == '__main__':
293
+ unittest.main()
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env python
2
+
3
+ # Codac tests
4
+ # ----------------------------------------------------------------------------
5
+ # \date 2024
6
+ # \author Simon Rohou
7
+ # \copyright Copyright 2024 Codac Team
8
+ # \license GNU Lesser General Public License (LGPL)
9
+
10
+ import unittest
11
+ from codac import *
12
+
13
+ class TestMatrix(unittest.TestCase):
14
+
15
+ def tests_def_Matrix(self):
16
+
17
+ x = Matrix([
18
+ [ 1, 2 ],
19
+ [ 3, 4 ],
20
+ ])
21
+
22
+ x[0,1] = 42
23
+ x[1,1] = 42
24
+
25
+ self.assertTrue(x == Matrix([
26
+ [ 1, 42 ],
27
+ [ 3, 42 ],
28
+ ]))
29
+
30
+ # The following simple call was a problem before
31
+ # (order of def of constructors):
32
+ m = Matrix(x)
33
+
34
+
35
+ def tests_fnc_Matrix(self):
36
+
37
+ x = Matrix([
38
+ [ -1, 3 ],
39
+ [ -6, -9 ]
40
+ ])
41
+
42
+ self.assertTrue(abs(x) == Matrix([
43
+ [ 1, 3 ],
44
+ [ 6, 9 ]
45
+ ]))
46
+
47
+ y = Matrix([
48
+ [ -1.2, 3.9 ],
49
+ [ -6.2, -9.0 ]
50
+ ])
51
+
52
+ self.assertTrue(floor(y) == Matrix([
53
+ [ -2, 3 ],
54
+ [ -7, -9 ]
55
+ ]))
56
+
57
+ self.assertTrue(ceil(y) == Matrix([
58
+ [ -1, 4 ],
59
+ [ -6, -9 ]
60
+ ]))
61
+
62
+ self.assertTrue(round(y) == Matrix([
63
+ [ -1, 4 ],
64
+ [ -6, -9 ]
65
+ ]))
66
+
67
+ if __name__ == '__main__':
68
+ unittest.main()
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env python
2
+
3
+ # Codac tests
4
+ # ----------------------------------------------------------------------------
5
+ # \date 2024
6
+ # \author Simon Rohou
7
+ # \copyright Copyright 2024 Codac Team
8
+ # \license GNU Lesser General Public License (LGPL)
9
+
10
+ import unittest
11
+ from codac import *
12
+
13
+ class TestOctaSym(unittest.TestCase):
14
+
15
+ def tests_OctaSym(self):
16
+
17
+ a = OctaSym([-2,1])
18
+ self.assertTrue(a.invert() == OctaSym([2,-1]))
19
+
20
+ x = IntervalVector([[-1,1],[5,6]])
21
+ self.assertTrue(a(x) == IntervalVector([[-6,-5],[-1,1]]))
22
+ self.assertTrue(a.invert()(a(x)) == x)
23
+
24
+ b = OctaSym([2,-1])
25
+ self.assertTrue(b.invert() == OctaSym([-2,1]))
26
+ self.assertTrue(b*b == OctaSym([-1,-2]))
27
+
28
+ c = OctaSym([-2,1,3])
29
+ self.assertTrue(c.permutation_matrix() == Matrix([[0,-1,0],[1,0,0],[0,0,1]]))
30
+
31
+ if __name__ == '__main__':
32
+ unittest.main()
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env python
2
+
3
+ # Codac tests
4
+ # ----------------------------------------------------------------------------
5
+ # \date 2024
6
+ # \author Simon Rohou
7
+ # \copyright Copyright 2024 Codac Team
8
+ # \license GNU Lesser General Public License (LGPL)
9
+
10
+ import unittest
11
+ from codac import *
12
+
13
+ class TestPolygon(unittest.TestCase):
14
+
15
+ def tests_polygon_base(self):
16
+
17
+ p1 = Polygon([[3,4]])
18
+ self.assertTrue(p1 == Polygon([[3,4]]))
19
+
20
+ p2 = Polygon([[3,4],[1,2]])
21
+ self.assertTrue(p2 == Polygon([[3,4],[1,2]]))
22
+ self.assertTrue(p2 == Polygon([[1,2],[3,4]]))
23
+
24
+ p3 = Polygon([[3,4],[1,2],[5,1]])
25
+ self.assertTrue(p3 == Polygon([[3,4],[1,2],[5,1]]))
26
+ self.assertTrue(p3 == Polygon([[1,2],[5,1],[3,4]]))
27
+ self.assertTrue(p3 == Polygon([[5,1],[1,2],[3,4]]))
28
+ self.assertTrue(p3 == Polygon([[1,2],[3,4],[5,1]]))
29
+
30
+ def tests_empty_polygon(self):
31
+
32
+ p1 = Polygon.empty()
33
+ self.assertTrue(p1.contains(IntervalVector([1,1])) == BoolInterval.FALSE)
34
+ self.assertTrue(p1.contains(IntervalVector(2)) == BoolInterval.FALSE)
35
+ self.assertTrue(p1.is_empty())
36
+ self.assertTrue(len(p1.edges()) == 0)
37
+ self.assertTrue(len(p1.unsorted_vertices()) == 0)
38
+ self.assertTrue(len(p1.sorted_vertices()) == 0)
39
+
40
+ def tests_Polygon(self):
41
+
42
+ p1 = Polygon([[3,-1],[3,4],[5,6],[-1,1]])
43
+ self.assertTrue(p1.contains([3.1,3]) == BoolInterval.FALSE)
44
+ self.assertTrue(p1.contains([2.9,3]) == BoolInterval.TRUE)
45
+ self.assertTrue(p1.contains([3,3]) == BoolInterval.TRUE)
46
+ self.assertTrue(p1.contains([0,1]) == BoolInterval.TRUE)
47
+ self.assertTrue(p1.contains([4,1]) == BoolInterval.FALSE)
48
+ self.assertTrue(p1.contains([2,4]) == BoolInterval.FALSE)
49
+ self.assertTrue(p1.contains([2.8,4]) == BoolInterval.TRUE)
50
+ self.assertTrue(p1.contains([3,4]) == BoolInterval.TRUE)
51
+ self.assertTrue(p1.contains([4,4]) == BoolInterval.FALSE)
52
+ self.assertTrue(p1.contains([5,6]) == BoolInterval.TRUE)
53
+ self.assertTrue(p1.contains([6,6]) == BoolInterval.FALSE)
54
+
55
+ transect = Segment(Vector([next_float(-oo),3]), Vector([3,3]))
56
+ e1,e2 = Segment(Vector([5,6]),Vector([-1,1])), Segment(Vector([3,-1]),Vector([3,4]))
57
+ self.assertTrue(transect.intersects(e1) == BoolInterval.TRUE)
58
+ self.assertTrue(transect.intersects(e2) == BoolInterval.TRUE)
59
+
60
+ p2 = Polygon([[0,0],[0,1],[1,1],[1,0]])
61
+ self.assertTrue(p2.contains([0,0]) == BoolInterval.TRUE)
62
+ self.assertTrue(p2.contains([1,1]) == BoolInterval.TRUE)
63
+ self.assertTrue(p2.contains([0,2]) == BoolInterval.FALSE)
64
+ self.assertTrue(p2.contains([2,0]) == BoolInterval.FALSE)
65
+ self.assertTrue(p2.contains([0.5,1]) == BoolInterval.TRUE)
66
+ self.assertTrue(p2.contains([1,0.5]) == BoolInterval.TRUE)
67
+
68
+ transect = Segment(Vector([next_float(-oo),2]), Vector([0,2]))
69
+ e1 = Segment(Vector([0,0]),Vector([0,1]))
70
+ e2 = Segment(Vector([0,1]),Vector([1,1]))
71
+ e3 = Segment(Vector([1,1]),Vector([1,0]))
72
+ e4 = Segment(Vector([1,0]),Vector([0,0]))
73
+
74
+ self.assertTrue(transect.intersects(e1) == BoolInterval.FALSE)
75
+ self.assertTrue(transect.intersects(e2) == BoolInterval.FALSE)
76
+ self.assertTrue(transect.intersects(e3) == BoolInterval.FALSE)
77
+ self.assertTrue(transect.intersects(e4) == BoolInterval.FALSE)
78
+
79
+ p3 = Polygon([[0,1],[1,0],[0,0]])
80
+ self.assertTrue(p3.contains([1,1]) == BoolInterval.FALSE)
81
+
82
+ def tests_Polygon_degenerated_cases(self):
83
+
84
+ p1 = Polygon([[1,1]])
85
+ self.assertTrue(p1.contains(IntervalVector([1,1])) == BoolInterval.TRUE)
86
+ self.assertTrue(p1.contains(IntervalVector([2,1])) == BoolInterval.FALSE)
87
+ self.assertTrue(p1.contains(IntervalVector([2,2])) == BoolInterval.FALSE)
88
+ self.assertTrue(p1.contains(IntervalVector([1,2])) == BoolInterval.FALSE)
89
+ self.assertTrue(p1.contains(IntervalVector([-10,1])) == BoolInterval.FALSE)
90
+ self.assertTrue(p1.contains(IntervalVector([10,1])) == BoolInterval.FALSE)
91
+
92
+ p2 = Polygon([[1,1],[3,2]])
93
+ self.assertTrue(p2.contains(IntervalVector([1,1])) == BoolInterval.TRUE)
94
+ self.assertTrue(p2.contains(IntervalVector([3,2])) == BoolInterval.TRUE)
95
+ self.assertTrue(p2.contains(IntervalVector([2,1.5])) == BoolInterval.TRUE)
96
+
97
+ p3 = Polygon([[1,1],[3,1]])
98
+ self.assertTrue(p3.contains(IntervalVector([1,1])) == BoolInterval.TRUE)
99
+ self.assertTrue(p3.contains(IntervalVector([3,1])) == BoolInterval.TRUE)
100
+ self.assertTrue(p3.contains(IntervalVector([2,1])) == BoolInterval.TRUE)
101
+
102
+ p4 = Polygon([[1,1],[1,3]])
103
+ self.assertTrue(p4.contains(IntervalVector([1,1])) == BoolInterval.TRUE)
104
+ self.assertTrue(p4.contains(IntervalVector([1,3])) == BoolInterval.TRUE)
105
+ self.assertTrue(p4.contains(IntervalVector([1,2])) == BoolInterval.TRUE)
106
+
107
+ if __name__ == '__main__':
108
+ unittest.main()
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env python
2
+
3
+ # Codac tests
4
+ # ----------------------------------------------------------------------------
5
+ # \date 2024
6
+ # \author Simon Rohou
7
+ # \copyright Copyright 2024 Codac Team
8
+ # \license GNU Lesser General Public License (LGPL)
9
+
10
+ import unittest
11
+ from codac import *
12
+ import sys, math
13
+
14
+ class TestSampledTraj(unittest.TestCase):
15
+
16
+ def tests_SampledTraj(self):
17
+
18
+ x = SampledVectorTraj({
19
+ 0.25: [-0.5,0.5],
20
+ 1.: [0,0],
21
+ 2.: [1,0],
22
+ 3.: [1,1],
23
+ 4.: [-1,1],
24
+ 5.: [-1,-1],
25
+ 6.: [2,-1]
26
+ })
27
+
28
+ self.assertTrue(x.tdomain() == Interval(0.25,6))
29
+ self.assertTrue(x.size() == 2)
30
+ self.assertTrue(x.nb_samples() == 7)
31
+ self.assertTrue(not x.is_empty())
32
+ self.assertTrue(x.codomain() == IntervalVector([[-1,2],[-1,1]]))
33
+ self.assertTrue(x(0.25) == Vector([-0.5,0.5]))
34
+ self.assertTrue(x(1.) == Vector([0,0]))
35
+ self.assertTrue(x(6.) == Vector([2,-1]))
36
+ # Interpolations:
37
+ self.assertTrue(Approx(x(0.75)) == Vector([-1/6.,1/6.]))
38
+ self.assertTrue(x(1.5) == Vector([0.5,0]))
39
+ self.assertTrue(x(5.5) == Vector([0.5,-1]))
40
+ self.assertTrue(x(Interval(1,4)) == IntervalVector([[-1,1],[0,1]]))
41
+
42
+ x_sampled = x.sampled(0.1)
43
+ self.assertTrue(x_sampled.tdomain() == Interval(0.25,6))
44
+ self.assertTrue(x_sampled.size() == 2)
45
+ self.assertTrue(x_sampled.nb_samples() > 5*x.nb_samples()) # approx
46
+ self.assertTrue(not x_sampled.is_empty())
47
+ self.assertTrue(x_sampled.codomain() == IntervalVector([[-1,2],[-1,1]]))
48
+ self.assertTrue(x_sampled(0.25) == Vector([-0.5,0.5]))
49
+ self.assertTrue(x_sampled(1.) == Vector([0,0]))
50
+ self.assertTrue(x_sampled(6.) == Vector([2,-1]))
51
+ # Interpolations:
52
+ self.assertTrue(Approx(x_sampled(0.75)) == Vector([-1/6.,1/6.]))
53
+ self.assertTrue(Approx(x_sampled(1.5)) == Vector([0.5,0]))
54
+ self.assertTrue(Approx(x_sampled(5.5)) == Vector([0.5,-1]))
55
+ self.assertTrue(x_sampled(Interval(1,4)) == IntervalVector([[-1,1],[0,1]]))
56
+
57
+ #DefaultFigure.set_window_properties([75,75],[700,700])
58
+ #DefaultFigure.draw_trajectory(x, Color.blue())
59
+ #DefaultFigure.draw_trajectory(x_sampled, Color.red())
60
+
61
+ # SampledTraj as operator (1d case)
62
+
63
+ t = ScalarVar()
64
+ f = AnalyticFunction(
65
+ [t], cos(t)
66
+ )
67
+ analytic_traj = AnalyticTraj(f, [-math.pi,math.pi])
68
+ sampled_traj = analytic_traj.sampled(1e-2)
69
+ g = sampled_traj.as_function()
70
+
71
+ h = AnalyticFunction(
72
+ [t], g(t)
73
+ )
74
+
75
+ t_ = -math.pi
76
+ while t_ < math.pi:
77
+ self.assertTrue(Approx(h.real_eval(t_),1e-8) == math.cos(t_))
78
+ t_=t_+1e-2
79
+
80
+ # SampledTraj as operator (nd case)
81
+
82
+ t = ScalarVar()
83
+ f = AnalyticFunction(
84
+ [t],
85
+ vec(2*cos(t),sin(2*t))
86
+ )
87
+
88
+ analytic_traj = AnalyticTraj(f, [0,5])
89
+ sampled_traj = analytic_traj.sampled(1e-2)
90
+ g = sampled_traj.as_function()
91
+
92
+ h = AnalyticFunction(
93
+ [t],
94
+ g(t)
95
+ )
96
+
97
+ t_ = 0
98
+ while t_ < 5:
99
+ self.assertTrue(Approx(h.real_eval(t_),1e-8) == Vector([2*math.cos(t_),math.sin(2*t_)]))
100
+ t_=t_+1e-2
101
+
102
+ h = AnalyticFunction(
103
+ [t],
104
+ [ g(t)[0],g(t)[1] ]
105
+ )
106
+
107
+ t_ = 0
108
+ while t_ < 5:
109
+ self.assertTrue(Approx(h.real_eval(t_),1e-8) == Vector([2*math.cos(t_),math.sin(2*t_)]))
110
+ t_=t_+1e-2
111
+
112
+ if __name__ == '__main__':
113
+ unittest.main()