Coverage for tests/test_Interval1d.py: 22%
Shortcuts 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
Shortcuts 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 CONTAINS, DISJOINT, Interval1d
29class Interval1dTestCase(unittest.TestCase):
31 def testConstruction(self):
32 i = Interval1d(1)
33 self.assertEqual(i.getA(), i.getB())
34 self.assertEqual(i.getA(), 1)
35 i = Interval1d(1, 2)
36 self.assertEqual(i, Interval1d(1, 2))
37 self.assertTrue(Interval1d.empty().isEmpty())
39 def testComparisonOperators(self):
40 self.assertEqual(Interval1d(1), Interval1d(1, 1))
41 self.assertEqual(Interval1d(1), 1)
42 self.assertNotEqual(Interval1d(1, 1), Interval1d(2, 2))
43 self.assertNotEqual(Interval1d(2, 2), 1)
45 def testCenterAndSize(self):
46 i = Interval1d(1, 2)
47 self.assertEqual(i.getSize(), 1)
48 self.assertEqual(i.getCenter(), 1.5)
50 def testRelationships(self):
51 i02 = Interval1d(0, 2)
52 i13 = Interval1d(1, 3)
53 i46 = Interval1d(4, 6)
54 i06 = Interval1d(0, 6)
55 self.assertTrue(i02.contains(1))
56 self.assertTrue(i02.contains(Interval1d(0.5, 1.5)))
57 self.assertTrue(i02.isDisjointFrom(3))
58 self.assertTrue(i02.isDisjointFrom(i46))
59 self.assertTrue(i02.intersects(1))
60 self.assertTrue(i02.intersects(i13))
61 self.assertTrue(Interval1d(1, 1).isWithin(i02))
62 self.assertTrue(i02.isWithin(i06))
63 r = i02.relate(1)
64 self.assertEqual(r, CONTAINS)
65 r = i46.relate(i02)
66 self.assertEqual(r, DISJOINT)
68 def testExpandingAndClipping(self):
69 a = Interval1d(1, 2)
70 b = (
71 a.expandedTo(3)
72 .expandedTo(Interval1d(2, 4))
73 .clippedTo(Interval1d(0, 2))
74 .clippedTo(1)
75 )
76 a.expandTo(3).expandTo(Interval1d(2, 4))
77 a.clipTo(Interval1d(0, 2)).clipTo(1)
78 self.assertEqual(a, b)
79 self.assertEqual(a, 1)
81 def testDilationAndErosion(self):
82 a = Interval1d(1, 3)
83 b = a.dilatedBy(1).erodedBy(2)
84 a.dilateBy(1).erodeBy(2)
85 self.assertEqual(a, b)
86 self.assertEqual(a, 2)
88 def testString(self):
89 i = Interval1d(1, 2)
90 self.assertEqual(str(i), '[1.0, 2.0]')
91 self.assertEqual(repr(i), 'Interval1d(1.0, 2.0)')
92 self.assertEqual(i, eval(repr(i), dict(Interval1d=Interval1d)))
94 def testPickle(self):
95 a = Interval1d(1.5, 3.5)
96 b = pickle.loads(pickle.dumps(a))
97 self.assertEqual(a, b)
100if __name__ == '__main__': 100 ↛ 101line 100 didn't jump to line 101, because the condition on line 100 was never true
101 unittest.main()