Coverage for tests/test_NormalizedAngle.py: 24%
Shortcuts 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
Shortcuts 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 unittest
26from lsst.sphgeom import Angle, LonLat, NormalizedAngle, UnitVector3d
29class NormalizedAngleTestCase(unittest.TestCase):
31 def testConstruction(self):
32 a1 = NormalizedAngle(1.0)
33 a2 = NormalizedAngle.fromRadians(1.0)
34 a3 = NormalizedAngle.fromDegrees(57.29577951308232)
35 self.assertEqual(a1, a2)
36 self.assertEqual(a1.asRadians(), 1.0)
37 self.assertEqual(a1, a3)
38 self.assertEqual(a1.asDegrees(), 57.29577951308232)
39 self.assertEqual(
40 NormalizedAngle.between(NormalizedAngle(0), NormalizedAngle(1)),
41 NormalizedAngle(1)
42 )
43 a = NormalizedAngle.center(NormalizedAngle(0), NormalizedAngle(1))
44 self.assertAlmostEqual(a.asRadians(), 0.5, places=15)
45 a = NormalizedAngle(LonLat.fromDegrees(45, 0),
46 LonLat.fromDegrees(90, 0))
47 self.assertAlmostEqual(a.asDegrees(), 45.0, places=13)
48 a = NormalizedAngle(UnitVector3d.Y(), UnitVector3d.Z())
49 self.assertAlmostEqual(a.asDegrees(), 90.0, places=13)
51 def testComparisonOperators(self):
52 a1 = NormalizedAngle(1)
53 a2 = NormalizedAngle(2)
54 self.assertNotEqual(a1, a2)
55 self.assertLess(a1, a2)
56 self.assertLessEqual(a1, a2)
57 self.assertGreater(a2, a1)
58 self.assertGreaterEqual(a2, a1)
60 def testArithmeticOperators(self):
61 a = NormalizedAngle(1)
62 b = -a
63 self.assertEqual(a + b, Angle(0))
64 self.assertEqual(a - b, 2.0 * a)
65 self.assertEqual(a - b, a * 2.0)
66 self.assertEqual(a / 1.0, a)
67 self.assertEqual(a / a, 1.0)
69 def testAngleTo(self):
70 self.assertEqual(NormalizedAngle(1).getAngleTo(NormalizedAngle(2)),
71 NormalizedAngle(1))
73 def testString(self):
74 self.assertEqual(str(NormalizedAngle(1)), '1.0')
75 self.assertEqual(repr(NormalizedAngle(1)), 'NormalizedAngle(1.0)')
76 a = NormalizedAngle(0.5)
77 self.assertEqual(
78 a, eval(repr(a), dict(NormalizedAngle=NormalizedAngle)))
80 def testPickle(self):
81 a = NormalizedAngle(1.5)
82 b = pickle.loads(pickle.dumps(a))
83 self.assertEqual(a, b)
86if __name__ == '__main__': 86 ↛ 87line 86 didn't jump to line 87, because the condition on line 86 was never true
87 unittest.main()