From: Bruno Turcksin Date: Tue, 11 Apr 2017 13:41:18 +0000 (-0400) Subject: Add tests. X-Git-Tag: v9.0.0-rc1~1704^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f72d57cc8479a0dfafd55de45cd5570557197f15;p=dealii.git Add tests. --- diff --git a/contrib/python-bindings/tests/point_wrapper.py b/contrib/python-bindings/tests/point_wrapper.py index 4fcbc309e3..7b1b3b136d 100644 --- a/contrib/python-bindings/tests/point_wrapper.py +++ b/contrib/python-bindings/tests/point_wrapper.py @@ -14,31 +14,110 @@ # --------------------------------------------------------------------- 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__':