-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_hyperduck.py
52 lines (37 loc) · 986 Bytes
/
test_hyperduck.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
__author__ = 'andi'
from functional_collections import *
def test_hyperduck():
Dog = caseclass("Dog", [("name", str), ("age", int)])
@implicit(Dog, int)
def dog2int(d):
return d.age
@takes(int)
def multiply_int_by_2(i):
assert(type(i) == int)
return i*2
result = multiply_int_by_2(Dog("Matthew", 13))
assert(result == 26)
def test_hyperduck_stats():
Dog = caseclass("Dog", [("name", str), ("age", int)])
@implicit(Dog, int)
def dog2int(d):
return d.age
@takes(int)
def multiply_int_by_2(i):
assert(type(i) == int)
return i*2
result = multiply_int_by_2(Dog("Matthew", 13))
assert(result == 26)
stats = get_hyperduck_stats(multiply_int_by_2)
assert(stats.transformed == 1)
def test_hyperduck_failure():
@takes(list)
def typeof(thing):
return type(True)
assert(typeof(True) == bool)
stats = get_hyperduck_stats(typeof)
assert(stats.failed == 1)
if __name__ == "__main__":
test_hyperduck()
test_hyperduck_stats()
test_hyperduck_failure()