98 lines
1.7 KiB
Python
Raw Normal View History

2021-12-14 11:03:33 +08:00
import PikaStdLib
2022-01-05 10:55:27 +08:00
import PikaStdData
2021-12-14 11:03:33 +08:00
2022-01-05 10:55:27 +08:00
mem = PikaStdLib.MemChecker()
2022-01-05 11:19:56 +08:00
mem.resetMax()
2022-01-05 10:55:27 +08:00
def EXPECT_EQ(test_name, input, expected):
print('-----TEST-----')
print(test_name)
if input != expected:
print('[Error]')
print(test_name)
print('[info] Expected:')
print(expected)
print('[info] Input:')
print(input)
# error
while True:
is_error = 1
else:
print('[ OK ]')
a = 0
for i in range(0, 10):
if i == 5:
continue
a = a + i
EXPECT_EQ('for_if_continue', a, 40)
a = 0
for i in range(0, 10):
if i == 5:
break
a = a + i
EXPECT_EQ('for_if_break', a, 10)
a = 0
for i in range(0, 10):
for k in range(0, 3):
# print(k)
a = a + k
EXPECT_EQ('for_for_in_range', a, 30)
a = 0
for i in range(0, 10):
# print(i)
a = a + i
EXPECT_EQ('for_in_range', a, 45)
list = PikaStdData.List()
list.append(7)
list.append('eee')
len = list.len()
for item in list:
# print(item)
a = item
EXPECT_EQ('list_for_loop', a, 'eee')
list = PikaStdData.List()
list.append(7)
list.append('eee')
len = list.len()
a1 = list.get(0)
a2 = list.get(1)
res = iter(list)
EXPECT_EQ('iter', res, list)
dict = PikaStdData.Dict()
dict.set('a', 1)
dict.set('b', 2)
dict.remove('b')
a = dict.get('a')
b = dict.get('b')
EXPECT_EQ('PikaStdData', a, 1)
2022-01-05 11:07:49 +08:00
num = 0
i = 2
for i in range(2,30):
j=2
is_prime = 1
for j in range(2,i):
if i%j==0 :
is_prime = 0
break
if is_prime:
num = num + i
2022-01-05 11:09:17 +08:00
EXPECT_EQ('prime_number_30', num, 129)
2022-01-05 11:07:49 +08:00
print('====================')
print('[Unit Tests Succeed]')
print('====================')
print('mem used max:')
2022-01-11 20:23:25 +08:00
mem.max()
print("test\r\n\r\n")
print("end\r\n")