Skip to content

Commit 5fc94d2

Browse files
committed
Fix assertEqual for difficult expressions
1 parent 3c4a5b8 commit 5fc94d2

File tree

2 files changed

+48
-37
lines changed

2 files changed

+48
-37
lines changed

test/test_chapter13.py

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,46 @@
33
from sympy import Symbol, S, sqrt
44
from galgebra.ga import Ga
55

6+
USE_DIAGONAL_G = True
7+
68

79
class TestChapter13(TestCase):
810

911
def setUp(self):
1012
"""
1113
Initialize CGA.
1214
"""
13-
g = [
14-
[ 1, 0, 0, 0, 0],
15-
[ 0, 1, 0, 0, 0],
16-
[ 0, 0, 1, 0, 0],
17-
[ 0, 0, 0, 1, 0],
18-
[ 0, 0, 0, 0, -1],
19-
]
20-
21-
ga, e, e_1, e_2, e_3, eb = Ga.build('e e1 e2 e3 eb', g=g)
22-
o = S.Half * (e + eb)
23-
inf = eb - e
24-
25-
self.ga = ga
26-
self.o = o
27-
self.e_1 = e_1
28-
self.e_2 = e_2
29-
self.e_3 = e_3
30-
self.inf = inf
31-
32-
"""
33-
# test_13_2_2 will fails with this
34-
35-
g = [
36-
[ 0, 0, 0, 0, -1],
37-
[ 0, 1, 0, 0, 0],
38-
[ 0, 0, 1, 0, 0],
39-
[ 0, 0, 0, 1, 0],
40-
[-1, 0, 0, 0, 0],
41-
]
15+
if USE_DIAGONAL_G:
16+
# This is way faster with galgebra but o and inf can't be printed...
17+
g = [
18+
[ 1, 0, 0, 0, 0],
19+
[ 0, 1, 0, 0, 0],
20+
[ 0, 0, 1, 0, 0],
21+
[ 0, 0, 0, 1, 0],
22+
[ 0, 0, 0, 0, -1],
23+
]
24+
25+
ga, e, e_1, e_2, e_3, eb = Ga.build('e e1 e2 e3 eb', g=g)
26+
o = S.Half * (e + eb)
27+
inf = eb - e
28+
29+
else:
30+
g = [
31+
[ 0, 0, 0, 0, -1],
32+
[ 0, 1, 0, 0, 0],
33+
[ 0, 0, 1, 0, 0],
34+
[ 0, 0, 0, 1, 0],
35+
[-1, 0, 0, 0, 0],
36+
]
37+
38+
ga, o, e_1, e_2, e_3, inf = Ga.build('o e1 e2 e3 inf', g=g)
4239

43-
ga, o, e_1, e_2, e_3, inf = Ga.build('o e1 e2 e3 inf', g=g)
4440
self.ga = ga
4541
self.o = o
4642
self.e_1 = e_1
4743
self.e_2 = e_2
4844
self.e_3 = e_3
4945
self.inf = inf
50-
"""
5146

5247
def vector(self, x, y, z):
5348
"""

test/test_utils.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import unittest
22

3-
from sympy import S, simplify
3+
from sympy import expand, S, simplify
44
from galgebra.ga import Ga
55
from galgebra.mv import Mv
6+
from galgebra.metric import Simp
67

78

89
def com(A, B):
@@ -24,19 +25,29 @@ def assertEqual(self, first, second):
2425
if isinstance(second, Mv):
2526
second = second.obj
2627

28+
# We need to help sympy a little...
29+
first = Simp.apply(expand(first))
30+
second = Simp.apply(expand(second))
31+
32+
# Check
2733
diff = simplify(first - second)
2834

2935
self.assertTrue(diff == 0, "\n%s\n==\n%s\n%s" % (first, second, diff))
3036

31-
def assertProjEqual(self, X, Y):
37+
def assertProjEqual(self, first, second):
3238
"""
3339
Compare two points, two planes or two lines up to a scalar.
3440
"""
35-
assert isinstance(X, Mv)
36-
assert isinstance(Y, Mv)
41+
assert isinstance(first, Mv)
42+
assert isinstance(second, Mv)
43+
44+
# TODO: this should use Mv methods and not the derived test case methods...
45+
first /= self.norm(first)
46+
second /= self.norm(second)
3747

38-
X /= self.norm(X)
39-
Y /= self.norm(Y)
48+
# We need to help sympy a little...
49+
X = Simp.apply(expand(first.obj))
50+
Y = Simp.apply(expand(second.obj))
4051

4152
# We can't easily retrieve the sign, so we test both
4253
diff = simplify(X.obj - Y.obj)
@@ -55,6 +66,11 @@ def assertNotEqual(self, first, second):
5566
if isinstance(second, Mv):
5667
second = second.obj
5768

69+
# We need to help sympy a little...
70+
first = Simp.apply(expand(first))
71+
second = Simp.apply(expand(second))
72+
73+
# Check
5874
diff = simplify(first - second)
5975

6076
self.assertTrue(diff != 0, "\n%s\n!=\n%s\n%s" % (first, second, diff))

0 commit comments

Comments
 (0)