-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
155 lines (153 loc) · 3.78 KB
/
main.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
from LCSTestCase import LCSTestCase
class PrintFeedback:
def write(self, string_to_write):
print(string_to_write, end="")
test_feedback = PrintFeedback()
test_cases = [
LCSTestCase(
"ALASKAN",
"BANANAS",
{ "AAA", "AAS", "AAN" },
[
[ 0, 1, 1, 1, 1, 1, 1 ],
[ 0, 1, 1, 1, 1, 1, 1 ],
[ 0, 1, 1, 2, 2, 2, 2 ],
[ 0, 1, 1, 2, 2, 2, 3 ],
[ 0, 1, 1, 2, 2, 2, 3 ],
[ 0, 1, 1, 2, 2, 3, 3 ],
[ 0, 1, 2, 2, 3, 3, 3 ]
]
),
LCSTestCase(
"BAAB",
"ABBA",
{ "AA", "BB", "AB", "BA" },
[
# A B B A
[ 0, 1, 1, 1 ], # B
[ 1, 1, 1, 2 ], # A
[ 1, 1, 1, 2 ], # A
[ 1, 2, 2, 2 ] # B
]
),
LCSTestCase(
"ABBA",
"BAAB",
{ "AA", "BB", "AB", "BA" },
[
# B A A B
[ 0, 1, 1, 1 ], # A
[ 1, 1, 1, 2 ], # B
[ 1, 1, 1, 2 ], # B
[ 1, 2, 2, 2 ] # A
],
),
LCSTestCase(
"lower case",
"UPPER CASE",
{ " " },
[
# U P P E R C A S E
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], # l
[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E",
{ "ATIVE" }
),
LCSTestCase(
"ACTIVE",
"RELATIVELY",
{ "ATIVE" }
),
LCSTestCase(
"very very very very very very very very very long string",
"short string",
{ "o string", "r string" }
),
LCSTestCase(
"five food groups",
"dairy, vegetables, fruits, grains, and protein",
{ "ive f grp", "ive fd ro", "ive f gro", "ive f grs" }
),
LCSTestCase(
"A MAN A PLAN A CANAL PANAMA",
"THE RAIN IN SPAIN STAYS MAINLY IN THE PLAIN",
{ " AN PAN A ANL PAN" }
)
]
# Execute each test case and count the number that pass
pass_count = 0;
for test_case in test_cases:
if test_case.execute(test_feedback):
pass_count += 1
test_feedback.write("\n")
#
# Print the summary
test_feedback.write(f"{pass_count} of {len(test_cases)}")
test_feedback.write(" test cases passed\n\n")