forked from brutasse/graphite-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_intervals.py
61 lines (43 loc) · 1.64 KB
/
test_intervals.py
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
from graphite_api.intervals import IntervalSet, Interval, union_overlapping
from . import TestCase
class IntervalTestCase(TestCase):
def test_interval(self):
with self.assertRaises(ValueError):
Interval(1, 0)
i = Interval(0, 1)
j = Interval(1, 2)
k = Interval(0, 1)
l = Interval(0, 0)
self.assertNotEqual(i, j)
self.assertEqual(i, k)
self.assertEqual(hash(i), hash(k))
with self.assertRaises(TypeError):
len(i)
self.assertTrue(j > i)
self.assertTrue(i)
self.assertFalse(l)
self.assertEqual(repr(i), '<Interval: (0, 1)>')
self.assertIsNone(i.intersect(j))
self.assertEqual(i.intersect(k), k)
self.assertTrue(i.overlaps(j))
self.assertEqual(i.union(j), Interval(0, 2))
with self.assertRaises(TypeError):
j.union(l)
self.assertEqual(union_overlapping([i, j, k, l]),
[Interval(0, 2)])
def test_interval_set(self):
i = Interval(0, 1)
j = Interval(1, 2)
s = IntervalSet([i, j])
self.assertEqual(repr(s), '[<Interval: (0, 2)>]')
s = IntervalSet([i, j], disjoint=True)
it = iter(s)
self.assertEqual(next(it), i)
self.assertEqual(next(it), j)
self.assertTrue(s)
self.assertFalse(IntervalSet([]))
self.assertEqual(s - IntervalSet([i]),
IntervalSet([j]))
self.assertFalse(IntervalSet([]).intersect(s))
self.assertEqual(s.union(IntervalSet([Interval(3, 4)])),
IntervalSet([Interval(3, 4), i, j]))