Coverage for tests/test_AngleIntervals.py: 24%
67 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 CONTAINS, DISJOINT, Angle, AngleInterval, NormalizedAngle, NormalizedAngleInterval
29class IntervalTests:
30 """Test intervals."""
32 def testConstruction(self):
33 i = self.Interval(self.Scalar(1))
34 self.assertEqual(i.getA(), i.getB())
35 self.assertEqual(i.getA(), self.Scalar(1))
36 i = self.Interval(self.Scalar(1), self.Scalar(2))
37 self.assertEqual(i, self.Interval.fromRadians(1, 2))
38 self.assertTrue(self.Interval.empty().isEmpty())
40 def testComparisonOperators(self):
41 self.assertEqual(self.Interval(self.Scalar(1)), self.Interval.fromRadians(1, 1))
42 self.assertEqual(self.Interval(self.Scalar(1)), self.Scalar(1))
43 self.assertNotEqual(self.Interval.fromDegrees(1, 1), self.Interval.fromRadians(1, 1))
44 self.assertNotEqual(self.Interval.fromDegrees(2, 2), self.Scalar(1))
46 def testCenterAndSize(self):
47 a = self.Interval.fromRadians(1, 2)
48 self.assertEqual(a.getSize(), self.Scalar(1))
49 self.assertEqual(a.getCenter(), self.Scalar(1.5))
51 def testRelationships(self):
52 a02 = self.Interval.fromRadians(0, 2)
53 a13 = self.Interval.fromRadians(1, 3)
54 a46 = self.Interval.fromRadians(4, 6)
55 a06 = self.Interval.fromRadians(0, 6)
56 self.assertTrue(a02.contains(self.Scalar(1)))
57 self.assertTrue(a02.contains(self.Interval.fromRadians(0.5, 1.5)))
58 self.assertTrue(a02.isDisjointFrom(self.Scalar(3)))
59 self.assertTrue(a02.isDisjointFrom(a46))
60 self.assertTrue(a02.intersects(self.Scalar(1)))
61 self.assertTrue(a02.intersects(a13))
62 self.assertTrue(self.Interval.fromRadians(1, 1).isWithin(a02))
63 self.assertTrue(a02.isWithin(a06))
64 r = a02.relate(self.Scalar(1))
65 self.assertEqual(r, CONTAINS)
66 r = a46.relate(a02)
67 self.assertEqual(r, DISJOINT)
69 def testExpandingAndClipping(self):
70 a = self.Interval.fromRadians(1, 2)
71 b = (
72 a.expandedTo(self.Scalar(3))
73 .expandedTo(self.Interval.fromRadians(2, 4))
74 .clippedTo(self.Interval.fromRadians(0, 2))
75 .clippedTo(self.Scalar(1))
76 )
77 a.expandTo(self.Scalar(3)).expandTo(self.Interval.fromRadians(2, 4))
78 a.clipTo(self.Interval.fromRadians(0, 2)).clipTo(self.Scalar(1))
79 self.assertEqual(a, b)
80 self.assertEqual(a, self.Scalar(1))
82 def testDilationAndErosion(self):
83 a = self.Interval.fromRadians(1, 3)
84 b = a.dilatedBy(self.Scalar(1)).erodedBy(self.Scalar(2))
85 a.dilateBy(self.Scalar(1)).erodeBy(self.Scalar(2))
86 self.assertEqual(a, b)
87 self.assertEqual(a, self.Scalar(2))
89 def testString(self):
90 a = self.Interval.fromRadians(0.5, 1.5)
91 self.assertEqual(str(a), "[0.5, 1.5]")
92 self.assertEqual(repr(a), self.Interval.__name__ + ".fromRadians(0.5, 1.5)")
93 self.assertEqual(a, eval(repr(a), {self.Interval.__name__: self.Interval}))
95 def testPickle(self):
96 a = self.Interval.fromRadians(1, 3)
97 b = pickle.loads(pickle.dumps(a))
98 self.assertEqual(a, b)
101class AngleIntervalTestCase(unittest.TestCase, IntervalTests):
102 """Angle interval test cases."""
104 def setUp(self):
105 self.Interval = AngleInterval
106 self.Scalar = Angle
109class NormalizedAngleIntervalTestCase(unittest.TestCase, IntervalTests):
110 """Normalized angle interval test cases."""
112 def setUp(self):
113 self.Interval = NormalizedAngleInterval
114 self.Scalar = NormalizedAngle
117if __name__ == "__main__":
118 unittest.main()