]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add tests.
authorBruno Turcksin <bruno.turcksin@gmail.com>
Tue, 11 Apr 2017 13:41:18 +0000 (09:41 -0400)
committerBruno Turcksin <bruno.turcksin@gmail.com>
Tue, 11 Apr 2017 14:24:26 +0000 (10:24 -0400)
contrib/python-bindings/tests/point_wrapper.py

index 4fcbc309e306aff4a6b96ecb8aed7f8bc27d5cb5..7b1b3b136d78f7556058c63c72ec9097776054e2 100644 (file)
 # ---------------------------------------------------------------------
 
 import unittest
+import math
 from PyDealII.Debug import *
 
 
 class TestPointWrapper(unittest.TestCase):
 
     def test_2d_point(self):
-        point = Point([0., 1.])
-        self.assertEqual(point.x, 0.)
-        self.assertEqual(point.y, 1.)
-        point.x = 1.
-        point.y = 2.
-        self.assertEqual(point.x, 1.)
-        self.assertEqual(point.y, 2.)
+        p1 = Point([0., 1.])
+        self.assertEqual(p1.x, 0.)
+        self.assertEqual(p1.y, 1.)
+        p1.x = 1.
+        p1.y = 2.
+        self.assertEqual(p1.x, 1.)
+        self.assertEqual(p1.y, 2.)
+        p2 = Point([0., 2.])
+        self.assertEqual(p1.distance(p2), 1.)
+        self.assertEqual(p2.norm(), 2.) 
+        self.assertEqual(p2.norm_square(), 4.)
+        self.assertEqual(p1 != p2, True)
+        self.assertEqual(p1 == p2, False)
+        self.assertEqual(p1*p2, 4.)
+        p3 = p1 + p2
+        self.assertEqual(p3.x, p1.x + p2.x)
+        self.assertEqual(p3.y, p1.y + p2.y)
+        p3 = p1 - p2
+        self.assertEqual(p3.x, p1.x - p2.x)
+        self.assertEqual(p3.y, p1.y - p2.y)
+        p3 = -p2;
+        self.assertEqual(p3.x, -p2.x)
+        self.assertEqual(p3.y, -p2.y)
+        p3 = p2 / 2.; 
+        self.assertEqual(p3.x, p2.x / 2.)
+        self.assertEqual(p3.y, p2.y / 2.)
+        p3 = p2 * 2.;
+        self.assertEqual(p3.x, p2.x * 2.)
+        self.assertEqual(p3.y, p2.y * 2.)
+        p2 += p1 
+        self.assertEqual(p2.x, 1.)
+        self.assertEqual(p2.y, 4.)
+        p2 -= p1 
+        self.assertEqual(p2.x, 0.)
+        self.assertEqual(p2.y, 2.)
+        p2 /= 2.; 
+        self.assertEqual(p2.x, 0.)
+        self.assertEqual(p2.y, 1.)
+        p2 *= 2.;
+        self.assertEqual(p2.x, 0.)
+        self.assertEqual(p2.y, 2.)
 
     def test_3d_point(self):
-        point = Point([0., 1., 2.])
-        self.assertEqual(point.x, 0.)
-        self.assertEqual(point.y, 1.)
-        self.assertEqual(point.z, 2.)
-        point.x = 1.
-        point.y = 2.
-        point.z = 3.
-        self.assertEqual(point.x, 1.)
-        self.assertEqual(point.y, 2.)
-        self.assertEqual(point.z, 3.)
+        p1 = Point([0., 1., 2.])
+        self.assertEqual(p1.x, 0.)
+        self.assertEqual(p1.y, 1.)
+        self.assertEqual(p1.z, 2.)
+        p1.x = 1.
+        p1.y = 2.
+        p1.z = 3.
+        self.assertEqual(p1.x, 1.)
+        self.assertEqual(p1.y, 2.)
+        self.assertEqual(p1.z, 3.)
+        p2 = Point([0., 1., 2.])
+        self.assertAlmostEqual(p1.distance(p2), math.sqrt(3))
+        self.assertAlmostEqual(p2.norm(), math.sqrt(5))
+        self.assertEqual(p2.norm_square(), 5.)
+        self.assertEqual(p1 != p2, True)
+        self.assertEqual(p1 == p2, False)
+        self.assertEqual(p1*p2, 8)
+        dim = 3
+        p3 = p1 + p2
+        self.assertEqual(p3.x, p1.x + p2.x)
+        self.assertEqual(p3.y, p1.y + p2.y)
+        self.assertEqual(p3.z, p1.z + p2.z)
+        p3 = p1 - p2
+        self.assertEqual(p3.x, p1.x - p2.x)
+        self.assertEqual(p3.y, p1.y - p2.y)
+        self.assertEqual(p3.z, p1.z - p2.z)
+        p3 = -p2;
+        self.assertEqual(p3.x, -p2.x)
+        self.assertEqual(p3.y, -p2.y)
+        self.assertEqual(p3.z, -p2.z)
+        p3 = p2 / 2.; 
+        self.assertEqual(p3.x, p2.x / 2.)
+        self.assertEqual(p3.y, p2.y / 2.)
+        self.assertEqual(p3.z, p2.z / 2.)
+        p3 = p2 * 2.;
+        self.assertEqual(p3.x, p2.x * 2.)
+        self.assertEqual(p3.y, p2.y * 2.)
+        self.assertEqual(p3.z, p2.z * 2.)
+        p2 += p1
+        self.assertEqual(p2.x, 1.)
+        self.assertEqual(p2.y, 3.)
+        self.assertEqual(p2.z, 5.)
+        p2 -= p1
+        self.assertEqual(p2.x, 0.)
+        self.assertEqual(p2.y, 1.)
+        self.assertEqual(p2.z, 2.)
+        p2 /= 2.
+        self.assertEqual(p2.x, 0.)
+        self.assertEqual(p2.y, 0.5)
+        self.assertEqual(p2.z, 1.)
+        p2 *= 2.
+        self.assertEqual(p2.x, 0.)
+        self.assertEqual(p2.y, 1.)
+        self.assertEqual(p2.z, 2.)
 
 
 if __name__ == '__main__':

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.