Coverage for tests/test_AngleIntervals.py: 25%

69 statements  

« prev     ^ index     » next       coverage.py v7.3.0, created at 2023-08-23 18:04 +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 CONTAINS, DISJOINT, Angle, AngleInterval, NormalizedAngle, NormalizedAngleInterval 

27 

28 

29class IntervalTests: 

30 def testConstruction(self): 

31 i = self.Interval(self.Scalar(1)) 

32 self.assertEqual(i.getA(), i.getB()) 

33 self.assertEqual(i.getA(), self.Scalar(1)) 

34 i = self.Interval(self.Scalar(1), self.Scalar(2)) 

35 self.assertEqual(i, self.Interval.fromRadians(1, 2)) 

36 self.assertTrue(self.Interval.empty().isEmpty()) 

37 

38 def testComparisonOperators(self): 

39 self.assertEqual(self.Interval(self.Scalar(1)), self.Interval.fromRadians(1, 1)) 

40 self.assertEqual(self.Interval(self.Scalar(1)), self.Scalar(1)) 

41 self.assertNotEqual(self.Interval.fromDegrees(1, 1), self.Interval.fromRadians(1, 1)) 

42 self.assertNotEqual(self.Interval.fromDegrees(2, 2), self.Scalar(1)) 

43 

44 def testCenterAndSize(self): 

45 a = self.Interval.fromRadians(1, 2) 

46 self.assertEqual(a.getSize(), self.Scalar(1)) 

47 self.assertEqual(a.getCenter(), self.Scalar(1.5)) 

48 

49 def testRelationships(self): 

50 a02 = self.Interval.fromRadians(0, 2) 

51 a13 = self.Interval.fromRadians(1, 3) 

52 a46 = self.Interval.fromRadians(4, 6) 

53 a06 = self.Interval.fromRadians(0, 6) 

54 self.assertTrue(a02.contains(self.Scalar(1))) 

55 self.assertTrue(a02.contains(self.Interval.fromRadians(0.5, 1.5))) 

56 self.assertTrue(a02.isDisjointFrom(self.Scalar(3))) 

57 self.assertTrue(a02.isDisjointFrom(a46)) 

58 self.assertTrue(a02.intersects(self.Scalar(1))) 

59 self.assertTrue(a02.intersects(a13)) 

60 self.assertTrue(self.Interval.fromRadians(1, 1).isWithin(a02)) 

61 self.assertTrue(a02.isWithin(a06)) 

62 r = a02.relate(self.Scalar(1)) 

63 self.assertEqual(r, CONTAINS) 

64 r = a46.relate(a02) 

65 self.assertEqual(r, DISJOINT) 

66 

67 def testExpandingAndClipping(self): 

68 a = self.Interval.fromRadians(1, 2) 

69 b = ( 

70 a.expandedTo(self.Scalar(3)) 

71 .expandedTo(self.Interval.fromRadians(2, 4)) 

72 .clippedTo(self.Interval.fromRadians(0, 2)) 

73 .clippedTo(self.Scalar(1)) 

74 ) 

75 a.expandTo(self.Scalar(3)).expandTo(self.Interval.fromRadians(2, 4)) 

76 a.clipTo(self.Interval.fromRadians(0, 2)).clipTo(self.Scalar(1)) 

77 self.assertEqual(a, b) 

78 self.assertEqual(a, self.Scalar(1)) 

79 

80 def testDilationAndErosion(self): 

81 a = self.Interval.fromRadians(1, 3) 

82 b = a.dilatedBy(self.Scalar(1)).erodedBy(self.Scalar(2)) 

83 a.dilateBy(self.Scalar(1)).erodeBy(self.Scalar(2)) 

84 self.assertEqual(a, b) 

85 self.assertEqual(a, self.Scalar(2)) 

86 

87 def testString(self): 

88 a = self.Interval.fromRadians(0.5, 1.5) 

89 self.assertEqual(str(a), "[0.5, 1.5]") 

90 self.assertEqual(repr(a), self.Interval.__name__ + ".fromRadians(0.5, 1.5)") 

91 self.assertEqual(a, eval(repr(a), dict([(self.Interval.__name__, self.Interval)]))) 

92 

93 def testPickle(self): 

94 a = self.Interval.fromRadians(1, 3) 

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

96 self.assertEqual(a, b) 

97 

98 

99class AngleIntervalTestCase(unittest.TestCase, IntervalTests): 

100 def setUp(self): 

101 self.Interval = AngleInterval 

102 self.Scalar = Angle 

103 

104 

105class NormalizedAngleIntervalTestCase(unittest.TestCase, IntervalTests): 

106 def setUp(self): 

107 self.Interval = NormalizedAngleInterval 

108 self.Scalar = NormalizedAngle 

109 

110 

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

112 unittest.main()