Coverage for tests/test_Angle.py: 24%

44 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-06 20:22 +0000

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# 

22 

23import pickle 

24import unittest 

25 

26from lsst.sphgeom import Angle 

27 

28 

29class AngleTestCase(unittest.TestCase): 

30 

31 def testConstruction(self): 

32 a1 = Angle(1.0) 

33 a2 = Angle.fromRadians(1.0) 

34 a3 = Angle.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 

40 def testComparisonOperators(self): 

41 a1 = Angle(1) 

42 a2 = Angle(2) 

43 self.assertNotEqual(a1, a2) 

44 self.assertLess(a1, a2) 

45 self.assertLessEqual(a1, a2) 

46 self.assertGreater(a2, a1) 

47 self.assertGreaterEqual(a2, a1) 

48 

49 def testArithmeticOperators(self): 

50 a = Angle(1) 

51 b = -a 

52 self.assertEqual(a + b, Angle(0)) 

53 self.assertEqual(a - b, 2.0 * a) 

54 self.assertEqual(a - b, a * 2.0) 

55 self.assertEqual(a / 1.0, a) 

56 self.assertEqual(a / a, 1.0) 

57 a += a 

58 a *= 2 

59 a -= b 

60 a /= 5 

61 self.assertEqual(a.asRadians(), 1) 

62 

63 def testString(self): 

64 self.assertEqual(str(Angle(1)), '1.0') 

65 self.assertEqual(repr(Angle(1)), 'Angle(1.0)') 

66 a = Angle(2.5) 

67 self.assertEqual(a, eval(repr(a), dict(Angle=Angle))) 

68 

69 def testPickle(self): 

70 a = Angle(1.5) 

71 b = pickle.loads(pickle.dumps(a)) 

72 self.assertEqual(a, b) 

73 

74 

75if __name__ == '__main__': 75 ↛ 76line 75 didn't jump to line 76, because the condition on line 75 was never true

76 unittest.main()