From a4d9129d77ff45fda2b46846a15beeb50b8da1a3 Mon Sep 17 00:00:00 2001 From: "Stephen M. McQuay" Date: Thu, 22 Mar 2012 10:09:14 -0600 Subject: [PATCH] Vertex now uses true division instead of casting RHS to float - updated tests --- surf/geometry.py | 3 ++- test/vertex.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/surf/geometry.py b/surf/geometry.py index ccf34d8..5a81975 100755 --- a/surf/geometry.py +++ b/surf/geometry.py @@ -1,3 +1,4 @@ +from __future__ import division import pprint ''' @@ -66,8 +67,8 @@ class Vertex(object): def __div__(self, other): # same assumption as __mult__ - other = float(other) return Vertex(self.x / other, self.y / other, self.z / other) + __truediv__ = __div__ def __neg__(self): return Vertex(-self.x, -self.y, -self.z) diff --git a/test/vertex.py b/test/vertex.py index a75cabd..e21cd09 100644 --- a/test/vertex.py +++ b/test/vertex.py @@ -1,6 +1,6 @@ import unittest -from surf.geometry import Vertex, cross +from surf.geometry import Vertex class TestVertexOperations(unittest.TestCase): @@ -30,6 +30,14 @@ class TestVertexOperations(unittest.TestCase): v2 = self.v1 / 2.0 self.assertEqual(v1, v2) + def test_inappropriate_division(self): + with self.assertRaises(TypeError): + self.v1 / self.v2 + with self.assertRaises(TypeError): + 1.0 / self.v1 + with self.assertRaises(TypeError): + self.v1 / 'asdf' + def test_multiply(self): self.assertEqual(type(self.v1 * 2), Vertex) self.assertEqual(type(self.v1 * self.v1), Vertex) @@ -37,7 +45,6 @@ class TestVertexOperations(unittest.TestCase): self.assertEqual(self.v1 * self.v1, Vertex(0, 0, 0)) self.assertEqual(self.v1 * self.v2, Vertex(0, 0, 0)) self.assertEqual(self.v3 * self.v4, Vertex(58, -35, -50)) - def test_cross(self): i = Vertex(1, 0, 0)