Coverage for tests/test_Angle.py: 24%
44 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-12-14 03:21 -0800
« prev ^ index » next coverage.py v6.5.0, created at 2022-12-14 03:21 -0800
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
29class AngleTestCase(unittest.TestCase):
30 def testConstruction(self):
31 a1 = Angle(1.0)
32 a2 = Angle.fromRadians(1.0)
33 a3 = Angle.fromDegrees(57.29577951308232)
34 self.assertEqual(a1, a2)
35 self.assertEqual(a1.asRadians(), 1.0)
36 self.assertEqual(a1, a3)
37 self.assertEqual(a1.asDegrees(), 57.29577951308232)
39 def testComparisonOperators(self):
40 a1 = Angle(1)
41 a2 = Angle(2)
42 self.assertNotEqual(a1, a2)
43 self.assertLess(a1, a2)
44 self.assertLessEqual(a1, a2)
45 self.assertGreater(a2, a1)
46 self.assertGreaterEqual(a2, a1)
48 def testArithmeticOperators(self):
49 a = Angle(1)
50 b = -a
51 self.assertEqual(a + b, Angle(0))
52 self.assertEqual(a - b, 2.0 * a)
53 self.assertEqual(a - b, a * 2.0)
54 self.assertEqual(a / 1.0, a)
55 self.assertEqual(a / a, 1.0)
56 a += a
57 a *= 2
58 a -= b
59 a /= 5
60 self.assertEqual(a.asRadians(), 1)
62 def testString(self):
63 self.assertEqual(str(Angle(1)), "1.0")
64 self.assertEqual(repr(Angle(1)), "Angle(1.0)")
65 a = Angle(2.5)
66 self.assertEqual(a, eval(repr(a), dict(Angle=Angle)))
68 def testPickle(self):
69 a = Angle(1.5)
70 b = pickle.loads(pickle.dumps(a))
71 self.assertEqual(a, b)
74if __name__ == "__main__": 74 ↛ 75line 74 didn't jump to line 75, because the condition on line 74 was never true
75 unittest.main()