Belle II Software light-2406-ragdoll
TestIntervalOfValidity Class Reference
Inheritance diagram for TestIntervalOfValidity:
Collaboration diagram for TestIntervalOfValidity:

Public Member Functions

def iovify (self, iov)
 
def test_create (self)
 
def test_intersection (self)
 
def test_union (self)
 
def test_union_startone (self)
 
def test_subtract (self)
 

Detailed Description

Helper class to test an IoV

Definition at line 21 of file test_iov.py.

Member Function Documentation

◆ iovify()

def iovify (   self,
  iov 
)
Helper function to turn a tuple/None/list(tuple) into iov instances

Definition at line 24 of file test_iov.py.

24 def iovify(self, iov):
25 """Helper function to turn a tuple/None/list(tuple) into iov instances"""
26 if isinstance(iov, list):
27 return tuple(IntervalOfValidity(i) for i in iov)
28 elif iov is not None:
29 return IntervalOfValidity(iov)
30 else:
31 return None
32

◆ test_create()

def test_create (   self)
Test that we get errors when creating invalid iovs

Definition at line 33 of file test_iov.py.

33 def test_create(self):
34 """Test that we get errors when creating invalid iovs"""
35 with self.assertRaises(ValueError):
36 iov = IntervalOfValidity(0)
37 with self.assertRaises(ValueError):
38 iov = IntervalOfValidity(-1, 0, 0, 0)
39 with self.assertRaises(ValueError):
40 iov = IntervalOfValidity(0, -1, 0, 0)
41 with self.assertRaises(ValueError):
42 iov = IntervalOfValidity(-1, -1, 0, 0)
43 with self.assertRaises(ValueError):
44 iov = IntervalOfValidity(1, 0, 0, 0)
45 with self.assertRaises(ValueError):
46 iov = IntervalOfValidity(0, 1, 0, 0)
47 with self.assertRaises(ValueError):
48 iov = IntervalOfValidity(10, 0, 7, 4)
49 with self.assertRaises(ValueError):
50 iov = IntervalOfValidity(0, 0, -1, 4)
51 iov = IntervalOfValidity(0, 0, -1, -1)
52 self.assertEqual(iov.final, (math.inf, math.inf))
53 iov = IntervalOfValidity(0, 0, 1, -1)
54 self.assertEqual(iov.final, (1, math.inf))
55 self.assertEqual(IntervalOfValidity(0, 1, 2, 3), IntervalOfValidity((0, 1, 2, 3)))
56

◆ test_intersection()

def test_intersection (   self)
Test that we can intersect iovs

Definition at line 57 of file test_iov.py.

57 def test_intersection(self):
58 """Test that we can intersect iovs"""
59 iov = IntervalOfValidity
60 for a, b, c in [
61 [(0, 0, 10, 0), (11, 10, 11, 12), None],
62 [(0, 0, 10, 0), (8, 0, 10, 12), (8, 0, 10, 0)],
63 [(0, 0, 0, 0), (0, 0, -1, -1), (0, 0, 0, 0)],
64 [(0, 0, -1, -1), (20, 12, 21, 234), (20, 12, 21, 234)],
65 [(0, 0, 2, -1), (1, 1, 2, 8), (1, 1, 2, 8)],
66 [(1, 2, 2, -1), (0, 0, 2, 8), (1, 2, 2, 8)],
67 [(1, 0, 3, -1), (0, 0, 2, -1), (1, 0, 2, -1)],
68 [(0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)],
69 ]:
70 self.assertEqual(iov(a) & iov(b), self.iovify(c), f'{a} & {b} = {c}')
71 self.assertEqual(iov(b) & iov(a), self.iovify(c), f'{a} & {b} = {c}')
72

◆ test_subtract()

def test_subtract (   self)
Test subtracting iovs from another

Definition at line 101 of file test_iov.py.

101 def test_subtract(self):
102 """Test subtracting iovs from another"""
103 iov = IntervalOfValidity
104 for a, b, c, d in [
105 [(0, 0, 10, 0), (11, 10, 11, 12), (0, 0, 10, 0), (11, 10, 11, 12)],
106 [(0, 0, 10, 0), (8, 0, 10, 12), (0, 0, 7, -1), (10, 1, 10, 12)],
107 [(0, 0, 0, 0), (0, 0, -1, -1), None, (0, 1, -1, -1)],
108 [(0, 0, -1, -1), (20, 12, 21, 234), [(0, 0, 20, 11), (21, 235, -1, -1)], None],
109 [(0, 0, 2, -1), (1, 1, 2, 8), [(0, 0, 1, 0), (2, 9, 2, -1)], None],
110 [(1, 2, 2, -1), (0, 0, 2, 8), (2, 9, 2, -1), (0, 0, 1, 1)],
111 [(1, 0, 3, -1), (0, 0, 2, -1), (3, 0, 3, -1), (0, 0, 0, -1)],
112 [(0, 0, -1, -1), (0, 0, -1, -1), None, None],
113 [(0, 0, 1, -1), (0, 0, 1, -1), None, None],
114 [(0, 0, 0, 0), (0, 0, 0, 0), None, None],
115 [(0, 0, 1, -1), (2, 0, 2, -1), (0, 0, 1, -1), (2, 0, 2, -1)],
116 [(11, 0, 12, 86), (0, 0, 11, -1), (12, 0, 12, 86), (0, 0, 10, -1)],
117 ]:
118 self.assertEqual(iov(a) - iov(b), self.iovify(c), f'{a} - {b} = {c}')
119 self.assertEqual(iov(b) - iov(a), self.iovify(d), f'{b} - {a} = {d}')
120
121

◆ test_union()

def test_union (   self)
Test that we can calculate the union of iovs

Definition at line 73 of file test_iov.py.

73 def test_union(self):
74 """Test that we can calculate the union of iovs"""
75 iov = IntervalOfValidity
76 for a, b, c in [
77 [(0, 0, 10, 0), (11, 10, 11, 12), None],
78 [(0, 0, 10, 0), (8, 0, 10, 12), (0, 0, 10, 12)],
79 [(0, 0, 0, 0), (0, 0, -1, -1), (0, 0, -1, -1)],
80 [(0, 0, -1, -1), (20, 12, 21, 234), (0, 0, -1, -1)],
81 [(0, 0, 2, -1), (1, 1, 2, 8), (0, 0, 2, -1)],
82 [(1, 2, 2, -1), (0, 0, 2, 8), (0, 0, 2, -1)],
83 [(1, 0, 3, -1), (0, 0, 2, -1), (0, 0, 3, -1)],
84 [(0, 0, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)],
85 [(0, 0, 1, 1), (1, 2, 1, 3), (0, 0, 1, 3)],
86 [(0, 0, 1, 1), (1, 3, 1, 4), None],
87 [(0, 0, 1, -1), (2, 0, 2, 1), (0, 0, 2, 1)],
88 [(0, 0, 1, -1), (2, 0, 2, 1), (0, 0, 2, 1)],
89 [(0, 0, 1, -1), (2, 1, 2, 1), None],
90 [(0, 0, 1, -1), (1, 9999, 2, 1), (0, 0, 2, 1)],
91 ]:
92 self.assertEqual(iov(a) | iov(b), self.iovify(c), f'{a} | {b} = {c}')
93 self.assertEqual(iov(b) | iov(a), self.iovify(c), f'{a} | {b} = {c}')
94

◆ test_union_startone()

def test_union_startone (   self)
Test that we can calculate the union starting at run 1 as well

Definition at line 95 of file test_iov.py.

95 def test_union_startone(self):
96 """Test that we can calculate the union starting at run 1 as well"""
97 iov = IntervalOfValidity
98 self.assertEqual(iov(0, 0, 1, -1).union(iov(2, 1, 2, -1)), None)
99 self.assertEqual(iov(0, 0, 1, -1).union(iov(2, 1, 2, -1), True), iov(0, 0, 2, -1))
100

The documentation for this class was generated from the following file: