forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_builtin_int.py
52 lines (46 loc) · 968 Bytes
/
test_builtin_int.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
from ltypes import f64, i32, i64
def test_int():
f: f64
f = 5.678
i: i32
i = 4
assert int() == 0
assert int(i) == 4
i2: i64
i2 = int(3.0)
assert i2 == 3
assert int(5.678) == 5
assert int(f) == 5
f = -183745.23
assert int(-183745.23) == -183745
assert int(f) == -183745
assert int(5.5) == 5
assert int(-5.5) == -5
assert int(True) == 1
assert int(False) == 0
def test_bool_to_int():
b: i32
b = True - True
assert b == 0
b = False - False
assert b == 0
b = False - True
assert b == -1
b = True - False
assert b == 1
b = True + True
assert b == 2
b = False + False
assert b == 0
b = False + True
assert b == 1
b = True + False
assert b == 1
b = True + True + True - False
assert b == 3
b = True + (True + True) - (False + True)
assert b == 2
def check_all():
test_int()
test_bool_to_int()
check_all()