Coverage for tests/test_Ellipse.py : 26%

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
24try:
25 import yaml
26except ImportError:
27 yaml = None
29import math
30import unittest
32from lsst.sphgeom import (Angle, CONTAINS, Circle, Ellipse, Region,
33 UnitVector3d, WITHIN)
36class EllipseTestCase(unittest.TestCase):
38 def test_construction(self):
39 self.assertTrue(Ellipse.empty().isEmpty())
40 self.assertTrue(Ellipse().isEmpty())
41 self.assertTrue(Ellipse.full().isFull())
42 e = Ellipse(Circle(UnitVector3d.X(), Angle(math.pi / 2)))
43 f = Ellipse(UnitVector3d.X(), Angle(math.pi / 2))
44 self.assertEqual(e, f)
45 self.assertEqual(e.getAlpha(), e.getBeta())
46 self.assertTrue(e.isCircle())
47 self.assertTrue(e.isGreatCircle())
48 g = Ellipse(e)
49 h = e.clone()
50 self.assertEqual(e, g)
51 self.assertEqual(g, h)
52 self.assertNotEqual(id(e), id(g))
53 self.assertNotEqual(id(g), id(h))
55 def test_comparison_operators(self):
56 e = Ellipse(UnitVector3d.X(), UnitVector3d.Y(), Angle(2 * math.pi / 3))
57 f = Ellipse(UnitVector3d.X(),
58 Angle(math.pi / 3), Angle(math.pi / 6), Angle(0))
59 self.assertEqual(e, e)
60 self.assertNotEqual(e, f)
62 def test_center_and_dimensions(self):
63 e = Ellipse(UnitVector3d.X(), UnitVector3d.Y(), Angle(2 * math.pi / 3))
64 self.assertAlmostEqual(e.getF1().dot(UnitVector3d.X()), 1.0)
65 self.assertAlmostEqual(e.getF2().dot(UnitVector3d.Y()), 1.0)
66 self.assertAlmostEqual(e.getAlpha(), Angle(2 * math.pi / 3))
67 f = Ellipse(UnitVector3d.X(),
68 Angle(math.pi / 3), Angle(math.pi / 6), Angle(0))
69 self.assertEqual(f.getCenter(), UnitVector3d.X())
71 def test_relationships(self):
72 e = Ellipse(UnitVector3d.X(),
73 Angle(math.pi / 3), Angle(math.pi / 6), Angle(0))
74 self.assertTrue(e.contains(UnitVector3d.X()))
75 self.assertTrue(UnitVector3d.X() in e)
76 c = Circle(UnitVector3d.X(), Angle(math.pi / 2))
77 self.assertEqual(c.relate(e), CONTAINS)
78 self.assertEqual(e.relate(c), WITHIN)
80 def test_complement(self):
81 e = Ellipse(UnitVector3d.X(),
82 Angle(math.pi / 3), Angle(math.pi / 6), Angle(0))
83 f = e.complemented().complement()
84 self.assertEqual(e, f)
86 def test_codec(self):
87 e = Ellipse(UnitVector3d.X(), UnitVector3d.Y(), Angle(2 * math.pi / 3))
88 s = e.encode()
89 self.assertEqual(Ellipse.decode(s), e)
90 self.assertEqual(Region.decode(s), e)
92 def test_string(self):
93 c = Ellipse(UnitVector3d.Z(), Angle(1.0))
94 self.assertEqual(str(c),
95 'Ellipse([0.0, 0.0, 1.0], [0.0, 0.0, 1.0], 1.0)')
96 self.assertEqual(repr(c),
97 'Ellipse(UnitVector3d(0.0, 0.0, 1.0), '
98 'UnitVector3d(0.0, 0.0, 1.0), Angle(1.0))')
99 self.assertEqual(c, eval(repr(c), dict(
100 Angle=Angle, Ellipse=Ellipse, UnitVector3d=UnitVector3d)))
102 def test_pickle(self):
103 a = Ellipse(UnitVector3d.X(), UnitVector3d.Y(), Angle(2 * math.pi / 3))
104 b = pickle.loads(pickle.dumps(a, pickle.HIGHEST_PROTOCOL))
105 self.assertEqual(a, b)
107 @unittest.skipIf(not yaml, "YAML module can not be imported")
108 def test_yaml(self):
109 a = Ellipse(UnitVector3d.X(), UnitVector3d.Y(), Angle(2 * math.pi / 3))
110 b = yaml.safe_load(yaml.dump(a))
111 self.assertEqual(a, b)
114if __name__ == '__main__': 114 ↛ 115line 114 didn't jump to line 115, because the condition on line 114 was never true
115 unittest.main()