-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_auto.py
89 lines (78 loc) · 3.35 KB
/
test_auto.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
#NATIVE MODULE
#PERSONNAL MODULE
from conf import *
from utils import *
from node import *
from token import *
from lexical_analyze import *
from synthax_analyze import *
test_natural_operator = True
test_logic_operator = True
#TEST NATURAL OPERATOR (UNAIRE & BINAIRE)
code_src_test_natural_operator = [
{"src" : "5 * 2 - 4 / 2" , "res" : 5 * 2 - 4 / 2},
{"src" : "5 * (2 - 4) / 2" , "res" : 5 * (2 - 4) / 2},
{"src" : "-5 * (-2 - 4) / 2" , "res" : -5 * (-2 - 4) / 2},
{"src" : "(5 + 5) * (3 - 1)" , "res" : (5 + 5) * (3 - 1)},
{"src" : "-55", "res" : -55},
{"src" : "--55", "res" : 55},
{"src" : "-+-55", "res" : 55},
{"src" : "!0" , "res" : 1},
{"src" : "!256" , "res" : 0},
{"src" : "!-256" , "res" : 0},
{"src" : "!!256" , "res" : 1},
{"src" : "5 ^ 2 ^ 2" , "res" : pow(5, pow(2, 2))},
{"src" : "(5 ^ 2) ^ 2" , "res" : pow(pow(5,2),2)}
]
#TEST LOGIC OPERATOR
code_src_test_logic_operator = [
#TEST SIMPLE
{"src" : "5 and 5" , "res" : 1},
{"src" : "5 == 5" , "res" : 1},
{"src" : "5 != 5" , "res" : 0},
{"src" : "5 <= 5" , "res" : 1},
{"src" : "5 >= 5" , "res" : 1},
{"src" : "5 < 6" , "res" : 1},
{"src" : "5 > 6" , "res" : 0},
{"src" : "5 <= 6" , "res" : 1},
{"src" : "5 >= 6" , "res" : 0},
{"src" : "5 or 6" , "res" : 1},
#TEST COMPLEX
{"src" : "(5 != 6) and (5 < 6)" , "res" : 1},
{"src" : "(5 != 6) and (5 > 6)" , "res" : 0},
{"src" : "(5 != 6) or (5 < 6)" , "res" : 1},
{"src" : "(5 != 6) or (5 > 6)" , "res" : 1},
{"src" : "(5 != 5) or (5 < 6)" , "res" : 1},
{"src" : "(5 != 5) or (5 > 6)" , "res" : 0},
]
if test_natural_operator :
print "==================================="
print "====== TEST NATURAL OPERATOR ======"
print "==================================="
for i in range(0,len(code_src_test_natural_operator) ) :
lexique_analyze_line(code_src_test_natural_operator[i]["src"],1)
arbre = synthax_analyse()
res = eval_expr(arbre)
if res == code_src_test_natural_operator[i]["res"] :
print "[CODE "+str(i)+"] ~ "+ '\033[92m' + "[VALIDE]"+'\033[0m'+" ~ "+code_src_test_natural_operator[i]["src"]+" [=] "+str(code_src_test_natural_operator[i]["res"])
else :
print '\033[91m' + "[CODE "+str(i)+"] ~ [ERROR] ~ "+code_src_test_natural_operator[i]["src"]+" [!=] "+str(res)+" [RES = "+str(code_src_test_natural_operator[i]["res"])+"]" + '\033[0m'
#RESET TAB
tab_token = []
index_tab = 0
print "\n \n"
if test_logic_operator :
print "==================================="
print "======= TEST LOGIC OPERATOR ======="
print "==================================="
for i in range(0,len(code_src_test_logic_operator) ) :
lexique_analyze_line(code_src_test_logic_operator[i]["src"],1)
arbre = synthax_analyse()
res = eval_expr(arbre)
if res == code_src_test_logic_operator[i]["res"] :
print "[CODE "+str(i)+"] ~ "+ '\033[92m' + "[VALIDE]"+'\033[0m'+" ~ "+code_src_test_logic_operator[i]["src"]+" [=] "+str(code_src_test_logic_operator[i]["res"])
else :
print '\033[91m' + "[CODE "+str(i)+"] ~ [ERROR] ~ "+code_src_test_logic_operator[i]["src"]+" [!=] "+str(res)+" [RES = "+str(code_src_test_logic_operator[i]["res"])+"]" + '\033[0m'
#RESET TAB
tab_token = []
index_tab = 0