-
Notifications
You must be signed in to change notification settings - Fork 7
/
test_natural.py
123 lines (100 loc) · 2.77 KB
/
test_natural.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import pytest
from lambdas import TRUE, FALSE
from lambdas import ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN
from lambdas import ADD, INC, MUL, POW, DEC, SUB
from lambdas import ISZERO, GTE, LTE, GT, LT, EQ
from lambdas import decode_number
@pytest.mark.parametrize('given, expected', [
(ONE, 1),
(TWO, 2),
(THREE, 3),
(FOUR, 4),
(FIVE, 5),
(SIX, 6),
(SEVEN, 7),
(EIGHT, 8),
(NINE, 9),
(TEN, 10),
])
def test_numbers(given, expected):
assert decode_number(given) == expected
@pytest.mark.parametrize('given, expected', [
(ZERO, 1),
(ONE, 2),
(TWO, 3),
(THREE, 4),
])
def test_inc(given, expected):
assert decode_number(INC(given)) == expected
@pytest.mark.parametrize('given, expected', [
(ZERO, 0),
(ONE, 0),
(TWO, 1),
(THREE, 2),
])
def test_dec(given, expected):
assert decode_number(DEC(given)) == expected
@pytest.mark.parametrize('left, right, expected', [
(ONE, ONE, 2),
(TWO, THREE, 5),
(THREE, TWO, 5),
])
def test_add(left, right, expected):
assert decode_number(ADD(left)(right)) == expected
@pytest.mark.parametrize('left, right, expected', [
(ONE, ONE, 0),
(TWO, ONE, 1),
(THREE, TWO, 1),
(FOUR, ONE, 3),
])
def test_sub(left, right, expected):
assert decode_number(SUB(left)(right)) == expected
@pytest.mark.parametrize('left, right, expected', [
(ONE, ONE, 1),
(TWO, THREE, 6),
(THREE, TWO, 6),
])
def test_mul(left, right, expected):
assert decode_number(MUL(left)(right)) == expected
@pytest.mark.parametrize('left, right, expected', [
(ONE, ONE, 1),
(TWO, ONE, 2),
(ONE, TWO, 1),
(THREE, TWO, 9),
(THREE, THREE, 27),
])
def test_pow(left, right, expected):
assert decode_number(POW(left)(right)) == expected
@pytest.mark.parametrize('given, expected', [
(ZERO, TRUE),
(ONE, FALSE),
(TWO, FALSE),
])
def test_iszero(given, expected):
assert ISZERO(given) is expected
@pytest.mark.parametrize('left, right, expected', [
(ONE, ONE, TRUE),
(TWO, THREE, FALSE),
(THREE, TWO, TRUE),
(FOUR, TWO, TRUE),
])
def test_gte(left, right, expected):
assert GTE(left)(right) is expected
assert LT(left)(right) is not expected
@pytest.mark.parametrize('left, right, expected', [
(ONE, ONE, FALSE),
(TWO, THREE, FALSE),
(THREE, TWO, TRUE),
(FOUR, TWO, TRUE),
])
def test_gt(left, right, expected):
assert GT(left)(right) is expected
assert LTE(left)(right) is not expected
@pytest.mark.parametrize('left, right, expected', [
(ONE, ONE, TRUE),
(TWO, TWO, TRUE),
(TWO, ONE, FALSE),
(ONE, TWO, FALSE),
])
def test_eq(left, right, expected):
assert EQ(left)(right) is expected