Coverage for tests/test_Ellipse.py : 25%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#
2# LSST Data Management System
3# See COPYRIGHT file at the top of the source tree.
4#
5# This product includes software developed by the
6# LSST Project (http://www.lsst.org/).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the LSST License Statement and
19# the GNU General Public License along with this program. If not,
20# see <https://www.lsstcorp.org/LegalNotices/>.
21#
23import pickle
24import yaml
26import math
27import unittest
29from lsst.sphgeom import (Angle, CONTAINS, Circle, Ellipse, Region,
30 UnitVector3d, WITHIN)
33class EllipseTestCase(unittest.TestCase):
35 def test_construction(self):
36 self.assertTrue(Ellipse.empty().isEmpty())
37 self.assertTrue(Ellipse().isEmpty())
38 self.assertTrue(Ellipse.full().isFull())
39 e = Ellipse(Circle(UnitVector3d.X(), Angle(math.pi / 2)))
40 f = Ellipse(UnitVector3d.X(), Angle(math.pi / 2))
41 self.assertEqual(e, f)
42 self.assertEqual(e.getAlpha(), e.getBeta())
43 self.assertTrue(e.isCircle())
44 self.assertTrue(e.isGreatCircle())
45 g = Ellipse(e)
46 h = e.clone()
47 self.assertEqual(e, g)
48 self.assertEqual(g, h)
49 self.assertNotEqual(id(e), id(g))
50 self.assertNotEqual(id(g), id(h))
52 def test_comparison_operators(self):
53 e = Ellipse(UnitVector3d.X(), UnitVector3d.Y(), Angle(2 * math.pi / 3))
54 f = Ellipse(UnitVector3d.X(),
55 Angle(math.pi / 3), Angle(math.pi / 6), Angle(0))
56 self.assertEqual(e, e)
57 self.assertNotEqual(e, f)
59 def test_center_and_dimensions(self):
60 e = Ellipse(UnitVector3d.X(), UnitVector3d.Y(), Angle(2 * math.pi / 3))
61 self.assertAlmostEqual(e.getF1().dot(UnitVector3d.X()), 1.0)
62 self.assertAlmostEqual(e.getF2().dot(UnitVector3d.Y()), 1.0)
63 self.assertAlmostEqual(e.getAlpha(), Angle(2 * math.pi / 3))
64 f = Ellipse(UnitVector3d.X(),
65 Angle(math.pi / 3), Angle(math.pi / 6), Angle(0))
66 self.assertEqual(f.getCenter(), UnitVector3d.X())
68 def test_relationships(self):
69 e = Ellipse(UnitVector3d.X(),
70 Angle(math.pi / 3), Angle(math.pi / 6), Angle(0))
71 self.assertTrue(e.contains(UnitVector3d.X()))
72 self.assertTrue(UnitVector3d.X() in e)
73 c = Circle(UnitVector3d.X(), Angle(math.pi / 2))
74 self.assertEqual(c.relate(e), CONTAINS)
75 self.assertEqual(e.relate(c), WITHIN)
77 def test_complement(self):
78 e = Ellipse(UnitVector3d.X(),
79 Angle(math.pi / 3), Angle(math.pi / 6), Angle(0))
80 f = e.complemented().complement()
81 self.assertEqual(e, f)
83 def test_codec(self):
84 e = Ellipse(UnitVector3d.X(), UnitVector3d.Y(), Angle(2 * math.pi / 3))
85 s = e.encode()
86 self.assertEqual(Ellipse.decode(s), e)
87 self.assertEqual(Region.decode(s), e)
89 def test_string(self):
90 c = Ellipse(UnitVector3d.Z(), Angle(1.0))
91 self.assertEqual(str(c),
92 'Ellipse([0.0, 0.0, 1.0], [0.0, 0.0, 1.0], 1.0)')
93 self.assertEqual(repr(c),
94 'Ellipse(UnitVector3d(0.0, 0.0, 1.0), '
95 'UnitVector3d(0.0, 0.0, 1.0), Angle(1.0))')
96 self.assertEqual(c, eval(repr(c), dict(
97 Angle=Angle, Ellipse=Ellipse, UnitVector3d=UnitVector3d)))
99 def test_pickle(self):
100 a = Ellipse(UnitVector3d.X(), UnitVector3d.Y(), Angle(2 * math.pi / 3))
101 b = pickle.loads(pickle.dumps(a, pickle.HIGHEST_PROTOCOL))
102 self.assertEqual(a, b)
104 def test_yaml(self):
105 a = Ellipse(UnitVector3d.X(), UnitVector3d.Y(), Angle(2 * math.pi / 3))
106 b = yaml.safe_load(yaml.dump(a))
107 self.assertEqual(a, b)
110if __name__ == '__main__': 110 ↛ 111line 110 didn't jump to line 111, because the condition on line 110 was never true
111 unittest.main()