Debian Codegraph @

python/test/unit/geometry/test_point.py

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 """Unit tests for Point interface"""
2
3 # Copyright (C) 2017 Jan Blechta
4 #
5 # This file is part of DOLFIN.
6 #
7 # DOLFIN is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Lesser General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # DOLFIN is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
19
20 import pytest
21 import numpy as np
22
23 from dolfin import *
24
25
26 def test_point_getitem():
27 p = Point(1, 2, 3)
28 assert p[0] == 1.0
29 assert p[1] == 2.0
30 assert p[2] == 3.0
31 with pytest.raises(IndexError):
32 p[3]
33 assert np.all(p[:] == np.array((1.0, 2.0, 3.0)))
34
35
36 def test_point_setitem():
37 p = Point()
38
39 p[0] = 6.0
40 assert p[0] == 6.0
41
42 p[1] = 16.0
43 p[1] += 600.0
44 assert np.isclose(p[1], 616.0)
45
46 p[2] = 111.0
47 p[2] *= 12.0
48 p[2] /= 2
49 assert np.isclose(p[2], 666.0)
50
51 with pytest.raises(IndexError):
52 p[3] = 6666.0
53
54 p[:] = (0, 0, 0)
55 assert np.all(p[:] == 0)
56
57 p[:] = (1, 2, 3)
58 assert np.all(p[:] == (1, 2, 3))
59
60 p[:] += np.array((1, 2, 3))
61 assert np.all(p[:] == (2, 4, 6))
62
63 p[:] /= 2
64 assert np.all(p[:] == (1, 2, 3))
65
66 p[:] *= np.array((2., 2., 2.))
67 assert np.all(p[:] == (2, 4, 6))
68
69
70 def test_point_array():
71 p = Point(1, 2, 3)
72 assert np.all(p.array() == (1, 2, 3))
73
74 # Point.array() is a copy, no in-place modification
75 p.array()[:] += 1000.0
76 assert np.all(p.array() == (1, 2, 3))
77
78
79 def test_point_equality():
80 p = Point(1.23, 2, DOLFIN_PI)
81 q = Point(1.23, 2, DOLFIN_PI)
82 r = Point(1.23+DOLFIN_EPS, 2, DOLFIN_PI)
83 assert p == q
84 assert p != r
85
86
87 def test_point_dot():
88 p = Point(1.0, 2.0, 3.0)
89 q = Point(3.1, 4.5, 5.6)
90 r = Point(-1.6, -2.5, 3.3)
91 s = Point(152.25)
92
93 assert p.dot(q) == p[0]*q[0] + p[1]*q[1] + p[2]*q[2]
94 assert p.dot(r) == p[0]*r[0] + p[1]*r[1] + p[2]*r[2]
95 assert p.dot(s) == p[0]*s[0]