-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathtest_types.py
49 lines (42 loc) · 1.3 KB
/
test_types.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
from opshin.type_impls import *
def test_record_type_order():
A = RecordType(Record("A", "A", 0, [("foo", IntegerInstanceType)]))
B = RecordType(Record("B", "B", 1, [("bar", IntegerInstanceType)]))
C = RecordType(Record("C", "C", 2, [("baz", IntegerInstanceType)]))
a = A
b = B
c = C
assert a >= a
assert not a >= b
assert not b >= a
assert not a >= c
assert not c >= a
assert not b >= c
assert not c >= b
A = RecordType(Record("A", "A", 0, [("foo", IntegerInstanceType)]))
B = RecordType(
Record(
"B", "B", 0, [("foo", IntegerInstanceType), ("bar", IntegerInstanceType)]
)
)
C = RecordType(Record("C", "C", 0, [("foo", InstanceType(AnyType()))]))
assert not A >= B
assert not C >= B
assert C >= A
def test_union_type_order():
A = RecordType(Record("A", "A", 0, [("foo", IntegerInstanceType)]))
B = RecordType(Record("B", "B", 1, [("bar", IntegerInstanceType)]))
C = RecordType(Record("C", "C", 2, [("baz", IntegerInstanceType)]))
abc = UnionType([A, B, C])
ab = UnionType([A, B])
a = A
c = C
assert a >= a
assert ab >= a
assert not a >= ab
assert abc >= ab
assert not ab >= abc
assert not c >= a
assert not a >= c
assert abc >= c
assert not ab >= c