Vertex now uses true division instead of casting RHS to float

- updated tests
This commit is contained in:
Stephen M. McQuay 2012-03-22 10:09:14 -06:00
parent c1f7ee46bc
commit a4d9129d77
2 changed files with 11 additions and 3 deletions

View File

@ -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)

View File

@ -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)