From ffa152eab2f8b641d8750902fc4a6c79a4087771 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 20 May 2011 09:55:00 -0600 Subject: Fix Matrix repr() and tests. --- libdimension-python/Matrix.c | 4 ++-- libdimension-python/tests/geometry.py | 38 ++++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 14 deletions(-) (limited to 'libdimension-python') diff --git a/libdimension-python/Matrix.c b/libdimension-python/Matrix.c index 0de8acc..b18b2d7 100644 --- a/libdimension-python/Matrix.c +++ b/libdimension-python/Matrix.c @@ -110,8 +110,8 @@ dmnsn_py_Matrix_repr(dmnsn_py_Matrix *self) return NULL; } - PyObject *repr = PyUnicode_FromFormat("dimension.Matrix(%R, %R, %R, %R," - "%R, %R, %R, %R," + PyObject *repr = PyUnicode_FromFormat("dimension.Matrix(%R, %R, %R, %R, " + "%R, %R, %R, %R, " "%R, %R, %R, %R)", floats[0][0], floats[0][1], floats[0][2], floats[0][3], diff --git a/libdimension-python/tests/geometry.py b/libdimension-python/tests/geometry.py index 8f76ef7..9c79ef5 100755 --- a/libdimension-python/tests/geometry.py +++ b/libdimension-python/tests/geometry.py @@ -51,15 +51,29 @@ assert v, bool(v) assert not Zero, not Zero assert proj(v, X) == 2*X, proj(v, X) -assert scale(1, 2, 3) == Matrix(1, 0, 0, 0, - 0, 2, 0, 0, - 0, 0, 3, 0), \ - scale(1, 2, 3) -assert translate(x = 1, y = 2, z = 3) == Matrix(1, 0, 0, 1, - 0, 1, 0, 2, - 0, 0, 1, 3), \ - translate(x = 1, y = 2, z = 3) -assert rotate(90*Y) == Matrix( 0, 0, 1, 0, - 0, 1, 0, 0, - -1, 0, 0, 0), \ - rotate(90*Y) +m = Matrix(1, 2, 3, 4, + 5, 6, 7, 8, + 9, 10, 11, 12) + +assert repr(m) == 'dimension.Matrix(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, \ +9.0, 10.0, 11.0, 12.0)', repr(m) +assert str(m) == '\n' \ + '[1.0\t2.0\t3.0\t4.0]\n' \ + '[5.0\t6.0\t7.0\t8.0]\n' \ + '[9.0\t10.0\t11.0\t12.0]\n' \ + '[0.0\t0.0\t0.0\t1.0]', str(m) + +s = scale(1, 2, 3) +assert s == Matrix(1, 0, 0, 0, + 0, 2, 0, 0, + 0, 0, 3, 0), s + +t = translate(x = 1, y = 2, z = 3) +assert t == Matrix(1, 0, 0, 1, + 0, 1, 0, 2, + 0, 0, 1, 3), t + +r = rotate(90*Y).inverse() +assert r == Matrix(0, 0, -1, 0, + 0, 1, 0, 0, + 1, 0, 0, 0), r -- cgit v1.2.3