Hide keyboard shortcuts

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

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

# 

# LSST Data Management System 

# See COPYRIGHT file at the top of the source tree. 

# 

# This product includes software developed by the 

# LSST Project (http://www.lsst.org/). 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the LSST License Statement and 

# the GNU General Public License along with this program. If not, 

# see <https://www.lsstcorp.org/LegalNotices/>. 

# 

 

import pickle 

import unittest 

 

from lsst.sphgeom import CONTAINS, DISJOINT, Interval1d 

 

 

class Interval1dTestCase(unittest.TestCase): 

 

def testConstruction(self): 

i = Interval1d(1) 

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

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

i = Interval1d(1, 2) 

self.assertEqual(i, Interval1d(1, 2)) 

self.assertTrue(Interval1d.empty().isEmpty()) 

 

def testComparisonOperators(self): 

self.assertEqual(Interval1d(1), Interval1d(1, 1)) 

self.assertEqual(Interval1d(1), 1) 

self.assertNotEqual(Interval1d(1, 1), Interval1d(2, 2)) 

self.assertNotEqual(Interval1d(2, 2), 1) 

 

def testCenterAndSize(self): 

i = Interval1d(1, 2) 

self.assertEqual(i.getSize(), 1) 

self.assertEqual(i.getCenter(), 1.5) 

 

def testRelationships(self): 

i02 = Interval1d(0, 2) 

i13 = Interval1d(1, 3) 

i46 = Interval1d(4, 6) 

i06 = Interval1d(0, 6) 

self.assertTrue(i02.contains(1)) 

self.assertTrue(i02.contains(Interval1d(0.5, 1.5))) 

self.assertTrue(i02.isDisjointFrom(3)) 

self.assertTrue(i02.isDisjointFrom(i46)) 

self.assertTrue(i02.intersects(1)) 

self.assertTrue(i02.intersects(i13)) 

self.assertTrue(Interval1d(1, 1).isWithin(i02)) 

self.assertTrue(i02.isWithin(i06)) 

r = i02.relate(1) 

self.assertEqual(r, CONTAINS) 

r = i46.relate(i02) 

self.assertEqual(r, DISJOINT) 

 

def testExpandingAndClipping(self): 

a = Interval1d(1, 2) 

b = ( 

a.expandedTo(3) 

.expandedTo(Interval1d(2, 4)) 

.clippedTo(Interval1d(0, 2)) 

.clippedTo(1) 

) 

a.expandTo(3).expandTo(Interval1d(2, 4)) 

a.clipTo(Interval1d(0, 2)).clipTo(1) 

self.assertEqual(a, b) 

self.assertEqual(a, 1) 

 

def testDilationAndErosion(self): 

a = Interval1d(1, 3) 

b = a.dilatedBy(1).erodedBy(2) 

a.dilateBy(1).erodeBy(2) 

self.assertEqual(a, b) 

self.assertEqual(a, 2) 

 

def testString(self): 

i = Interval1d(1, 2) 

self.assertEqual(str(i), '[1.0, 2.0]') 

self.assertEqual(repr(i), 'Interval1d(1.0, 2.0)') 

self.assertEqual(i, eval(repr(i), dict(Interval1d=Interval1d))) 

 

def testPickle(self): 

a = Interval1d(1.5, 3.5) 

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

self.assertEqual(a, b) 

 

 

100 ↛ 101line 100 didn't jump to line 101, because the condition on line 100 was never trueif __name__ == '__main__': 

unittest.main()