-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathtest_builtin_str_02.py
96 lines (81 loc) · 2.67 KB
/
test_builtin_str_02.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
from lpython import i32
def _lpython_strcmp_eq(a: str, b: str) -> bool:
if len(a) != len(b):
return False
i: i32
for i in range(len(a)):
if a[i] != b[i]:
return False
return True
def _lpython_strcmp_noteq(a: str, b: str) -> bool:
return not _lpython_strcmp_eq(a, b)
def _lpython_strcmp_lt(a: str, b: str) -> bool:
l: i32
l = len(a)
if l > len(b):
l = len(b)
i: i32
for i in range(l):
if a[i] > b[i]:
return False
return True
def _lpython_strcmp_lteq(a: str, b: str) -> bool:
return _lpython_strcmp_eq(a, b) or _lpython_strcmp_lt(a, b)
def _lpython_strcmp_gt(a: str, b: str) -> bool:
l: i32
l = len(a)
if l > len(b):
l = len(b)
i: i32
for i in range(l):
if a[i] < b[i]:
return False
return True
def _lpython_strcmp_gteq(a: str, b: str) -> bool:
return _lpython_strcmp_eq(a, b) or _lpython_strcmp_gt(a, b)
def _lpython_str_repeat(a: str, n: i32) -> str:
s: str
s = ""
i: i32
for i in range(n):
s += a
return s
def f():
assert _lpython_strcmp_eq("a", "a")
assert not _lpython_strcmp_eq("a2", "a")
assert not _lpython_strcmp_eq("a", "a123")
assert not _lpython_strcmp_eq("a23", "a24")
assert _lpython_strcmp_eq("a24", "a24")
assert _lpython_strcmp_eq("abcdefg", "abcdefg")
assert not _lpython_strcmp_eq("abcdef3", "abcdefg")
assert _lpython_strcmp_noteq("a2", "a")
assert _lpython_strcmp_noteq("a", "a123")
assert _lpython_strcmp_noteq("a23", "a24")
assert _lpython_strcmp_noteq("abcdef3", "abcdefg")
assert not _lpython_strcmp_noteq("a24", "a24")
assert _lpython_strcmp_lt("a", "a2")
assert _lpython_strcmp_lt("a", "a123")
assert _lpython_strcmp_lt("a23", "a24")
assert _lpython_strcmp_lt("abcdef3", "gbc")
assert not _lpython_strcmp_lt("bg", "abc")
assert not _lpython_strcmp_lt("abcdefg", "abcdef3")
assert _lpython_strcmp_lteq("a", "a2")
assert _lpython_strcmp_lteq("a123", "a123")
assert _lpython_strcmp_lteq("a23", "a24")
assert not _lpython_strcmp_lteq("abcdefg", "abcdef3")
assert _lpython_strcmp_gt("a2", "a")
assert _lpython_strcmp_gt("a123", "a")
assert _lpython_strcmp_gt("a24", "a23")
assert _lpython_strcmp_gt("z", "abcdef3")
assert not _lpython_strcmp_gt("abcdef3", "abcdefg")
a: str
a = "abcdefg"
b: str
b = "abcdef3"
assert _lpython_strcmp_gteq("a2", "a")
assert _lpython_strcmp_gteq("a123", "a123")
assert _lpython_strcmp_gteq("bg", "abc")
assert _lpython_strcmp_gteq(a, b)
assert _lpython_str_repeat("abc", 3) == "abcabcabc"
assert _lpython_str_repeat("", -1) == ""
f()