Coverage for tests/test_AngleIntervals.py : 25%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
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, AngleInterval,
27 CONTAINS, DISJOINT,
28 NormalizedAngle, NormalizedAngleInterval)
31class IntervalTests:
33 def testConstruction(self):
34 i = self.Interval(self.Scalar(1))
35 self.assertEqual(i.getA(), i.getB())
36 self.assertEqual(i.getA(), self.Scalar(1))
37 i = self.Interval(self.Scalar(1), self.Scalar(2))
38 self.assertEqual(i, self.Interval.fromRadians(1, 2))
39 self.assertTrue(self.Interval.empty().isEmpty())
41 def testComparisonOperators(self):
42 self.assertEqual(self.Interval(self.Scalar(1)),
43 self.Interval.fromRadians(1, 1))
44 self.assertEqual(self.Interval(self.Scalar(1)), self.Scalar(1))
45 self.assertNotEqual(self.Interval.fromDegrees(1, 1),
46 self.Interval.fromRadians(1, 1))
47 self.assertNotEqual(self.Interval.fromDegrees(2, 2), self.Scalar(1))
49 def testCenterAndSize(self):
50 a = self.Interval.fromRadians(1, 2)
51 self.assertEqual(a.getSize(), self.Scalar(1))
52 self.assertEqual(a.getCenter(), self.Scalar(1.5))
54 def testRelationships(self):
55 a02 = self.Interval.fromRadians(0, 2)
56 a13 = self.Interval.fromRadians(1, 3)
57 a46 = self.Interval.fromRadians(4, 6)
58 a06 = self.Interval.fromRadians(0, 6)
59 self.assertTrue(a02.contains(self.Scalar(1)))
60 self.assertTrue(a02.contains(self.Interval.fromRadians(0.5, 1.5)))
61 self.assertTrue(a02.isDisjointFrom(self.Scalar(3)))
62 self.assertTrue(a02.isDisjointFrom(a46))
63 self.assertTrue(a02.intersects(self.Scalar(1)))
64 self.assertTrue(a02.intersects(a13))
65 self.assertTrue(self.Interval.fromRadians(1, 1).isWithin(a02))
66 self.assertTrue(a02.isWithin(a06))
67 r = a02.relate(self.Scalar(1))
68 self.assertEqual(r, CONTAINS)
69 r = a46.relate(a02)
70 self.assertEqual(r, DISJOINT)
72 def testExpandingAndClipping(self):
73 a = self.Interval.fromRadians(1, 2)
74 b = (
75 a.expandedTo(self.Scalar(3))
76 .expandedTo(self.Interval.fromRadians(2, 4))
77 .clippedTo(self.Interval.fromRadians(0, 2))
78 .clippedTo(self.Scalar(1))
79 )
80 a.expandTo(self.Scalar(3)).expandTo(self.Interval.fromRadians(2, 4))
81 a.clipTo(self.Interval.fromRadians(0, 2)).clipTo(self.Scalar(1))
82 self.assertEqual(a, b)
83 self.assertEqual(a, self.Scalar(1))
85 def testDilationAndErosion(self):
86 a = self.Interval.fromRadians(1, 3)
87 b = a.dilatedBy(self.Scalar(1)).erodedBy(self.Scalar(2))
88 a.dilateBy(self.Scalar(1)).erodeBy(self.Scalar(2))
89 self.assertEqual(a, b)
90 self.assertEqual(a, self.Scalar(2))
92 def testString(self):
93 a = self.Interval.fromRadians(0.5, 1.5)
94 self.assertEqual(str(a), '[0.5, 1.5]')
95 self.assertEqual(repr(a),
96 self.Interval.__name__ + '.fromRadians(0.5, 1.5)')
97 self.assertEqual(
98 a, eval(repr(a), dict([(self.Interval.__name__, self.Interval)])))
100 def testPickle(self):
101 a = self.Interval.fromRadians(1, 3)
102 b = pickle.loads(pickle.dumps(a))
103 self.assertEqual(a, b)
106class AngleIntervalTestCase(unittest.TestCase, IntervalTests):
108 def setUp(self):
109 self.Interval = AngleInterval
110 self.Scalar = Angle
113class NormalizedAngleIntervalTestCase(unittest.TestCase, IntervalTests):
115 def setUp(self):
116 self.Interval = NormalizedAngleInterval
117 self.Scalar = NormalizedAngle
120if __name__ == '__main__': 120 ↛ 121line 120 didn't jump to line 121, because the condition on line 120 was never true
121 unittest.main()