Coverage for tests/test_Angle.py: 21%
42 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-12 10:50 -0700
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-12 10:50 -0700
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 """Test the Angle class."""
32 def testConstruction(self):
33 a1 = Angle(1.0)
34 a2 = Angle.fromRadians(1.0)
35 a3 = Angle.fromDegrees(57.29577951308232)
36 self.assertEqual(a1, a2)
37 self.assertEqual(a1.asRadians(), 1.0)
38 self.assertEqual(a1, a3)
39 self.assertEqual(a1.asDegrees(), 57.29577951308232)
41 def testComparisonOperators(self):
42 a1 = Angle(1)
43 a2 = Angle(2)
44 self.assertNotEqual(a1, a2)
45 self.assertLess(a1, a2)
46 self.assertLessEqual(a1, a2)
47 self.assertGreater(a2, a1)
48 self.assertGreaterEqual(a2, a1)
50 def testArithmeticOperators(self):
51 a = Angle(1)
52 b = -a
53 self.assertEqual(a + b, Angle(0))
54 self.assertEqual(a - b, 2.0 * a)
55 self.assertEqual(a - b, a * 2.0)
56 self.assertEqual(a / 1.0, a)
57 self.assertEqual(a / a, 1.0)
58 a += a
59 a *= 2
60 a -= b
61 a /= 5
62 self.assertEqual(a.asRadians(), 1)
64 def testString(self):
65 self.assertEqual(str(Angle(1)), "1.0")
66 self.assertEqual(repr(Angle(1)), "Angle(1.0)")
67 a = Angle(2.5)
68 self.assertEqual(a, eval(repr(a), {"Angle": Angle}))
70 def testPickle(self):
71 a = Angle(1.5)
72 b = pickle.loads(pickle.dumps(a))
73 self.assertEqual(a, b)
76if __name__ == "__main__":
77 unittest.main()