diff --git a/test/test_chapter13.py b/test/test_chapter13.py index ff1ddc7d..ce6645a1 100644 --- a/test/test_chapter13.py +++ b/test/test_chapter13.py @@ -3,6 +3,8 @@ from sympy import Symbol, S, sqrt from galgebra.ga import Ga +USE_DIAGONAL_G = True + class TestChapter13(TestCase): @@ -10,44 +12,37 @@ def setUp(self): """ Initialize CGA. """ - g = [ - [ 1, 0, 0, 0, 0], - [ 0, 1, 0, 0, 0], - [ 0, 0, 1, 0, 0], - [ 0, 0, 0, 1, 0], - [ 0, 0, 0, 0, -1], - ] - - ga, e, e_1, e_2, e_3, eb = Ga.build('e e1 e2 e3 eb', g=g) - o = S.Half * (e + eb) - inf = eb - e - - self.ga = ga - self.o = o - self.e_1 = e_1 - self.e_2 = e_2 - self.e_3 = e_3 - self.inf = inf - - """ - # test_13_2_2 will fails with this - - g = [ - [ 0, 0, 0, 0, -1], - [ 0, 1, 0, 0, 0], - [ 0, 0, 1, 0, 0], - [ 0, 0, 0, 1, 0], - [-1, 0, 0, 0, 0], - ] + if USE_DIAGONAL_G: + # This is way faster with galgebra but o and inf can't be printed... + g = [ + [ 1, 0, 0, 0, 0], + [ 0, 1, 0, 0, 0], + [ 0, 0, 1, 0, 0], + [ 0, 0, 0, 1, 0], + [ 0, 0, 0, 0, -1], + ] + + ga, e, e_1, e_2, e_3, eb = Ga.build('e e1 e2 e3 eb', g=g) + o = S.Half * (e + eb) + inf = eb - e + + else: + g = [ + [ 0, 0, 0, 0, -1], + [ 0, 1, 0, 0, 0], + [ 0, 0, 1, 0, 0], + [ 0, 0, 0, 1, 0], + [-1, 0, 0, 0, 0], + ] + + ga, o, e_1, e_2, e_3, inf = Ga.build('o e1 e2 e3 inf', g=g) - ga, o, e_1, e_2, e_3, inf = Ga.build('o e1 e2 e3 inf', g=g) self.ga = ga self.o = o self.e_1 = e_1 self.e_2 = e_2 self.e_3 = e_3 self.inf = inf - """ def vector(self, x, y, z): """ diff --git a/test/test_utils.py b/test/test_utils.py index 3571b580..0ab99ecc 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -1,8 +1,9 @@ import unittest -from sympy import S, simplify +from sympy import expand, S, simplify from galgebra.ga import Ga from galgebra.mv import Mv +from galgebra.metric import Simp def com(A, B): @@ -24,19 +25,29 @@ def assertEqual(self, first, second): if isinstance(second, Mv): second = second.obj + # We need to help sympy a little... + first = Simp.apply(expand(first)) + second = Simp.apply(expand(second)) + + # Check diff = simplify(first - second) self.assertTrue(diff == 0, "\n%s\n==\n%s\n%s" % (first, second, diff)) - def assertProjEqual(self, X, Y): + def assertProjEqual(self, first, second): """ Compare two points, two planes or two lines up to a scalar. """ - assert isinstance(X, Mv) - assert isinstance(Y, Mv) + assert isinstance(first, Mv) + assert isinstance(second, Mv) + + # TODO: this should use Mv methods and not the derived test case methods... + first /= self.norm(first) + second /= self.norm(second) - X /= self.norm(X) - Y /= self.norm(Y) + # We need to help sympy a little... + X = Simp.apply(expand(first.obj)) + Y = Simp.apply(expand(second.obj)) # We can't easily retrieve the sign, so we test both diff = simplify(X.obj - Y.obj) @@ -55,6 +66,11 @@ def assertNotEqual(self, first, second): if isinstance(second, Mv): second = second.obj + # We need to help sympy a little... + first = Simp.apply(expand(first)) + second = Simp.apply(expand(second)) + + # Check diff = simplify(first - second) self.assertTrue(diff != 0, "\n%s\n!=\n%s\n%s" % (first, second, diff))