codac4matlab 2.0.0.dev25__cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.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.
- codac4matlab/__init__.py +4 -0
- codac4matlab/_core.cpython-314-aarch64-linux-gnu.so +0 -0
- codac4matlab/_graphics.cpython-314-aarch64-linux-gnu.so +0 -0
- codac4matlab/_unsupported.cpython-314-aarch64-linux-gnu.so +0 -0
- codac4matlab/core/__init__.py +588 -0
- codac4matlab/empty.cpython-314-aarch64-linux-gnu.so +0 -0
- codac4matlab/graphics/__init__.py +1 -0
- codac4matlab/tests/__init__.py +1 -0
- codac4matlab/tests/test_AnalyticFunction.py +442 -0
- codac4matlab/tests/test_AnalyticTraj.py +62 -0
- codac4matlab/tests/test_Approx.py +27 -0
- codac4matlab/tests/test_BoolInterval.py +96 -0
- codac4matlab/tests/test_Color.py +77 -0
- codac4matlab/tests/test_ConvexPolygon.py +300 -0
- codac4matlab/tests/test_CtcAction.py +30 -0
- codac4matlab/tests/test_CtcCartProd.py +39 -0
- codac4matlab/tests/test_CtcCtcBoundary.py +48 -0
- codac4matlab/tests/test_CtcDeriv.py +434 -0
- codac4matlab/tests/test_CtcEval.py +214 -0
- codac4matlab/tests/test_CtcFixpoint.py +65 -0
- codac4matlab/tests/test_CtcInter.py +39 -0
- codac4matlab/tests/test_CtcInverse.py +213 -0
- codac4matlab/tests/test_CtcInverseNotIn.py +129 -0
- codac4matlab/tests/test_CtcLazy.py +50 -0
- codac4matlab/tests/test_CtcPolygon.py +91 -0
- codac4matlab/tests/test_CtcSegment.py +104 -0
- codac4matlab/tests/test_Ellipsoid.py +20 -0
- codac4matlab/tests/test_GaussJordan.py +34 -0
- codac4matlab/tests/test_IntFullPivLU.py +84 -0
- codac4matlab/tests/test_Interval.py +254 -0
- codac4matlab/tests/test_IntervalMatrix.py +664 -0
- codac4matlab/tests/test_IntervalVector.py +657 -0
- codac4matlab/tests/test_Interval_operations.py +293 -0
- codac4matlab/tests/test_Matrix.py +81 -0
- codac4matlab/tests/test_OctaSym.py +41 -0
- codac4matlab/tests/test_Parallelepiped.py +35 -0
- codac4matlab/tests/test_Parallelepiped_eval.py +62 -0
- codac4matlab/tests/test_Polygon.py +120 -0
- codac4matlab/tests/test_SampledTraj.py +135 -0
- codac4matlab/tests/test_Segment.py +138 -0
- codac4matlab/tests/test_SepCartProd.py +34 -0
- codac4matlab/tests/test_SepCtcBoundary.py +52 -0
- codac4matlab/tests/test_SepInverse.py +104 -0
- codac4matlab/tests/test_SepPolygon.py +102 -0
- codac4matlab/tests/test_SepProj.py +39 -0
- codac4matlab/tests/test_SepTransform.py +41 -0
- codac4matlab/tests/test_Slice.py +78 -0
- codac4matlab/tests/test_Slice_polygon.py +208 -0
- codac4matlab/tests/test_SlicedTube.py +562 -0
- codac4matlab/tests/test_SlicedTube_integral.py +380 -0
- codac4matlab/tests/test_TDomain.py +115 -0
- codac4matlab/tests/test_Vector.py +41 -0
- codac4matlab/tests/test_arithmetic_add.py +54 -0
- codac4matlab/tests/test_arithmetic_div.py +46 -0
- codac4matlab/tests/test_arithmetic_mul.py +114 -0
- codac4matlab/tests/test_arithmetic_sub.py +54 -0
- codac4matlab/tests/test_capd.py +19 -0
- codac4matlab/tests/test_cart_prod.py +38 -0
- codac4matlab/tests/test_eigen.py +19 -0
- codac4matlab/tests/test_geometry.py +136 -0
- codac4matlab/tests/test_hull.py +35 -0
- codac4matlab/tests/test_ibex.py +19 -0
- codac4matlab/tests/test_inversion.py +57 -0
- codac4matlab/tests/test_linear_ctc.py +77 -0
- codac4matlab/tests/test_operators.py +377 -0
- codac4matlab/tests/test_peibos.py +83 -0
- codac4matlab/tests/test_predefined_tubes.py +193 -0
- codac4matlab/tests/test_serialization.py +30 -0
- codac4matlab/tests/test_transformations.py +61 -0
- codac4matlab/tests/test_trunc.py +95 -0
- codac4matlab/unsupported/__init__.py +1 -0
- codac4matlab/version.py +1 -0
- codac4matlab-2.0.0.dev25.dist-info/METADATA +23 -0
- codac4matlab-2.0.0.dev25.dist-info/RECORD +76 -0
- codac4matlab-2.0.0.dev25.dist-info/WHEEL +6 -0
- codac4matlab-2.0.0.dev25.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2024
|
|
6
|
+
# \author Simon Rohou, Damien Massé
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
import sys, os
|
|
11
|
+
import unittest
|
|
12
|
+
import math
|
|
13
|
+
from codac import *
|
|
14
|
+
|
|
15
|
+
def create_f():
|
|
16
|
+
x = ScalarVar()
|
|
17
|
+
return AnalyticFunction([x], x*cos(x))
|
|
18
|
+
|
|
19
|
+
class TestAnalyticFunction(unittest.TestCase):
|
|
20
|
+
|
|
21
|
+
def test_AnalyticFunction(self):
|
|
22
|
+
|
|
23
|
+
def invalid_function():
|
|
24
|
+
x = ScalarVar()
|
|
25
|
+
f = AnalyticFunction([3], cos(x))
|
|
26
|
+
|
|
27
|
+
self.assertRaises(ValueError, invalid_function)
|
|
28
|
+
|
|
29
|
+
x = ScalarVar()
|
|
30
|
+
self.assertTrue(x.size() == 1)
|
|
31
|
+
|
|
32
|
+
y = VectorVar(3)
|
|
33
|
+
self.assertTrue(y.size() == 3)
|
|
34
|
+
self.assertTrue(type(y[0]) == ScalarExpr)
|
|
35
|
+
self.assertTrue(type(y[2]) == ScalarExpr)
|
|
36
|
+
|
|
37
|
+
for i in range(0,2):
|
|
38
|
+
|
|
39
|
+
def test_eval(i,f,*args):
|
|
40
|
+
|
|
41
|
+
if(i == 0): # natural
|
|
42
|
+
return f.eval(EvalMode.NATURAL,*args)
|
|
43
|
+
|
|
44
|
+
elif(i == 1): # centered
|
|
45
|
+
return f.eval(EvalMode.CENTERED,*args)
|
|
46
|
+
|
|
47
|
+
else: # centered and natural
|
|
48
|
+
return f.eval(*args)
|
|
49
|
+
|
|
50
|
+
f = AnalyticFunction([x], x)
|
|
51
|
+
self.assertTrue(Approx(test_eval(i,f,Interval(0))) == 0)
|
|
52
|
+
f = AnalyticFunction([x], x+Interval(2))
|
|
53
|
+
self.assertTrue(Approx(test_eval(i,f,Interval(3))) == 5)
|
|
54
|
+
f = AnalyticFunction([x], x+x)
|
|
55
|
+
self.assertTrue(Approx(test_eval(i,f,Interval(2))) == 4)
|
|
56
|
+
f = AnalyticFunction([x], x+x+2)
|
|
57
|
+
self.assertTrue(Approx(test_eval(i,f,Interval(2))) == 6)
|
|
58
|
+
f = AnalyticFunction([x], pow(x,2))
|
|
59
|
+
self.assertTrue(Approx(test_eval(i,f,Interval(3))) == 9)
|
|
60
|
+
f = AnalyticFunction([x], x^2)
|
|
61
|
+
self.assertTrue(Approx(test_eval(i,f,Interval(3))) == 9)
|
|
62
|
+
f = AnalyticFunction([x], (0.+x)^(1.*x))
|
|
63
|
+
self.assertTrue(Approx(test_eval(i,f,Interval(3))) == 27)
|
|
64
|
+
f = AnalyticFunction([x], x**2)
|
|
65
|
+
self.assertTrue(Approx(test_eval(i,f,Interval(3))) == 9)
|
|
66
|
+
f = AnalyticFunction([x], (0.+x)**(1.*x))
|
|
67
|
+
self.assertTrue(Approx(test_eval(i,f,Interval(3))) == 27)
|
|
68
|
+
f = AnalyticFunction([x], cos(x))
|
|
69
|
+
self.assertTrue(Approx(test_eval(i,f,Interval(0))) == 1)
|
|
70
|
+
|
|
71
|
+
f = AnalyticFunction([x], [x,x])
|
|
72
|
+
|
|
73
|
+
fvec = AnalyticFunction([x], [x,x])
|
|
74
|
+
self.assertTrue(Approx(test_eval(i,f,1)) == IntervalVector([[1],[1]]))
|
|
75
|
+
|
|
76
|
+
self.assertTrue(test_eval(i,AnalyticFunction([], +4)) == 4)
|
|
77
|
+
self.assertTrue(test_eval(i,AnalyticFunction([], +4.)) == 4.)
|
|
78
|
+
self.assertTrue(test_eval(i,AnalyticFunction([], +Interval(4,5))) == Interval(4,5))
|
|
79
|
+
self.assertTrue(test_eval(i,AnalyticFunction([], Vector([2,9]))) == Vector([2,9]))
|
|
80
|
+
self.assertTrue(test_eval(i,AnalyticFunction([], IntervalVector(3))) == IntervalVector([[-oo,oo],[-oo,oo],[-oo,oo]]))
|
|
81
|
+
|
|
82
|
+
x1 = ScalarVar()
|
|
83
|
+
x2 = ScalarVar()
|
|
84
|
+
v1 = VectorVar(2)
|
|
85
|
+
v2 = VectorVar(2)
|
|
86
|
+
|
|
87
|
+
# ======> ScalarVar
|
|
88
|
+
|
|
89
|
+
# .def("__pos__", [](const ScalarVar& e1)
|
|
90
|
+
self.assertTrue(test_eval(i,AnalyticFunction([x1], +x1), 5.) == 5.)
|
|
91
|
+
# .def("__add__", [](const ScalarVar& e1, const ScalarVar& e2)
|
|
92
|
+
self.assertTrue(test_eval(i,AnalyticFunction([x1,x2], x1+x2), 5.,6.) == 11.)
|
|
93
|
+
# .def("__add__", [](const ScalarVar& e1, const Interval& e2)
|
|
94
|
+
self.assertTrue(test_eval(i,AnalyticFunction([x1], x1+Interval(3)), 5.) == 8.)
|
|
95
|
+
# .def("__radd__", [](const ScalarVar& e1, const Interval& e2)
|
|
96
|
+
self.assertTrue(test_eval(i,AnalyticFunction([x1], Interval(3)+x1), 5.) == 8.)
|
|
97
|
+
# .def("__neg__", [](const ScalarVar& e1)
|
|
98
|
+
self.assertTrue(test_eval(i,AnalyticFunction([x2], -x2), 6.) == -6.)
|
|
99
|
+
# .def("__sub__", [](const ScalarVar& e1, const ScalarVar& e2)
|
|
100
|
+
self.assertTrue(test_eval(i,AnalyticFunction([x1,x2], x1-x2), 5.,6.) == -1.)
|
|
101
|
+
# .def("__sub__", [](const ScalarVar& e1, const Interval& e2)
|
|
102
|
+
self.assertTrue(test_eval(i,AnalyticFunction([x1], x1-Interval(2.)), 5.) == 3.)
|
|
103
|
+
# .def("__rsub__", [](const ScalarVar& e1, const Interval& e2)
|
|
104
|
+
self.assertTrue(test_eval(i,AnalyticFunction([x1], Interval(2.)-x1), 5.) == -3.)
|
|
105
|
+
# .def("__mul__", [](const ScalarVar& e1, const ScalarVar& e2)
|
|
106
|
+
self.assertTrue(test_eval(i,AnalyticFunction([x1,x2], x1*x2), 5.,6.) == 30.)
|
|
107
|
+
# .def("__mul__", [](const ScalarVar& e1, const Interval& e2)
|
|
108
|
+
self.assertTrue(test_eval(i,AnalyticFunction([x1], x1*Interval(6.)), 5.) == 30.)
|
|
109
|
+
# .def("__rmul__", [](const ScalarVar& e1, const Interval& e2)
|
|
110
|
+
self.assertTrue(test_eval(i,AnalyticFunction([x1], Interval(6.)*x1), 5.) == 30.)
|
|
111
|
+
# .def("__mul__", [](const ScalarVar& e1, const VectorVar& e2)
|
|
112
|
+
self.assertTrue(test_eval(i,AnalyticFunction([v1,v2], v1[0]*v2), Vector([5.,10.]),IntervalVector([[3],[3]])) == Vector([15,15]))
|
|
113
|
+
# .def("__mul__", [](const ScalarVar& e1, const IntervalVector& e2)
|
|
114
|
+
self.assertTrue(test_eval(i,AnalyticFunction([x1], x1*IntervalVector([[-2,3],[0,1]])), 5.) == IntervalVector([[-10,15],[0,5]]))
|
|
115
|
+
# .def("__truediv__", [](const ScalarVar& e1, const ScalarVar& e2)
|
|
116
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1,x2], x1/x2), 1.,10.)) == 0.1)
|
|
117
|
+
# .def("__truediv__", [](const ScalarVar& e1, const Interval& e2)
|
|
118
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], x1/Interval(10)), 1.)) == 0.1)
|
|
119
|
+
# .def("__rtruediv__", [](const ScalarVar& e1, const Interval& e2)
|
|
120
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], Interval(2.)/x1), 10.)) == 0.2)
|
|
121
|
+
|
|
122
|
+
# ======> VectorVar
|
|
123
|
+
|
|
124
|
+
#.def("__pos__", [](const VectorVar& e1)
|
|
125
|
+
self.assertTrue(test_eval(i,AnalyticFunction([v1], +v1), Vector([5.,6.])) == Vector([5.,6.]))
|
|
126
|
+
#.def("__add__", [](const VectorVar& e1, const VectorVar& e2)
|
|
127
|
+
self.assertTrue(test_eval(i,AnalyticFunction([v1,v2], v1+v2), Vector([5.,6.]),Vector([2.,3.])) == Vector([7.,9.]))
|
|
128
|
+
#.def("__add__", [](const VectorVar& e1, const IntervalVector& e2)
|
|
129
|
+
self.assertTrue(test_eval(i,AnalyticFunction([v1], v1+IntervalVector([[2],[3]])), Vector([5.,6.])) == IntervalVector([[7.],[9.]]))
|
|
130
|
+
#.def("__radd__", [](const VectorVar& e1, const IntervalVector& e2)
|
|
131
|
+
self.assertTrue(test_eval(i,AnalyticFunction([v1], IntervalVector([[2],[3]])+v1), Vector([5.,6.])) == IntervalVector([[7.],[9.]]))
|
|
132
|
+
#.def("__neg__", [](const VectorVar& e1)
|
|
133
|
+
self.assertTrue(test_eval(i,AnalyticFunction([v1], -v1), Vector([5.,6.])) == -Vector([5.,6.]))
|
|
134
|
+
#.def("__sub__", [](const VectorVar& e1, const VectorVar& e2)
|
|
135
|
+
self.assertTrue(test_eval(i,AnalyticFunction([v1,v2], v1-v2), Vector([5.,6.]),Vector([2.,3.])) == Vector([3.,3.]))
|
|
136
|
+
#.def("__sub__", [](const VectorVar& e1, const IntervalVector& e2)
|
|
137
|
+
self.assertTrue(test_eval(i,AnalyticFunction([v1], v1-IntervalVector([[2],[3]])), Vector([5.,6.])) == IntervalVector([[3.],[3.]]))
|
|
138
|
+
#.def("__rsub__", [](const VectorVar& e1, const IntervalVector& e2)
|
|
139
|
+
self.assertTrue(test_eval(i,AnalyticFunction([v1], IntervalVector([[2],[3]])-v1), Vector([5.,6.])) == IntervalVector([[-3.],[-3.]]))
|
|
140
|
+
|
|
141
|
+
# ======> ScalarExpr
|
|
142
|
+
|
|
143
|
+
#.def("__pos__", [](const ScalarExpr& e1)
|
|
144
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], +cos(x1)), Interval(0.))) == Interval(1.))
|
|
145
|
+
#.def(py::self + py::self)
|
|
146
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], cos(x1)+cos(x1)), Interval(0.))) == Interval(2.))
|
|
147
|
+
#.def("__add__", [](const ScalarExpr& e1, const ScalarVar& e2)
|
|
148
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], cos(x1)+x1), math.pi)) == math.pi-1)
|
|
149
|
+
#.def("__radd__", [](const ScalarExpr& e1, const ScalarVar& e2)
|
|
150
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], x1+cos(x1)), math.pi)) == math.pi-1)
|
|
151
|
+
#.def("__add__", [](const ScalarExpr& e1, const Interval& e2)
|
|
152
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], cos(x1)+Interval(10.)), math.pi)) == Interval(9))
|
|
153
|
+
#.def("__radd__", [](const ScalarExpr& e1, const Interval& e2)
|
|
154
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], 10+cos(x1)), math.pi)) == Interval(9))
|
|
155
|
+
#.def(- py::self)
|
|
156
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], -cos(x1)), Interval(0.))) == Interval(-1.))
|
|
157
|
+
#.def(py::self - py::self)
|
|
158
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], cos(x1)-cos(x1)), Interval(0.))) == Interval(0.))
|
|
159
|
+
#.def("__sub__", [](const ScalarExpr& e1, const ScalarVar& e2)
|
|
160
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], cos(x1)-x1), math.pi)) == -math.pi-1)
|
|
161
|
+
#.def("__rsub__", [](const ScalarExpr& e1, const ScalarVar& e2)
|
|
162
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], x1-cos(x1)), math.pi)) == math.pi+1)
|
|
163
|
+
#.def("__sub__", [](const ScalarExpr& e1, const Interval& e2)
|
|
164
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], cos(x1)-Interval(10.)), math.pi)) == -Interval(11))
|
|
165
|
+
#.def("__rsub__", [](const ScalarExpr& e1, const Interval& e2)
|
|
166
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], 10-cos(x1)), math.pi)) == Interval(11))
|
|
167
|
+
#.def(py::self * py::self)
|
|
168
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], cos(x1)*cos(x1)), Interval(0.))) == Interval(1.))
|
|
169
|
+
#.def("__mul__", [](const ScalarExpr& e1, const ScalarVar& e2)
|
|
170
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], cos(x1)*x1), math.pi)) == -1*math.pi)
|
|
171
|
+
#.def("__rmul__", [](const ScalarExpr& e1, const ScalarVar& e2)
|
|
172
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], x1*cos(x1)), math.pi)) == -1*math.pi)
|
|
173
|
+
#.def("__mul__", [](const ScalarExpr& e1, const Interval& e2)
|
|
174
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], cos(x1)*Interval(10.)), math.pi),1e-9) == -Interval(10))
|
|
175
|
+
#.def("__rmul__", [](const ScalarExpr& e1, const Interval& e2)
|
|
176
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], Interval(10.)*cos(x1)), math.pi),1e-9) == -10)
|
|
177
|
+
#.def("__mul__", [](const ScalarExpr& e1, const VectorExpr& e2)
|
|
178
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([v1,v2], cos(v1[0])*(v2+v2)), Vector([math.pi,-1]),Vector([2,3])),1e-9) == IntervalVector([[-4],[-6]]))
|
|
179
|
+
#.def("__truediv__", [](const ScalarExpr& e1, const ScalarExpr& e2)
|
|
180
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], cos(x1)/cos(x1)), Interval(0.))) == Interval(1.))
|
|
181
|
+
#.def("__truediv__", [](const ScalarExpr& e1, const ScalarVar& e2)
|
|
182
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], cos(x1)/x1), math.pi)) == -1/math.pi)
|
|
183
|
+
#.def("__rtruediv__", [](const ScalarExpr& e1, const ScalarVar& e2)
|
|
184
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], x1/cos(x1)), math.pi)) == -math.pi)
|
|
185
|
+
#.def("__truediv__", [](const ScalarExpr& e1, const Interval& e2)
|
|
186
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], cos(x1)/Interval(4.)), math.pi)) == -1./4)
|
|
187
|
+
#.def("__rtruediv__", [](const ScalarExpr& e1, const Interval& e2)
|
|
188
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], 4./cos(x1)), math.pi)) == -4)
|
|
189
|
+
|
|
190
|
+
# ======> VectorExpr
|
|
191
|
+
|
|
192
|
+
#.def("__pos__", [](const VectorExpr& e1)
|
|
193
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([v1], +(v1+v1)), IntervalVector([[0.],[-oo,5]]))) ==
|
|
194
|
+
IntervalVector([[0.],[-oo,oo]]) if i==1 else IntervalVector([[0.],[-oo,10]]))
|
|
195
|
+
#.def(py::self + py::self)
|
|
196
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([v1], v1+v1), IntervalVector([[0.],[-oo,5]]))) ==
|
|
197
|
+
IntervalVector([[0.],[-oo,oo]]) if i==1 else IntervalVector([[0.],[-oo,10]]))
|
|
198
|
+
#.def("__radd__", [](const VectorExpr& e1, const VectorVar& e2)
|
|
199
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([v1], (v1+v1)+v1), IntervalVector([[0.],[-oo,5]]))) ==
|
|
200
|
+
IntervalVector([[0.],[-oo,oo]]) if i==1 else IntervalVector([[0.],[-oo,15]]))
|
|
201
|
+
#.def("__radd__", [](const VectorExpr& e1, const IntervalVector& e2)
|
|
202
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([v1], v1+(v1+v1)), IntervalVector([[0.],[-oo,5]]))) ==
|
|
203
|
+
IntervalVector([[0.],[-oo,oo]]) if i==1 else IntervalVector([[0.],[-oo,15]]))
|
|
204
|
+
#.def(- py::self)
|
|
205
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([v1], -(v1+v1)), IntervalVector([[0.],[-oo,5]]))) ==
|
|
206
|
+
-IntervalVector([[0.],[-oo,oo]]) if i==1 else -IntervalVector([[0.],[-oo,10]]))
|
|
207
|
+
#.def(py::self - py::self)
|
|
208
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([v1,v2], (v1-v2)), IntervalVector([[2],[3]]),Vector([1,5]))) == IntervalVector([[1],[-2]]))
|
|
209
|
+
#.def("__sub__", [](const VectorExpr& e1, const VectorVar& e2)
|
|
210
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([v1,v2], (v1-v2)-v1), IntervalVector([[2],[3]]),Vector([1,5]))) == IntervalVector([[-1],[-5]]))
|
|
211
|
+
#.def("__rsub__", [](const VectorExpr& e1, const VectorVar& e2)
|
|
212
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([v1,v2], v2-(v1-v2)), IntervalVector([[2],[3]]),Vector([1,5]))) == IntervalVector([[0],[7]]))
|
|
213
|
+
#.def("__sub__", [](const VectorExpr& e1, const IntervalVector& e2)
|
|
214
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([v1,v2], (v1-v2)-IntervalVector([[2],[3]])), IntervalVector([[2],[3]]),Vector([1,5]))) == IntervalVector([[-1],[-5]]))
|
|
215
|
+
#.def("__rsub__", [](const VectorExpr& e1, const IntervalVector& e2)
|
|
216
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([v1,v2], Vector([1,5])-(v1-v2)), IntervalVector([[2],[3]]),Vector([1,5]))) == IntervalVector([[0],[7]]))
|
|
217
|
+
#.def("__rmul__", [](const VectorExpr& e1, const ScalarExpr& e2)
|
|
218
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([v1,v2], cos(v1[0])*(v2+v2)), Vector([math.pi,-1]),Vector([2,3])),1e-9) == IntervalVector([[-4],[-6]]))
|
|
219
|
+
#.def("__rmul__", [](const VectorExpr& e1, const ScalarVar& e2)
|
|
220
|
+
self.assertTrue(Approx(test_eval(i,AnalyticFunction([x1], x1*vec(3*x1,2*x1)), 3),1e-9) == IntervalVector([[27],[18]]))
|
|
221
|
+
|
|
222
|
+
x = VectorVar(2)
|
|
223
|
+
f = AnalyticFunction([x], x[0]*(x[0]+x[1])+sqr(x[1]))
|
|
224
|
+
self.assertTrue(f.diff(Vector([2,3]))(0,0) == 7)
|
|
225
|
+
self.assertTrue(f.diff(Vector([2,3]))(0,1) == 8)
|
|
226
|
+
|
|
227
|
+
# int values
|
|
228
|
+
x,y = ScalarVar(), ScalarVar()
|
|
229
|
+
f = AnalyticFunction([x,y], x*(x+y)+sqr(y))
|
|
230
|
+
self.assertTrue(f.diff(2,3)(0,0) == 7)
|
|
231
|
+
self.assertTrue(f.diff(2,3)(0,1) == 8)
|
|
232
|
+
|
|
233
|
+
# double values
|
|
234
|
+
x,y = ScalarVar(), ScalarVar()
|
|
235
|
+
f = AnalyticFunction([x,y], x*(x+y)+sqr(y))
|
|
236
|
+
self.assertTrue(f.diff(2.,3.)(0,0) == 7)
|
|
237
|
+
self.assertTrue(f.diff(2.,3.)(0,1) == 8)
|
|
238
|
+
|
|
239
|
+
# Interval values
|
|
240
|
+
x,y = ScalarVar(), ScalarVar()
|
|
241
|
+
f = AnalyticFunction([x,y], x*(x+y)+sqr(y))
|
|
242
|
+
self.assertTrue(f.diff(Interval(2.),Interval(3.))(0,0) == 7)
|
|
243
|
+
self.assertTrue(f.diff(Interval(2.),Interval(3.))(0,1) == 8)
|
|
244
|
+
|
|
245
|
+
# Evaluation modes
|
|
246
|
+
x = ScalarVar()
|
|
247
|
+
f = AnalyticFunction([x], x-x)
|
|
248
|
+
self.assertTrue(f.eval(EvalMode.NATURAL,Interval(-1,1)) == Interval(-2,2))
|
|
249
|
+
self.assertTrue(f.eval(EvalMode.CENTERED,Interval(-1,1)) == Interval(0))
|
|
250
|
+
self.assertTrue(f.eval(Interval(-1,1)) == Interval(0))
|
|
251
|
+
|
|
252
|
+
# Scalar outputs
|
|
253
|
+
f1 = AnalyticFunction([], 3)
|
|
254
|
+
self.assertTrue(f1.eval() == Interval(3))
|
|
255
|
+
f2 = AnalyticFunction([], 3.)
|
|
256
|
+
self.assertTrue(f2.eval() == Interval(3))
|
|
257
|
+
f3 = AnalyticFunction([], Interval(3.))
|
|
258
|
+
self.assertTrue(f3.eval() == Interval(3))
|
|
259
|
+
x = ScalarVar()
|
|
260
|
+
f4 = AnalyticFunction([x], x*x)
|
|
261
|
+
self.assertTrue(f4.eval(2.) == Interval(4))
|
|
262
|
+
|
|
263
|
+
# Vectorial outputs
|
|
264
|
+
|
|
265
|
+
f1 = AnalyticFunction([], [ 3 ])
|
|
266
|
+
self.assertTrue(f1.eval() == IntervalVector([3]))
|
|
267
|
+
f2 = AnalyticFunction([], [ 3. ])
|
|
268
|
+
self.assertTrue(f2.eval() == IntervalVector([3]))
|
|
269
|
+
f3 = AnalyticFunction([], [ Interval(3.) ])
|
|
270
|
+
self.assertTrue(f3.eval() == IntervalVector([3]))
|
|
271
|
+
x = ScalarVar()
|
|
272
|
+
f4 = AnalyticFunction([x], [ x*x ])
|
|
273
|
+
self.assertTrue(f4.eval(2.) == IntervalVector([4]))
|
|
274
|
+
|
|
275
|
+
f_2args = AnalyticFunction([x], [ x*x,x*x ])
|
|
276
|
+
self.assertTrue(f_2args.eval(1.) == IntervalVector.constant(2,[1]))
|
|
277
|
+
f_3args = AnalyticFunction([x], [ x,x*x,1 ])
|
|
278
|
+
self.assertTrue(f_3args.eval(1.) == IntervalVector.constant(3,[1]))
|
|
279
|
+
f_4args = AnalyticFunction([x], [ x,x*x,1,x ])
|
|
280
|
+
self.assertTrue(f_4args.eval(1.) == IntervalVector.constant(4,[1]))
|
|
281
|
+
f_5args = AnalyticFunction([x], [ x,x*x,1,x,x ])
|
|
282
|
+
self.assertTrue(f_5args.eval(1.) == IntervalVector.constant(5,[1]))
|
|
283
|
+
f_6args = AnalyticFunction([x], [ x,x*x,1,x,x,1*x ])
|
|
284
|
+
self.assertTrue(f_6args.eval(1.) == IntervalVector.constant(6,[1]))
|
|
285
|
+
f_7args = AnalyticFunction([x], [ x,x*x,1,x,x,1*x,x*x ])
|
|
286
|
+
self.assertTrue(f_7args.eval(1.) == IntervalVector.constant(7,[1]))
|
|
287
|
+
f_8args = AnalyticFunction([x], [ x,x*x,1,x,x,1*x,x*x,1 ])
|
|
288
|
+
self.assertTrue(f_8args.eval(1.) == IntervalVector.constant(8,[1]))
|
|
289
|
+
f_9args = AnalyticFunction([x], [ x,x*x,1,x,x,1*x,x*x,1,x ])
|
|
290
|
+
self.assertTrue(f_9args.eval(1.) == IntervalVector.constant(9,[1]))
|
|
291
|
+
f_10args = AnalyticFunction([x], [ x,x*x,1,x,x,1*x,x*x,1,x,1*x ])
|
|
292
|
+
self.assertTrue(f_10args.eval(1.) == IntervalVector.constant(10,[1]))
|
|
293
|
+
|
|
294
|
+
# Subvector on variables
|
|
295
|
+
p = VectorVar(2)
|
|
296
|
+
x = VectorVar(4)
|
|
297
|
+
f = AnalyticFunction([p], p[0]*p[1])
|
|
298
|
+
g = AnalyticFunction([x], f(x.subvector(0,1)) + f(x.subvector(2,3)))
|
|
299
|
+
|
|
300
|
+
a = IntervalVector(4)
|
|
301
|
+
|
|
302
|
+
a = IntervalVector([[1],[2],[3],[4]])
|
|
303
|
+
self.assertTrue(g.eval(EvalMode.NATURAL,a) == 14)
|
|
304
|
+
self.assertTrue(g.eval(EvalMode.CENTERED,a) == 14)
|
|
305
|
+
self.assertTrue(g.eval(a) == 14)
|
|
306
|
+
|
|
307
|
+
a = IntervalVector([[0],[2],[5],[4]])
|
|
308
|
+
self.assertTrue(g.eval(EvalMode.NATURAL,a) == 20)
|
|
309
|
+
self.assertTrue(g.eval(EvalMode.CENTERED,a) == 20)
|
|
310
|
+
self.assertTrue(g.eval(a) == 20)
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
# Sign, floor, ceil, min, max
|
|
314
|
+
x1 = ScalarVar()
|
|
315
|
+
x2 = ScalarVar()
|
|
316
|
+
|
|
317
|
+
f = AnalyticFunction([x1,x2], 2*max(x1,x2+1))
|
|
318
|
+
self.assertTrue(f.eval(0.,1.) == 4.)
|
|
319
|
+
self.assertTrue(f.eval(2.,1.) == 4.)
|
|
320
|
+
self.assertTrue(f.eval(3.,1.) == 6.)
|
|
321
|
+
|
|
322
|
+
f = AnalyticFunction([x1,x2], 2*min(x1,x2+1))
|
|
323
|
+
self.assertTrue(f.eval(0.,1.) == 0.)
|
|
324
|
+
self.assertTrue(f.eval(2.,1.) == 4.)
|
|
325
|
+
self.assertTrue(f.eval(3.,1.) == 4.)
|
|
326
|
+
|
|
327
|
+
f = AnalyticFunction([x1], 2*sign(x1+1))
|
|
328
|
+
self.assertTrue(f.eval(0.) == 2.)
|
|
329
|
+
self.assertTrue(sign(Interval.zero()) == Interval(-1,1))
|
|
330
|
+
self.assertTrue(sign(Interval(-0,0)) == Interval(-1,1))
|
|
331
|
+
self.assertTrue(f.eval(-1.) == Interval(-2,2))
|
|
332
|
+
self.assertTrue(f.eval(-2.) == -2.)
|
|
333
|
+
|
|
334
|
+
f = AnalyticFunction([x1], 2*floor(x1))
|
|
335
|
+
self.assertTrue(f.eval(0.) == 0.)
|
|
336
|
+
self.assertTrue(f.eval(1.5) == 2.)
|
|
337
|
+
self.assertTrue(f.eval(-1.5) == -4.)
|
|
338
|
+
|
|
339
|
+
f = AnalyticFunction([x1], 2*ceil(x1))
|
|
340
|
+
self.assertTrue(f.eval(0.) == 0.)
|
|
341
|
+
self.assertTrue(f.eval(1.5) == 4.)
|
|
342
|
+
self.assertTrue(f.eval(-1.5) == -2.)
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
# Issue #201
|
|
346
|
+
# Input argument is a py::list instead of a Vector
|
|
347
|
+
x1 = VectorVar(2)
|
|
348
|
+
f = AnalyticFunction([x1], 2.*x1)
|
|
349
|
+
self.assertTrue(f.eval([2,3]) == IntervalVector([[4],[6]]))
|
|
350
|
+
self.assertTrue(f.eval([[2,3],[4,5]]) == IntervalVector([[4,6],[8,10]]))
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
I = Matrix([[0,2],[-1,0]])
|
|
354
|
+
x = VectorVar(2)
|
|
355
|
+
f = AnalyticFunction([x], I*x)
|
|
356
|
+
self.assertTrue(f.eval(IntervalVector([[0,1],[2,3]])) == IntervalVector([[4,6],[-1,0]]))
|
|
357
|
+
|
|
358
|
+
I = Matrix([[1,0],[0,1]])
|
|
359
|
+
x = VectorVar(2)
|
|
360
|
+
f = AnalyticFunction([x], I*I*x)
|
|
361
|
+
self.assertTrue(f.eval(IntervalVector([[-1,1],[2,3]])) == IntervalVector([[-1,1],[2,3]]))
|
|
362
|
+
|
|
363
|
+
A = MatrixVar(2,2)
|
|
364
|
+
x = VectorVar(2)
|
|
365
|
+
h = AnalyticFunction([A], A*A)
|
|
366
|
+
f = AnalyticFunction([x,A], h(A)*x)
|
|
367
|
+
g = AnalyticFunction([x], f(x,Matrix([[0,2],[-1,0]])))
|
|
368
|
+
self.assertTrue(g.eval(IntervalVector([[-1,1],[2,3]])) == IntervalVector([[-2,2],[-6,-4]]))
|
|
369
|
+
|
|
370
|
+
A = MatrixVar(2,2)
|
|
371
|
+
f_det = AnalyticFunction([A], A(0,0)*A(1,1)-A(1,0)*A(0,1))
|
|
372
|
+
self.assertTrue(f_det.eval(Matrix([[1,2],[3,4]])) == -2)
|
|
373
|
+
self.assertTrue(f_det.eval(IntervalMatrix([[[0,1],[1,2]],[[2,3],[3,4]]])) == Interval(-6,2))
|
|
374
|
+
|
|
375
|
+
f = create_f()
|
|
376
|
+
self.assertTrue(Approx(f.eval(PI)) == -PI)
|
|
377
|
+
|
|
378
|
+
x = ScalarVar()
|
|
379
|
+
f = AnalyticFunction([x],sqrt(x))
|
|
380
|
+
self.assertTrue(Interval(0.).is_subset([0,oo]))
|
|
381
|
+
self.assertTrue(Interval(0.,10.).is_subset([0,oo]))
|
|
382
|
+
self.assertTrue(Approx(f.eval(EvalMode.NATURAL, 0.)) == 0.)
|
|
383
|
+
self.assertTrue(Approx(f.eval(EvalMode.NATURAL, 1e-10),1e-3) == 0.)
|
|
384
|
+
# Cannot compute in pure centered form due to the
|
|
385
|
+
# definition domain of the derivative of sqrt:
|
|
386
|
+
self.assertTrue(f.eval(EvalMode.CENTERED, 0.).is_empty())
|
|
387
|
+
self.assertTrue(Approx(f.eval(EvalMode.CENTERED, 1e-10),1e-3) == 0.)
|
|
388
|
+
self.assertTrue(Approx(f.eval(0.)) == 0.)
|
|
389
|
+
self.assertTrue(Approx(f.eval(1e-10),1e-3) == 0.)
|
|
390
|
+
|
|
391
|
+
x1,x2,x3 = VectorVar(2),VectorVar(2),VectorVar(2)
|
|
392
|
+
f = AnalyticFunction([x1,x2,x3], mat(+x1,-x2,2*x3))
|
|
393
|
+
self.assertTrue(f.eval(EvalMode.NATURAL, Vector([1,2]),Vector([-1,8]),IntervalVector([[-1,1],[2,oo]]))
|
|
394
|
+
== IntervalMatrix([[1,1,[-2,2]],[2,-8,[4,oo]]]))
|
|
395
|
+
|
|
396
|
+
x1 = VectorVar(2)
|
|
397
|
+
f = AnalyticFunction([x1],det(mat(+x1,2*x1)))
|
|
398
|
+
self.assertTrue(Approx(f.eval(EvalMode.NATURAL, IntervalVector([[0.9,1.1],[0.4,0.5]])),1e-9) == Interval(-0.38,0.38))
|
|
399
|
+
self.assertTrue(Approx(f.eval(EvalMode.CENTERED, IntervalVector([[0.9,1.1],[0.4,0.5]])),1e-9) == Interval(-0.04,0.04))
|
|
400
|
+
|
|
401
|
+
M1 = MatrixVar(2,3)
|
|
402
|
+
M2 = MatrixVar(3,2)
|
|
403
|
+
f = AnalyticFunction([M1,M2], M1*M2-M1*M2)
|
|
404
|
+
self.assertTrue(Approx(f.eval(EvalMode.NATURAL,
|
|
405
|
+
Matrix([[1,0,1],[0,1,0]]),
|
|
406
|
+
IntervalMatrix([[[-0.2,0.2],[-0.1,0.1]],
|
|
407
|
+
[[0.2,0.4],[-0.4,-0.1]],
|
|
408
|
+
[[1.0,2.0],[-0.2,-0.1]]])),1e-9)
|
|
409
|
+
== IntervalMatrix([[[-1.4,1.4],[-0.3,0.3]],
|
|
410
|
+
[[-0.2,0.2],[-0.3,0.3]]]))
|
|
411
|
+
self.assertTrue(Approx(f.eval(EvalMode.CENTERED,
|
|
412
|
+
Matrix([[1,0,1],[0,1,0]]),
|
|
413
|
+
IntervalMatrix([[[-0.2,0.2],[-0.1,0.1]],
|
|
414
|
+
[[0.2,0.4],[-0.4,-0.1]],
|
|
415
|
+
[[1.0,2.0],[-0.2,-0.1]]])),1e-9)
|
|
416
|
+
== Matrix([[0,0],[0,0]]))
|
|
417
|
+
|
|
418
|
+
m = MatrixVar(2,2)
|
|
419
|
+
f = AnalyticFunction([m], m*transpose(m))
|
|
420
|
+
theta = ScalarVar()
|
|
421
|
+
g = AnalyticFunction([theta], flatten(f(mat(vec(cos(theta),sin(theta)),
|
|
422
|
+
vec(-sin(theta),cos(theta))))))
|
|
423
|
+
a = Interval(0.3,0.4)
|
|
424
|
+
v1 = cos(a)*cos(a)+sin(a)*sin(a)
|
|
425
|
+
v2 = cos(a)*sin(a)-cos(a)*sin(a)
|
|
426
|
+
self.assertTrue(Approx(g.eval(EvalMode.NATURAL,a),1e-9)==
|
|
427
|
+
IntervalVector([v1,v2,v2,v1]))
|
|
428
|
+
v3 = 1.0 + Interval(-2,2)*(cos(a)*sin(a)-cos(a)*sin(a))*a.rad()
|
|
429
|
+
v4 = (cos(a)*cos(a)-cos(a)*cos(a)+sin(a)*sin(a)-sin(a)*sin(a))*a.rad()
|
|
430
|
+
self.assertTrue(Approx(g.eval(EvalMode.CENTERED,a),1e-9)==
|
|
431
|
+
IntervalVector([v3,v4,v4,v3]))
|
|
432
|
+
|
|
433
|
+
x = ScalarVar()
|
|
434
|
+
f = AnalyticFunction ([x], extend(x*(1-sqrt(x)),x));
|
|
435
|
+
self.assertTrue(f.eval(Interval(1.0,4.0))==Interval(-4.0,0.0))
|
|
436
|
+
self.assertTrue(f.eval(Interval(-4.0,-1.0))==Interval(-4.0,-1.0))
|
|
437
|
+
self.assertTrue(f.eval(Interval(0.0,4.0))==Interval(-4.0,4.0))
|
|
438
|
+
self.assertTrue(f.eval(Interval(0.0))==Interval(0.0))
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
if __name__ == '__main__':
|
|
442
|
+
unittest.main()
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
|
13
|
+
import math
|
|
14
|
+
|
|
15
|
+
def prim_value(x):
|
|
16
|
+
return 0.+(1./3.)*math.pow(x,3)
|
|
17
|
+
|
|
18
|
+
class TestAnalyticTraj(unittest.TestCase):
|
|
19
|
+
|
|
20
|
+
def test_AnalyticTraj(self):
|
|
21
|
+
|
|
22
|
+
t = ScalarVar()
|
|
23
|
+
f = AnalyticFunction(
|
|
24
|
+
[t],
|
|
25
|
+
sqr(t)
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
traj = AnalyticTraj(f, [-1,10])
|
|
29
|
+
|
|
30
|
+
self.assertTrue(traj.tdomain() == Interval(-1,10))
|
|
31
|
+
self.assertTrue(traj.codomain() == Interval(0,100))
|
|
32
|
+
self.assertTrue(traj.size() == 1)
|
|
33
|
+
self.assertTrue(Approx(traj(5.3),1e-3) == 28.09)
|
|
34
|
+
self.assertTrue(traj(traj.tdomain()) == traj.codomain())
|
|
35
|
+
self.assertTrue(traj([-oo,oo]) == Interval(-oo,oo))
|
|
36
|
+
|
|
37
|
+
# Testing sampled trajectory from analytic trajectory
|
|
38
|
+
sampled_traj = traj.sampled(0.01)
|
|
39
|
+
self.assertTrue(sampled_traj.tdomain() == Interval(-1,10))
|
|
40
|
+
self.assertTrue(Approx(sampled_traj.codomain()) == Interval(0,100))
|
|
41
|
+
self.assertTrue(sampled_traj.size() == 1)
|
|
42
|
+
self.assertTrue(Approx(sampled_traj(sampled_traj.tdomain())) == sampled_traj.codomain())
|
|
43
|
+
self.assertTrue(sampled_traj([-oo,oo]) == Interval(-oo,oo))
|
|
44
|
+
self.assertTrue(Approx(sampled_traj(0.)) == 0.)
|
|
45
|
+
self.assertTrue(Approx(sampled_traj(2.),1e-2) == 4.)
|
|
46
|
+
self.assertTrue(Approx(sampled_traj(5.),1e-2) == 25.)
|
|
47
|
+
self.assertTrue(Approx(sampled_traj(5.3),1e-2) == 28.09)
|
|
48
|
+
self.assertTrue(Approx(sampled_traj(9.),1e-2) == 81.)
|
|
49
|
+
|
|
50
|
+
# Testing primitive computation from analytic trajectory
|
|
51
|
+
sampled_prim_traj = traj.primitive(0.01)
|
|
52
|
+
self.assertTrue(sampled_prim_traj.tdomain() == Interval(-1,10))
|
|
53
|
+
self.assertTrue(Approx(sampled_prim_traj.codomain(),4e-1) == Interval(prim_value(0),prim_value(10.)))
|
|
54
|
+
self.assertTrue(sampled_prim_traj(-1.) == 0)
|
|
55
|
+
self.assertTrue(Approx(sampled_prim_traj(0.),4e-1) == prim_value(0.))
|
|
56
|
+
self.assertTrue(Approx(sampled_prim_traj(2.),4e-1) == prim_value(2.))
|
|
57
|
+
self.assertTrue(Approx(sampled_prim_traj(5.),4e-1) == prim_value(5.))
|
|
58
|
+
self.assertTrue(Approx(sampled_prim_traj(5.3),4e-1) == prim_value(5.3))
|
|
59
|
+
self.assertTrue(Approx(sampled_prim_traj(9.),4e-1) == prim_value(9.))
|
|
60
|
+
|
|
61
|
+
if __name__ == '__main__':
|
|
62
|
+
unittest.main()
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
|
13
|
+
|
|
14
|
+
class TestApprox(unittest.TestCase):
|
|
15
|
+
|
|
16
|
+
def test_approx(self):
|
|
17
|
+
|
|
18
|
+
self.assertFalse(Interval(0.1) == Interval(1.)/Interval(10.))
|
|
19
|
+
self.assertTrue(Approx(Interval(0.1)) == Interval(1.)/Interval(10.))
|
|
20
|
+
self.assertTrue(Interval(0.1) == Approx(Interval(1.)/Interval(10.)))
|
|
21
|
+
|
|
22
|
+
#self.assertTrue(IntervalVector([[0.1]]) != IntervalVector([1.])/Interval(10.))
|
|
23
|
+
#self.assertTrue(Approx(IntervalVector([[0.1]])) == IntervalVector([1.])/Interval(10.))
|
|
24
|
+
#self.assertTrue(IntervalVector([[0.1]]) == Approx(IntervalVector([1.])/Interval(10.)))
|
|
25
|
+
|
|
26
|
+
if __name__ == '__main__':
|
|
27
|
+
unittest.main()
|
|
@@ -0,0 +1,96 @@
|
|
|
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 TestBoolInterval(unittest.TestCase):
|
|
14
|
+
|
|
15
|
+
def test_BoolInterval(self):
|
|
16
|
+
|
|
17
|
+
# Bitwise AND (&) — Intersection
|
|
18
|
+
self.assertTrue((BoolInterval.TRUE & BoolInterval.TRUE) == BoolInterval.TRUE)
|
|
19
|
+
self.assertTrue((BoolInterval.TRUE & BoolInterval.FALSE) == BoolInterval.EMPTY)
|
|
20
|
+
self.assertTrue((BoolInterval.TRUE & BoolInterval.UNKNOWN) == BoolInterval.TRUE)
|
|
21
|
+
self.assertTrue((BoolInterval.TRUE & BoolInterval.EMPTY) == BoolInterval.EMPTY)
|
|
22
|
+
|
|
23
|
+
self.assertTrue((BoolInterval.FALSE & BoolInterval.FALSE) == BoolInterval.FALSE)
|
|
24
|
+
self.assertTrue((BoolInterval.FALSE & BoolInterval.UNKNOWN) == BoolInterval.FALSE)
|
|
25
|
+
self.assertTrue((BoolInterval.FALSE & BoolInterval.EMPTY) == BoolInterval.EMPTY)
|
|
26
|
+
|
|
27
|
+
self.assertTrue((BoolInterval.EMPTY & BoolInterval.EMPTY) == BoolInterval.EMPTY)
|
|
28
|
+
self.assertTrue((BoolInterval.EMPTY & BoolInterval.UNKNOWN) == BoolInterval.EMPTY)
|
|
29
|
+
|
|
30
|
+
self.assertTrue((BoolInterval.UNKNOWN & BoolInterval.UNKNOWN) == BoolInterval.UNKNOWN)
|
|
31
|
+
|
|
32
|
+
# Bitwise OR (|) — Union
|
|
33
|
+
self.assertTrue((BoolInterval.TRUE | BoolInterval.TRUE) == BoolInterval.TRUE)
|
|
34
|
+
self.assertTrue((BoolInterval.TRUE | BoolInterval.FALSE) == BoolInterval.UNKNOWN)
|
|
35
|
+
self.assertTrue((BoolInterval.TRUE | BoolInterval.UNKNOWN) == BoolInterval.UNKNOWN)
|
|
36
|
+
self.assertTrue((BoolInterval.TRUE | BoolInterval.EMPTY) == BoolInterval.TRUE)
|
|
37
|
+
|
|
38
|
+
self.assertTrue((BoolInterval.FALSE | BoolInterval.FALSE) == BoolInterval.FALSE)
|
|
39
|
+
self.assertTrue((BoolInterval.FALSE | BoolInterval.UNKNOWN) == BoolInterval.UNKNOWN)
|
|
40
|
+
self.assertTrue((BoolInterval.FALSE | BoolInterval.EMPTY) == BoolInterval.FALSE)
|
|
41
|
+
|
|
42
|
+
self.assertTrue((BoolInterval.EMPTY | BoolInterval.EMPTY) == BoolInterval.EMPTY)
|
|
43
|
+
self.assertTrue((BoolInterval.EMPTY | BoolInterval.UNKNOWN) == BoolInterval.UNKNOWN)
|
|
44
|
+
|
|
45
|
+
self.assertTrue((BoolInterval.UNKNOWN | BoolInterval.UNKNOWN) == BoolInterval.UNKNOWN)
|
|
46
|
+
|
|
47
|
+
# Logical AND (&&)
|
|
48
|
+
self.assertTrue(logical_and(BoolInterval.TRUE, BoolInterval.TRUE) == BoolInterval.TRUE)
|
|
49
|
+
self.assertTrue(logical_and(BoolInterval.TRUE, BoolInterval.FALSE) == BoolInterval.FALSE)
|
|
50
|
+
self.assertTrue(logical_and(BoolInterval.TRUE, BoolInterval.UNKNOWN) == BoolInterval.UNKNOWN)
|
|
51
|
+
self.assertTrue(logical_and(BoolInterval.TRUE, BoolInterval.EMPTY) == BoolInterval.EMPTY)
|
|
52
|
+
|
|
53
|
+
self.assertTrue(logical_and(BoolInterval.FALSE, BoolInterval.TRUE) == BoolInterval.FALSE)
|
|
54
|
+
self.assertTrue(logical_and(BoolInterval.FALSE, BoolInterval.FALSE) == BoolInterval.FALSE)
|
|
55
|
+
self.assertTrue(logical_and(BoolInterval.FALSE, BoolInterval.UNKNOWN) == BoolInterval.FALSE)
|
|
56
|
+
self.assertTrue(logical_and(BoolInterval.FALSE, BoolInterval.EMPTY) == BoolInterval.EMPTY)
|
|
57
|
+
|
|
58
|
+
self.assertTrue(logical_and(BoolInterval.UNKNOWN, BoolInterval.TRUE) == BoolInterval.UNKNOWN)
|
|
59
|
+
self.assertTrue(logical_and(BoolInterval.UNKNOWN, BoolInterval.FALSE) == BoolInterval.FALSE)
|
|
60
|
+
self.assertTrue(logical_and(BoolInterval.UNKNOWN, BoolInterval.UNKNOWN) == BoolInterval.UNKNOWN)
|
|
61
|
+
self.assertTrue(logical_and(BoolInterval.UNKNOWN, BoolInterval.EMPTY) == BoolInterval.EMPTY)
|
|
62
|
+
|
|
63
|
+
self.assertTrue(logical_and(BoolInterval.EMPTY, BoolInterval.TRUE) == BoolInterval.EMPTY)
|
|
64
|
+
self.assertTrue(logical_and(BoolInterval.EMPTY, BoolInterval.FALSE) == BoolInterval.EMPTY)
|
|
65
|
+
self.assertTrue(logical_and(BoolInterval.EMPTY, BoolInterval.UNKNOWN) == BoolInterval.EMPTY)
|
|
66
|
+
self.assertTrue(logical_and(BoolInterval.EMPTY, BoolInterval.EMPTY) == BoolInterval.EMPTY)
|
|
67
|
+
|
|
68
|
+
# Logical OR (||)
|
|
69
|
+
self.assertTrue(logical_or(BoolInterval.TRUE, BoolInterval.TRUE) == BoolInterval.TRUE)
|
|
70
|
+
self.assertTrue(logical_or(BoolInterval.TRUE, BoolInterval.FALSE) == BoolInterval.TRUE)
|
|
71
|
+
self.assertTrue(logical_or(BoolInterval.TRUE, BoolInterval.UNKNOWN) == BoolInterval.TRUE)
|
|
72
|
+
self.assertTrue(logical_or(BoolInterval.TRUE, BoolInterval.EMPTY) == BoolInterval.EMPTY)
|
|
73
|
+
|
|
74
|
+
self.assertTrue(logical_or(BoolInterval.FALSE, BoolInterval.TRUE) == BoolInterval.TRUE)
|
|
75
|
+
self.assertTrue(logical_or(BoolInterval.FALSE, BoolInterval.FALSE) == BoolInterval.FALSE)
|
|
76
|
+
self.assertTrue(logical_or(BoolInterval.FALSE, BoolInterval.UNKNOWN) == BoolInterval.UNKNOWN)
|
|
77
|
+
self.assertTrue(logical_or(BoolInterval.FALSE, BoolInterval.EMPTY) == BoolInterval.EMPTY)
|
|
78
|
+
|
|
79
|
+
self.assertTrue(logical_or(BoolInterval.UNKNOWN, BoolInterval.TRUE) == BoolInterval.TRUE)
|
|
80
|
+
self.assertTrue(logical_or(BoolInterval.UNKNOWN, BoolInterval.FALSE) == BoolInterval.UNKNOWN)
|
|
81
|
+
self.assertTrue(logical_or(BoolInterval.UNKNOWN, BoolInterval.UNKNOWN) == BoolInterval.UNKNOWN)
|
|
82
|
+
self.assertTrue(logical_or(BoolInterval.UNKNOWN, BoolInterval.EMPTY) == BoolInterval.EMPTY)
|
|
83
|
+
|
|
84
|
+
self.assertTrue(logical_or(BoolInterval.EMPTY, BoolInterval.TRUE) == BoolInterval.EMPTY)
|
|
85
|
+
self.assertTrue(logical_or(BoolInterval.EMPTY, BoolInterval.FALSE) == BoolInterval.EMPTY)
|
|
86
|
+
self.assertTrue(logical_or(BoolInterval.EMPTY, BoolInterval.UNKNOWN) == BoolInterval.EMPTY)
|
|
87
|
+
self.assertTrue(logical_or(BoolInterval.EMPTY, BoolInterval.EMPTY) == BoolInterval.EMPTY)
|
|
88
|
+
|
|
89
|
+
# Complement (~)
|
|
90
|
+
self.assertTrue((~BoolInterval.TRUE) == BoolInterval.FALSE)
|
|
91
|
+
self.assertTrue((~BoolInterval.FALSE) == BoolInterval.TRUE)
|
|
92
|
+
self.assertTrue((~BoolInterval.UNKNOWN) == BoolInterval.UNKNOWN)
|
|
93
|
+
self.assertTrue((~BoolInterval.EMPTY) == BoolInterval.EMPTY)
|
|
94
|
+
|
|
95
|
+
if __name__ == '__main__':
|
|
96
|
+
unittest.main()
|