summaryrefslogtreecommitdiffstats
path: root/libdimension-python/tests
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-05-18 22:20:17 -0600
committerTavian Barnes <tavianator@gmail.com>2011-05-18 22:20:17 -0600
commit6d86cbdcdeb60cdaa5146d186a33e844a09aaf86 (patch)
tree0472a21ef229a07a6f06cf2f2853934910131b21 /libdimension-python/tests
parentfe3bd7a078ac758792da7338d480b274e6aa4895 (diff)
downloaddimension-6d86cbdcdeb60cdaa5146d186a33e844a09aaf86.tar.xz
Implement Vectors in python.
Diffstat (limited to 'libdimension-python/tests')
-rw-r--r--libdimension-python/tests/Makefile.am3
-rwxr-xr-xlibdimension-python/tests/geometry.py52
2 files changed, 54 insertions, 1 deletions
diff --git a/libdimension-python/tests/Makefile.am b/libdimension-python/tests/Makefile.am
index 4bebfda..17589ba 100644
--- a/libdimension-python/tests/Makefile.am
+++ b/libdimension-python/tests/Makefile.am
@@ -17,7 +17,8 @@
## along with this program. If not, see <http://www.gnu.org/licenses/>. ##
###########################################################################
-TESTS = demo.py
+TESTS = geometry.py \
+ demo.py
TESTS_ENVIRONMENT = PYTHONPATH=$(top_builddir)/libdimension-python/.libs
.py:
diff --git a/libdimension-python/tests/geometry.py b/libdimension-python/tests/geometry.py
new file mode 100755
index 0000000..b398a1b
--- /dev/null
+++ b/libdimension-python/tests/geometry.py
@@ -0,0 +1,52 @@
+#!/usr/bin/python3
+
+#########################################################################
+# Copyright (C) 2010-2011 Tavian Barnes <tavianator@tavianator.com> #
+# #
+# This file is part of The Dimension Test Suite. #
+# #
+# The Dimension Test Suite is free software; you can redistribute it #
+# and/or modify it under the terms of the GNU General Public License as #
+# published by the Free Software Foundation; either version 3 of the #
+# License, or (at your option) any later version. #
+# #
+# The Dimension Test Suite is distributed in the hope that it will be #
+# useful, but WITHOUT ANY WARRANTY; without even the implied warranty #
+# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+#########################################################################
+
+from dimension import *
+
+# Treat warnings as errors for tests
+dieOnWarnings(True)
+
+assert Zero == Vector(0, 0, 0), Zero
+assert X == Vector(1, 0, 0), X
+assert Y == Vector(0, 1, 0), Y
+assert Z == Vector(0, 0, 1), Z
+
+v = Vector(1.5, 2.5, 3.5)
+
+assert v.x == 1.5, v.x
+assert v.y == 2.5, v.y
+assert v.z == 3.5, v.z
+assert repr(v) == 'dimension.Vector(1.5, 2.5, 3.5)', repr(v)
+assert str(v) == '<1.5, 2.5, 3.5>', str(v)
+
+v = Vector(x = 2, y = 3, z = 6)
+
+assert v.norm() == 7, v.norm()
+assert v.normalized() == v/7, v.normalized()
+assert v + v == 2*v == v*2 == Vector(4, 6, 12), v + v
+assert v/2 == v - v/2 == Vector(1, 1.5, 3), v/2
+assert +v == v, +v
+assert v + -v == Zero, v + -v
+assert cross(v, v) == Zero, cross(v, v)
+assert dot(v, v) == v.norm()**2, dot(v, v)
+assert v, bool(v)
+assert not Zero, not Zero
+assert proj(v, X) == 2*X, proj(v, X)