leet-tui 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/test_languages.sh +813 -0
- package/scripts/test_solutions/001_two_sum.c +15 -0
- package/scripts/test_solutions/001_two_sum.cpp +14 -0
- package/scripts/test_solutions/001_two_sum.js +11 -0
- package/scripts/test_solutions/001_two_sum.py +8 -0
- package/scripts/test_solutions/007_reverse_integer.c +9 -0
- package/scripts/test_solutions/007_reverse_integer.cpp +12 -0
- package/scripts/test_solutions/007_reverse_integer.js +12 -0
- package/scripts/test_solutions/007_reverse_integer.py +11 -0
- package/scripts/test_solutions/049_group_anagrams.c +14 -0
- package/scripts/test_solutions/049_group_anagrams.cpp +16 -0
- package/scripts/test_solutions/049_group_anagrams.js +9 -0
- package/scripts/test_solutions/049_group_anagrams.py +8 -0
- package/scripts/test_solutions/190_reverse_bits.c +8 -0
- package/scripts/test_solutions/190_reverse_bits.cpp +11 -0
- package/scripts/test_solutions/190_reverse_bits.js +8 -0
- package/scripts/test_solutions/190_reverse_bits.py +6 -0
- package/scripts/test_solutions/217_contains_duplicate.c +17 -0
- package/scripts/test_solutions/217_contains_duplicate.cpp +11 -0
- package/scripts/test_solutions/217_contains_duplicate.js +8 -0
- package/scripts/test_solutions/217_contains_duplicate.py +2 -0
- package/scripts/test_solutions/242_valid_anagram.c +14 -0
- package/scripts/test_solutions/242_valid_anagram.cpp +15 -0
- package/scripts/test_solutions/242_valid_anagram.js +10 -0
- package/scripts/test_solutions/242_valid_anagram.py +11 -0
- package/scripts/test_solutions/268_missing_number.c +7 -0
- package/scripts/test_solutions/268_missing_number.cpp +10 -0
- package/scripts/test_solutions/268_missing_number.js +8 -0
- package/scripts/test_solutions/268_missing_number.py +6 -0
- package/scripts/test_solutions/338_counting_bits.c +8 -0
- package/scripts/test_solutions/338_counting_bits.cpp +10 -0
- package/scripts/test_solutions/338_counting_bits.js +7 -0
- package/scripts/test_solutions/338_counting_bits.py +5 -0
- package/scripts/test_solutions/347_top_k_frequent.c +29 -0
- package/scripts/test_solutions/347_top_k_frequent.cpp +19 -0
- package/scripts/test_solutions/347_top_k_frequent.js +11 -0
- package/scripts/test_solutions/347_top_k_frequent.py +13 -0
- package/scripts/test_solutions/371_sum_of_two_integers.c +8 -0
- package/scripts/test_solutions/371_sum_of_two_integers.cpp +11 -0
- package/scripts/test_solutions/371_sum_of_two_integers.js +8 -0
- package/scripts/test_solutions/371_sum_of_two_integers.py +8 -0
|
@@ -0,0 +1,813 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Test multi-language support with 10 problems x 4 languages = 40 tests
|
|
3
|
+
# Tests JS and Python fully; C/C++ are scaffolded (manual verification recommended)
|
|
4
|
+
|
|
5
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
6
|
+
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
|
7
|
+
SOLUTIONS_DIR="$SCRIPT_DIR/test_solutions"
|
|
8
|
+
PROBLEMS_DIR="$PROJECT_DIR/problems"
|
|
9
|
+
|
|
10
|
+
# Colors for output
|
|
11
|
+
RED='\033[0;31m'
|
|
12
|
+
GREEN='\033[0;32m'
|
|
13
|
+
YELLOW='\033[1;33m'
|
|
14
|
+
NC='\033[0m' # No Color
|
|
15
|
+
|
|
16
|
+
PASSED=0
|
|
17
|
+
FAILED=0
|
|
18
|
+
SKIPPED=0
|
|
19
|
+
|
|
20
|
+
echo "========================================"
|
|
21
|
+
echo " Multi-Language Test Suite"
|
|
22
|
+
echo "========================================"
|
|
23
|
+
echo ""
|
|
24
|
+
|
|
25
|
+
# Check dependencies
|
|
26
|
+
echo "Checking dependencies..."
|
|
27
|
+
HAS_BUN=0
|
|
28
|
+
HAS_PYTHON=0
|
|
29
|
+
HAS_GCC=0
|
|
30
|
+
HAS_GPP=0
|
|
31
|
+
|
|
32
|
+
if command -v bun &> /dev/null; then
|
|
33
|
+
echo -e "${GREEN}✓${NC} bun found"
|
|
34
|
+
HAS_BUN=1
|
|
35
|
+
else
|
|
36
|
+
echo -e "${YELLOW}⚠${NC} bun not found"
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
if command -v python3 &> /dev/null; then
|
|
40
|
+
echo -e "${GREEN}✓${NC} python3 found"
|
|
41
|
+
HAS_PYTHON=1
|
|
42
|
+
else
|
|
43
|
+
echo -e "${YELLOW}⚠${NC} python3 not found"
|
|
44
|
+
fi
|
|
45
|
+
|
|
46
|
+
if command -v gcc &> /dev/null; then
|
|
47
|
+
echo -e "${GREEN}✓${NC} gcc found"
|
|
48
|
+
HAS_GCC=1
|
|
49
|
+
else
|
|
50
|
+
echo -e "${YELLOW}⚠${NC} gcc not found"
|
|
51
|
+
fi
|
|
52
|
+
|
|
53
|
+
if command -v g++ &> /dev/null; then
|
|
54
|
+
echo -e "${GREEN}✓${NC} g++ found"
|
|
55
|
+
HAS_GPP=1
|
|
56
|
+
else
|
|
57
|
+
echo -e "${YELLOW}⚠${NC} g++ not found"
|
|
58
|
+
fi
|
|
59
|
+
echo ""
|
|
60
|
+
|
|
61
|
+
# Test JavaScript solutions
|
|
62
|
+
test_js() {
|
|
63
|
+
local padded_id=$1
|
|
64
|
+
local func=$2
|
|
65
|
+
local solution_file=$(ls "$SOLUTIONS_DIR"/${padded_id}_*.js 2>/dev/null | head -1)
|
|
66
|
+
local problem_file=$(ls "$PROBLEMS_DIR"/${padded_id}_*.json 2>/dev/null | head -1)
|
|
67
|
+
|
|
68
|
+
if [[ ! -f "$problem_file" ]]; then
|
|
69
|
+
echo -e " ${YELLOW}SKIP${NC} JS - Problem $padded_id not found"
|
|
70
|
+
SKIPPED=$((SKIPPED + 1))
|
|
71
|
+
return
|
|
72
|
+
fi
|
|
73
|
+
|
|
74
|
+
if [[ ! -f "$solution_file" ]]; then
|
|
75
|
+
echo -e " ${YELLOW}SKIP${NC} JS - Solution not found"
|
|
76
|
+
SKIPPED=$((SKIPPED + 1))
|
|
77
|
+
return
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
local solution=$(cat "$solution_file")
|
|
81
|
+
|
|
82
|
+
local test_cases=$(python3 -c "
|
|
83
|
+
import json
|
|
84
|
+
with open('$problem_file') as f:
|
|
85
|
+
p = json.load(f)
|
|
86
|
+
print(json.dumps(p['test_cases']))
|
|
87
|
+
" 2>/dev/null)
|
|
88
|
+
|
|
89
|
+
local test_file=$(mktemp /tmp/test_XXXXXX.js)
|
|
90
|
+
cat > "$test_file" << EOF
|
|
91
|
+
$solution
|
|
92
|
+
|
|
93
|
+
const testCases = $test_cases;
|
|
94
|
+
let passed = 0;
|
|
95
|
+
let failed = 0;
|
|
96
|
+
|
|
97
|
+
// Normalize for order-independent comparison (for problems like groupAnagrams)
|
|
98
|
+
const normalize = (val) => {
|
|
99
|
+
if (!Array.isArray(val)) return JSON.stringify(val);
|
|
100
|
+
// Check if it's an array of arrays (like groupAnagrams output)
|
|
101
|
+
if (val.length > 0 && Array.isArray(val[0])) {
|
|
102
|
+
// Sort each inner array, then sort outer array by stringified inner
|
|
103
|
+
const sorted = val.map(inner => [...inner].sort()).sort((a, b) =>
|
|
104
|
+
JSON.stringify(a).localeCompare(JSON.stringify(b))
|
|
105
|
+
);
|
|
106
|
+
return JSON.stringify(sorted);
|
|
107
|
+
}
|
|
108
|
+
return JSON.stringify(val);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
for (const tc of testCases) {
|
|
112
|
+
const result = $func(...tc.input);
|
|
113
|
+
const resultStr = normalize(result);
|
|
114
|
+
const expectedStr = normalize(tc.expected);
|
|
115
|
+
if (resultStr === expectedStr) {
|
|
116
|
+
passed++;
|
|
117
|
+
} else {
|
|
118
|
+
failed++;
|
|
119
|
+
console.log(\`FAILED: expected=\${expectedStr}, got=\${resultStr}\`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (failed === 0) {
|
|
124
|
+
console.log(\`All \${passed} tests passed!\`);
|
|
125
|
+
process.exit(0);
|
|
126
|
+
} else {
|
|
127
|
+
console.log(\`\${failed} tests failed\`);
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|
|
130
|
+
EOF
|
|
131
|
+
|
|
132
|
+
local output
|
|
133
|
+
if output=$(bun run "$test_file" 2>&1); then
|
|
134
|
+
echo -e " ${GREEN}PASS${NC} JavaScript"
|
|
135
|
+
PASSED=$((PASSED + 1))
|
|
136
|
+
else
|
|
137
|
+
echo -e " ${RED}FAIL${NC} JavaScript"
|
|
138
|
+
echo " $output"
|
|
139
|
+
FAILED=$((FAILED + 1))
|
|
140
|
+
fi
|
|
141
|
+
rm -f "$test_file"
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
# Test Python solutions
|
|
145
|
+
test_python() {
|
|
146
|
+
local padded_id=$1
|
|
147
|
+
local func=$2
|
|
148
|
+
local solution_file=$(ls "$SOLUTIONS_DIR"/${padded_id}_*.py 2>/dev/null | head -1)
|
|
149
|
+
local problem_file=$(ls "$PROBLEMS_DIR"/${padded_id}_*.json 2>/dev/null | head -1)
|
|
150
|
+
|
|
151
|
+
if [[ ! -f "$problem_file" ]]; then
|
|
152
|
+
echo -e " ${YELLOW}SKIP${NC} Python - Problem $padded_id not found"
|
|
153
|
+
SKIPPED=$((SKIPPED + 1))
|
|
154
|
+
return
|
|
155
|
+
fi
|
|
156
|
+
|
|
157
|
+
if [[ ! -f "$solution_file" ]]; then
|
|
158
|
+
echo -e " ${YELLOW}SKIP${NC} Python - Solution not found"
|
|
159
|
+
SKIPPED=$((SKIPPED + 1))
|
|
160
|
+
return
|
|
161
|
+
fi
|
|
162
|
+
|
|
163
|
+
local solution=$(cat "$solution_file")
|
|
164
|
+
|
|
165
|
+
local test_cases=$(python3 -c "
|
|
166
|
+
import json
|
|
167
|
+
with open('$problem_file') as f:
|
|
168
|
+
p = json.load(f)
|
|
169
|
+
print(json.dumps(p['test_cases']))
|
|
170
|
+
" 2>/dev/null)
|
|
171
|
+
|
|
172
|
+
local test_file=$(mktemp /tmp/test_XXXXXX.py)
|
|
173
|
+
cat > "$test_file" << EOF
|
|
174
|
+
import json
|
|
175
|
+
|
|
176
|
+
$solution
|
|
177
|
+
|
|
178
|
+
test_cases = json.loads('''$test_cases''')
|
|
179
|
+
passed = 0
|
|
180
|
+
failed = 0
|
|
181
|
+
|
|
182
|
+
# Normalize for order-independent comparison (for problems like groupAnagrams)
|
|
183
|
+
def normalize(val):
|
|
184
|
+
if not isinstance(val, list):
|
|
185
|
+
return json.dumps(val, sort_keys=True)
|
|
186
|
+
# Check if it's a list of lists (like groupAnagrams output)
|
|
187
|
+
if len(val) > 0 and isinstance(val[0], list):
|
|
188
|
+
# Sort each inner list, then sort outer list by stringified inner
|
|
189
|
+
sorted_val = sorted([sorted(inner) for inner in val], key=lambda x: json.dumps(x))
|
|
190
|
+
return json.dumps(sorted_val, sort_keys=True)
|
|
191
|
+
return json.dumps(val, sort_keys=True)
|
|
192
|
+
|
|
193
|
+
for tc in test_cases:
|
|
194
|
+
result = $func(*tc["input"])
|
|
195
|
+
result_str = normalize(result)
|
|
196
|
+
expected_str = normalize(tc["expected"])
|
|
197
|
+
if result_str == expected_str:
|
|
198
|
+
passed += 1
|
|
199
|
+
else:
|
|
200
|
+
failed += 1
|
|
201
|
+
print(f"FAILED: expected={expected_str}, got={result_str}")
|
|
202
|
+
|
|
203
|
+
if failed == 0:
|
|
204
|
+
print(f"All {passed} tests passed!")
|
|
205
|
+
exit(0)
|
|
206
|
+
else:
|
|
207
|
+
print(f"{failed} tests failed")
|
|
208
|
+
exit(1)
|
|
209
|
+
EOF
|
|
210
|
+
|
|
211
|
+
local output
|
|
212
|
+
if output=$(python3 "$test_file" 2>&1); then
|
|
213
|
+
echo -e " ${GREEN}PASS${NC} Python"
|
|
214
|
+
PASSED=$((PASSED + 1))
|
|
215
|
+
else
|
|
216
|
+
echo -e " ${RED}FAIL${NC} Python"
|
|
217
|
+
echo " $output"
|
|
218
|
+
FAILED=$((FAILED + 1))
|
|
219
|
+
fi
|
|
220
|
+
rm -f "$test_file"
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
# Test C solutions
|
|
224
|
+
test_c() {
|
|
225
|
+
local padded_id=$1
|
|
226
|
+
local func=$2
|
|
227
|
+
local solution_file=$(ls "$SOLUTIONS_DIR"/${padded_id}_*.c 2>/dev/null | head -1)
|
|
228
|
+
|
|
229
|
+
if [[ ! -f "$solution_file" ]]; then
|
|
230
|
+
echo -e " ${YELLOW}SKIP${NC} C - Solution not found"
|
|
231
|
+
SKIPPED=$((SKIPPED + 1))
|
|
232
|
+
return
|
|
233
|
+
fi
|
|
234
|
+
|
|
235
|
+
local solution=$(cat "$solution_file")
|
|
236
|
+
local test_file=$(mktemp /tmp/test_XXXXXX.c)
|
|
237
|
+
local bin_file=$(mktemp /tmp/test_bin_XXXXXX)
|
|
238
|
+
|
|
239
|
+
# Generate problem-specific test harness
|
|
240
|
+
case "$padded_id" in
|
|
241
|
+
"001") # twoSum
|
|
242
|
+
cat > "$test_file" << 'CEOF'
|
|
243
|
+
#include <stdio.h>
|
|
244
|
+
#include <stdlib.h>
|
|
245
|
+
#include <string.h>
|
|
246
|
+
CEOF
|
|
247
|
+
echo "$solution" >> "$test_file"
|
|
248
|
+
cat >> "$test_file" << 'CEOF'
|
|
249
|
+
int main() {
|
|
250
|
+
int passed = 0, failed = 0;
|
|
251
|
+
// Test 1: [2,7,11,15], 9 -> [0,1]
|
|
252
|
+
int nums1[] = {2, 7, 11, 15}; int returnSize1;
|
|
253
|
+
int* res1 = twoSum(nums1, 4, 9, &returnSize1);
|
|
254
|
+
if (returnSize1 == 2 && res1[0] == 0 && res1[1] == 1) passed++; else failed++;
|
|
255
|
+
free(res1);
|
|
256
|
+
// Test 2: [3,2,4], 6 -> [1,2]
|
|
257
|
+
int nums2[] = {3, 2, 4}; int returnSize2;
|
|
258
|
+
int* res2 = twoSum(nums2, 3, 6, &returnSize2);
|
|
259
|
+
if (returnSize2 == 2 && res2[0] == 1 && res2[1] == 2) passed++; else failed++;
|
|
260
|
+
free(res2);
|
|
261
|
+
// Test 3: [3,3], 6 -> [0,1]
|
|
262
|
+
int nums3[] = {3, 3}; int returnSize3;
|
|
263
|
+
int* res3 = twoSum(nums3, 2, 6, &returnSize3);
|
|
264
|
+
if (returnSize3 == 2 && res3[0] == 0 && res3[1] == 1) passed++; else failed++;
|
|
265
|
+
free(res3);
|
|
266
|
+
if (failed == 0) { printf("All %d tests passed!\n", passed); return 0; }
|
|
267
|
+
else { printf("%d tests failed\n", failed); return 1; }
|
|
268
|
+
}
|
|
269
|
+
CEOF
|
|
270
|
+
;;
|
|
271
|
+
"217") # containsDuplicate
|
|
272
|
+
cat > "$test_file" << 'CEOF'
|
|
273
|
+
#include <stdio.h>
|
|
274
|
+
#include <stdlib.h>
|
|
275
|
+
#include <stdbool.h>
|
|
276
|
+
#include <string.h>
|
|
277
|
+
CEOF
|
|
278
|
+
echo "$solution" >> "$test_file"
|
|
279
|
+
cat >> "$test_file" << 'CEOF'
|
|
280
|
+
int main() {
|
|
281
|
+
int passed = 0, failed = 0;
|
|
282
|
+
int nums1[] = {1, 2, 3, 1};
|
|
283
|
+
if (containsDuplicate(nums1, 4) == true) passed++; else failed++;
|
|
284
|
+
int nums2[] = {1, 2, 3, 4};
|
|
285
|
+
if (containsDuplicate(nums2, 4) == false) passed++; else failed++;
|
|
286
|
+
int nums3[] = {1, 1, 1, 3, 3, 4, 3, 2, 4, 2};
|
|
287
|
+
if (containsDuplicate(nums3, 10) == true) passed++; else failed++;
|
|
288
|
+
if (failed == 0) { printf("All %d tests passed!\n", passed); return 0; }
|
|
289
|
+
else { printf("%d tests failed\n", failed); return 1; }
|
|
290
|
+
}
|
|
291
|
+
CEOF
|
|
292
|
+
;;
|
|
293
|
+
"242") # isAnagram
|
|
294
|
+
cat > "$test_file" << 'CEOF'
|
|
295
|
+
#include <stdio.h>
|
|
296
|
+
#include <stdlib.h>
|
|
297
|
+
#include <stdbool.h>
|
|
298
|
+
#include <string.h>
|
|
299
|
+
CEOF
|
|
300
|
+
echo "$solution" >> "$test_file"
|
|
301
|
+
cat >> "$test_file" << 'CEOF'
|
|
302
|
+
int main() {
|
|
303
|
+
int passed = 0, failed = 0;
|
|
304
|
+
if (isAnagram("anagram", "nagaram") == true) passed++; else failed++;
|
|
305
|
+
if (isAnagram("rat", "car") == false) passed++; else failed++;
|
|
306
|
+
if (isAnagram("a", "ab") == false) passed++; else failed++;
|
|
307
|
+
if (failed == 0) { printf("All %d tests passed!\n", passed); return 0; }
|
|
308
|
+
else { printf("%d tests failed\n", failed); return 1; }
|
|
309
|
+
}
|
|
310
|
+
CEOF
|
|
311
|
+
;;
|
|
312
|
+
"049") # groupAnagrams - complex, skip for C
|
|
313
|
+
echo -e " ${YELLOW}SKIP${NC} C - groupAnagrams requires complex memory management"
|
|
314
|
+
SKIPPED=$((SKIPPED + 1))
|
|
315
|
+
rm -f "$test_file" "$bin_file"
|
|
316
|
+
return
|
|
317
|
+
;;
|
|
318
|
+
"347") # topKFrequent
|
|
319
|
+
cat > "$test_file" << 'CEOF'
|
|
320
|
+
#include <stdio.h>
|
|
321
|
+
#include <stdlib.h>
|
|
322
|
+
CEOF
|
|
323
|
+
echo "$solution" >> "$test_file"
|
|
324
|
+
cat >> "$test_file" << 'CEOF'
|
|
325
|
+
int arrContains(int* arr, int size, int val) {
|
|
326
|
+
for (int i = 0; i < size; i++) if (arr[i] == val) return 1;
|
|
327
|
+
return 0;
|
|
328
|
+
}
|
|
329
|
+
int main() {
|
|
330
|
+
int passed = 0, failed = 0;
|
|
331
|
+
int returnSize1;
|
|
332
|
+
int nums1[] = {1, 1, 1, 2, 2, 3};
|
|
333
|
+
int* res1 = topKFrequent(nums1, 6, 2, &returnSize1);
|
|
334
|
+
if (returnSize1 == 2 && arrContains(res1, 2, 1) && arrContains(res1, 2, 2)) passed++; else failed++;
|
|
335
|
+
free(res1);
|
|
336
|
+
int returnSize2;
|
|
337
|
+
int nums2[] = {1};
|
|
338
|
+
int* res2 = topKFrequent(nums2, 1, 1, &returnSize2);
|
|
339
|
+
if (returnSize2 == 1 && res2[0] == 1) passed++; else failed++;
|
|
340
|
+
free(res2);
|
|
341
|
+
if (failed == 0) { printf("All %d tests passed!\n", passed); return 0; }
|
|
342
|
+
else { printf("%d tests failed\n", failed); return 1; }
|
|
343
|
+
}
|
|
344
|
+
CEOF
|
|
345
|
+
;;
|
|
346
|
+
"338") # countBits
|
|
347
|
+
cat > "$test_file" << 'CEOF'
|
|
348
|
+
#include <stdio.h>
|
|
349
|
+
#include <stdlib.h>
|
|
350
|
+
CEOF
|
|
351
|
+
echo "$solution" >> "$test_file"
|
|
352
|
+
cat >> "$test_file" << 'CEOF'
|
|
353
|
+
int main() {
|
|
354
|
+
int passed = 0, failed = 0;
|
|
355
|
+
int returnSize1;
|
|
356
|
+
int* res1 = countBits(2, &returnSize1);
|
|
357
|
+
int exp1[] = {0, 1, 1};
|
|
358
|
+
int ok1 = (returnSize1 == 3);
|
|
359
|
+
for (int i = 0; ok1 && i < 3; i++) if (res1[i] != exp1[i]) ok1 = 0;
|
|
360
|
+
if (ok1) passed++; else failed++;
|
|
361
|
+
free(res1);
|
|
362
|
+
int returnSize2;
|
|
363
|
+
int* res2 = countBits(5, &returnSize2);
|
|
364
|
+
int exp2[] = {0, 1, 1, 2, 1, 2};
|
|
365
|
+
int ok2 = (returnSize2 == 6);
|
|
366
|
+
for (int i = 0; ok2 && i < 6; i++) if (res2[i] != exp2[i]) ok2 = 0;
|
|
367
|
+
if (ok2) passed++; else failed++;
|
|
368
|
+
free(res2);
|
|
369
|
+
if (failed == 0) { printf("All %d tests passed!\n", passed); return 0; }
|
|
370
|
+
else { printf("%d tests failed\n", failed); return 1; }
|
|
371
|
+
}
|
|
372
|
+
CEOF
|
|
373
|
+
;;
|
|
374
|
+
"190") # reverseBits
|
|
375
|
+
cat > "$test_file" << 'CEOF'
|
|
376
|
+
#include <stdio.h>
|
|
377
|
+
#include <stdint.h>
|
|
378
|
+
CEOF
|
|
379
|
+
echo "$solution" >> "$test_file"
|
|
380
|
+
cat >> "$test_file" << 'CEOF'
|
|
381
|
+
int main() {
|
|
382
|
+
int passed = 0, failed = 0;
|
|
383
|
+
if (reverseBits(43261596) == 964176192) passed++; else failed++;
|
|
384
|
+
if (reverseBits(3) == 3221225472U) passed++; else failed++;
|
|
385
|
+
if (failed == 0) { printf("All %d tests passed!\n", passed); return 0; }
|
|
386
|
+
else { printf("%d tests failed\n", failed); return 1; }
|
|
387
|
+
}
|
|
388
|
+
CEOF
|
|
389
|
+
;;
|
|
390
|
+
"268") # missingNumber
|
|
391
|
+
cat > "$test_file" << 'CEOF'
|
|
392
|
+
#include <stdio.h>
|
|
393
|
+
CEOF
|
|
394
|
+
echo "$solution" >> "$test_file"
|
|
395
|
+
cat >> "$test_file" << 'CEOF'
|
|
396
|
+
int main() {
|
|
397
|
+
int passed = 0, failed = 0;
|
|
398
|
+
int nums1[] = {3, 0, 1};
|
|
399
|
+
if (missingNumber(nums1, 3) == 2) passed++; else failed++;
|
|
400
|
+
int nums2[] = {0, 1};
|
|
401
|
+
if (missingNumber(nums2, 2) == 2) passed++; else failed++;
|
|
402
|
+
int nums3[] = {9, 6, 4, 2, 3, 5, 7, 0, 1};
|
|
403
|
+
if (missingNumber(nums3, 9) == 8) passed++; else failed++;
|
|
404
|
+
if (failed == 0) { printf("All %d tests passed!\n", passed); return 0; }
|
|
405
|
+
else { printf("%d tests failed\n", failed); return 1; }
|
|
406
|
+
}
|
|
407
|
+
CEOF
|
|
408
|
+
;;
|
|
409
|
+
"371") # getSum
|
|
410
|
+
cat > "$test_file" << 'CEOF'
|
|
411
|
+
#include <stdio.h>
|
|
412
|
+
CEOF
|
|
413
|
+
echo "$solution" >> "$test_file"
|
|
414
|
+
cat >> "$test_file" << 'CEOF'
|
|
415
|
+
int main() {
|
|
416
|
+
int passed = 0, failed = 0;
|
|
417
|
+
if (getSum(1, 2) == 3) passed++; else failed++;
|
|
418
|
+
if (getSum(20, 30) == 50) passed++; else failed++;
|
|
419
|
+
if (getSum(-1, 1) == 0) passed++; else failed++;
|
|
420
|
+
if (failed == 0) { printf("All %d tests passed!\n", passed); return 0; }
|
|
421
|
+
else { printf("%d tests failed\n", failed); return 1; }
|
|
422
|
+
}
|
|
423
|
+
CEOF
|
|
424
|
+
;;
|
|
425
|
+
"007") # reverse
|
|
426
|
+
cat > "$test_file" << 'CEOF'
|
|
427
|
+
#include <stdio.h>
|
|
428
|
+
#include <limits.h>
|
|
429
|
+
CEOF
|
|
430
|
+
echo "$solution" >> "$test_file"
|
|
431
|
+
cat >> "$test_file" << 'CEOF'
|
|
432
|
+
int main() {
|
|
433
|
+
int passed = 0, failed = 0;
|
|
434
|
+
if (reverse(123) == 321) passed++; else failed++;
|
|
435
|
+
if (reverse(-123) == -321) passed++; else failed++;
|
|
436
|
+
if (reverse(120) == 21) passed++; else failed++;
|
|
437
|
+
if (reverse(0) == 0) passed++; else failed++;
|
|
438
|
+
if (reverse(1534236469) == 0) passed++; else failed++;
|
|
439
|
+
if (failed == 0) { printf("All %d tests passed!\n", passed); return 0; }
|
|
440
|
+
else { printf("%d tests failed\n", failed); return 1; }
|
|
441
|
+
}
|
|
442
|
+
CEOF
|
|
443
|
+
;;
|
|
444
|
+
*)
|
|
445
|
+
echo -e " ${YELLOW}SKIP${NC} C - No test harness for problem $padded_id"
|
|
446
|
+
SKIPPED=$((SKIPPED + 1))
|
|
447
|
+
rm -f "$test_file" "$bin_file"
|
|
448
|
+
return
|
|
449
|
+
;;
|
|
450
|
+
esac
|
|
451
|
+
|
|
452
|
+
local output
|
|
453
|
+
if output=$(gcc -O2 -o "$bin_file" "$test_file" 2>&1); then
|
|
454
|
+
if output=$("$bin_file" 2>&1); then
|
|
455
|
+
echo -e " ${GREEN}PASS${NC} C"
|
|
456
|
+
PASSED=$((PASSED + 1))
|
|
457
|
+
else
|
|
458
|
+
echo -e " ${RED}FAIL${NC} C"
|
|
459
|
+
echo " $output"
|
|
460
|
+
FAILED=$((FAILED + 1))
|
|
461
|
+
fi
|
|
462
|
+
else
|
|
463
|
+
echo -e " ${RED}FAIL${NC} C (compilation error)"
|
|
464
|
+
echo " $output"
|
|
465
|
+
FAILED=$((FAILED + 1))
|
|
466
|
+
fi
|
|
467
|
+
rm -f "$test_file" "$bin_file"
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
# Test C++ solutions
|
|
471
|
+
test_cpp() {
|
|
472
|
+
local padded_id=$1
|
|
473
|
+
local func=$2
|
|
474
|
+
local solution_file=$(ls "$SOLUTIONS_DIR"/${padded_id}_*.cpp 2>/dev/null | head -1)
|
|
475
|
+
|
|
476
|
+
if [[ ! -f "$solution_file" ]]; then
|
|
477
|
+
echo -e " ${YELLOW}SKIP${NC} C++ - Solution not found"
|
|
478
|
+
SKIPPED=$((SKIPPED + 1))
|
|
479
|
+
return
|
|
480
|
+
fi
|
|
481
|
+
|
|
482
|
+
local solution=$(cat "$solution_file")
|
|
483
|
+
local test_file=$(mktemp /tmp/test_XXXXXX.cpp)
|
|
484
|
+
local bin_file=$(mktemp /tmp/test_bin_XXXXXX)
|
|
485
|
+
|
|
486
|
+
# Generate problem-specific test harness
|
|
487
|
+
case "$padded_id" in
|
|
488
|
+
"001") # twoSum
|
|
489
|
+
cat > "$test_file" << 'CPPEOF'
|
|
490
|
+
#include <iostream>
|
|
491
|
+
#include <vector>
|
|
492
|
+
#include <unordered_map>
|
|
493
|
+
using namespace std;
|
|
494
|
+
CPPEOF
|
|
495
|
+
echo "$solution" >> "$test_file"
|
|
496
|
+
cat >> "$test_file" << 'CPPEOF'
|
|
497
|
+
int main() {
|
|
498
|
+
Solution s;
|
|
499
|
+
int passed = 0, failed = 0;
|
|
500
|
+
vector<int> nums1 = {2, 7, 11, 15};
|
|
501
|
+
vector<int> res1 = s.twoSum(nums1, 9);
|
|
502
|
+
if (res1.size() == 2 && res1[0] == 0 && res1[1] == 1) passed++; else failed++;
|
|
503
|
+
vector<int> nums2 = {3, 2, 4};
|
|
504
|
+
vector<int> res2 = s.twoSum(nums2, 6);
|
|
505
|
+
if (res2.size() == 2 && res2[0] == 1 && res2[1] == 2) passed++; else failed++;
|
|
506
|
+
vector<int> nums3 = {3, 3};
|
|
507
|
+
vector<int> res3 = s.twoSum(nums3, 6);
|
|
508
|
+
if (res3.size() == 2 && res3[0] == 0 && res3[1] == 1) passed++; else failed++;
|
|
509
|
+
if (failed == 0) { cout << "All " << passed << " tests passed!" << endl; return 0; }
|
|
510
|
+
else { cout << failed << " tests failed" << endl; return 1; }
|
|
511
|
+
}
|
|
512
|
+
CPPEOF
|
|
513
|
+
;;
|
|
514
|
+
"217") # containsDuplicate
|
|
515
|
+
cat > "$test_file" << 'CPPEOF'
|
|
516
|
+
#include <iostream>
|
|
517
|
+
#include <vector>
|
|
518
|
+
#include <unordered_set>
|
|
519
|
+
using namespace std;
|
|
520
|
+
CPPEOF
|
|
521
|
+
echo "$solution" >> "$test_file"
|
|
522
|
+
cat >> "$test_file" << 'CPPEOF'
|
|
523
|
+
int main() {
|
|
524
|
+
Solution s;
|
|
525
|
+
int passed = 0, failed = 0;
|
|
526
|
+
vector<int> nums1 = {1, 2, 3, 1};
|
|
527
|
+
if (s.containsDuplicate(nums1) == true) passed++; else failed++;
|
|
528
|
+
vector<int> nums2 = {1, 2, 3, 4};
|
|
529
|
+
if (s.containsDuplicate(nums2) == false) passed++; else failed++;
|
|
530
|
+
vector<int> nums3 = {1, 1, 1, 3, 3, 4, 3, 2, 4, 2};
|
|
531
|
+
if (s.containsDuplicate(nums3) == true) passed++; else failed++;
|
|
532
|
+
if (failed == 0) { cout << "All " << passed << " tests passed!" << endl; return 0; }
|
|
533
|
+
else { cout << failed << " tests failed" << endl; return 1; }
|
|
534
|
+
}
|
|
535
|
+
CPPEOF
|
|
536
|
+
;;
|
|
537
|
+
"242") # isAnagram
|
|
538
|
+
cat > "$test_file" << 'CPPEOF'
|
|
539
|
+
#include <iostream>
|
|
540
|
+
#include <string>
|
|
541
|
+
using namespace std;
|
|
542
|
+
CPPEOF
|
|
543
|
+
echo "$solution" >> "$test_file"
|
|
544
|
+
cat >> "$test_file" << 'CPPEOF'
|
|
545
|
+
int main() {
|
|
546
|
+
Solution s;
|
|
547
|
+
int passed = 0, failed = 0;
|
|
548
|
+
if (s.isAnagram("anagram", "nagaram") == true) passed++; else failed++;
|
|
549
|
+
if (s.isAnagram("rat", "car") == false) passed++; else failed++;
|
|
550
|
+
if (s.isAnagram("a", "ab") == false) passed++; else failed++;
|
|
551
|
+
if (failed == 0) { cout << "All " << passed << " tests passed!" << endl; return 0; }
|
|
552
|
+
else { cout << failed << " tests failed" << endl; return 1; }
|
|
553
|
+
}
|
|
554
|
+
CPPEOF
|
|
555
|
+
;;
|
|
556
|
+
"049") # groupAnagrams
|
|
557
|
+
cat > "$test_file" << 'CPPEOF'
|
|
558
|
+
#include <iostream>
|
|
559
|
+
#include <vector>
|
|
560
|
+
#include <string>
|
|
561
|
+
#include <unordered_map>
|
|
562
|
+
#include <algorithm>
|
|
563
|
+
using namespace std;
|
|
564
|
+
CPPEOF
|
|
565
|
+
echo "$solution" >> "$test_file"
|
|
566
|
+
cat >> "$test_file" << 'CPPEOF'
|
|
567
|
+
vector<vector<string>> normalize(vector<vector<string>> v) {
|
|
568
|
+
for (auto& inner : v) sort(inner.begin(), inner.end());
|
|
569
|
+
sort(v.begin(), v.end());
|
|
570
|
+
return v;
|
|
571
|
+
}
|
|
572
|
+
int main() {
|
|
573
|
+
Solution s;
|
|
574
|
+
int passed = 0, failed = 0;
|
|
575
|
+
vector<string> strs1 = {"eat", "tea", "tan", "ate", "nat", "bat"};
|
|
576
|
+
auto res1 = normalize(s.groupAnagrams(strs1));
|
|
577
|
+
vector<vector<string>> exp1 = {{"ate", "eat", "tea"}, {"bat"}, {"nat", "tan"}};
|
|
578
|
+
if (res1 == normalize(exp1)) passed++; else failed++;
|
|
579
|
+
vector<string> strs2 = {""};
|
|
580
|
+
auto res2 = normalize(s.groupAnagrams(strs2));
|
|
581
|
+
vector<vector<string>> exp2 = {{""}};
|
|
582
|
+
if (res2 == normalize(exp2)) passed++; else failed++;
|
|
583
|
+
vector<string> strs3 = {"a"};
|
|
584
|
+
auto res3 = normalize(s.groupAnagrams(strs3));
|
|
585
|
+
vector<vector<string>> exp3 = {{"a"}};
|
|
586
|
+
if (res3 == normalize(exp3)) passed++; else failed++;
|
|
587
|
+
if (failed == 0) { cout << "All " << passed << " tests passed!" << endl; return 0; }
|
|
588
|
+
else { cout << failed << " tests failed" << endl; return 1; }
|
|
589
|
+
}
|
|
590
|
+
CPPEOF
|
|
591
|
+
;;
|
|
592
|
+
"347") # topKFrequent
|
|
593
|
+
cat > "$test_file" << 'CPPEOF'
|
|
594
|
+
#include <iostream>
|
|
595
|
+
#include <vector>
|
|
596
|
+
#include <unordered_map>
|
|
597
|
+
#include <algorithm>
|
|
598
|
+
using namespace std;
|
|
599
|
+
CPPEOF
|
|
600
|
+
echo "$solution" >> "$test_file"
|
|
601
|
+
cat >> "$test_file" << 'CPPEOF'
|
|
602
|
+
bool contains(vector<int>& v, int val) {
|
|
603
|
+
return find(v.begin(), v.end(), val) != v.end();
|
|
604
|
+
}
|
|
605
|
+
int main() {
|
|
606
|
+
Solution s;
|
|
607
|
+
int passed = 0, failed = 0;
|
|
608
|
+
vector<int> nums1 = {1, 1, 1, 2, 2, 3};
|
|
609
|
+
auto res1 = s.topKFrequent(nums1, 2);
|
|
610
|
+
if (res1.size() == 2 && contains(res1, 1) && contains(res1, 2)) passed++; else failed++;
|
|
611
|
+
vector<int> nums2 = {1};
|
|
612
|
+
auto res2 = s.topKFrequent(nums2, 1);
|
|
613
|
+
if (res2.size() == 1 && res2[0] == 1) passed++; else failed++;
|
|
614
|
+
if (failed == 0) { cout << "All " << passed << " tests passed!" << endl; return 0; }
|
|
615
|
+
else { cout << failed << " tests failed" << endl; return 1; }
|
|
616
|
+
}
|
|
617
|
+
CPPEOF
|
|
618
|
+
;;
|
|
619
|
+
"338") # countBits
|
|
620
|
+
cat > "$test_file" << 'CPPEOF'
|
|
621
|
+
#include <iostream>
|
|
622
|
+
#include <vector>
|
|
623
|
+
using namespace std;
|
|
624
|
+
CPPEOF
|
|
625
|
+
echo "$solution" >> "$test_file"
|
|
626
|
+
cat >> "$test_file" << 'CPPEOF'
|
|
627
|
+
int main() {
|
|
628
|
+
Solution s;
|
|
629
|
+
int passed = 0, failed = 0;
|
|
630
|
+
vector<int> res1 = s.countBits(2);
|
|
631
|
+
vector<int> exp1 = {0, 1, 1};
|
|
632
|
+
if (res1 == exp1) passed++; else failed++;
|
|
633
|
+
vector<int> res2 = s.countBits(5);
|
|
634
|
+
vector<int> exp2 = {0, 1, 1, 2, 1, 2};
|
|
635
|
+
if (res2 == exp2) passed++; else failed++;
|
|
636
|
+
if (failed == 0) { cout << "All " << passed << " tests passed!" << endl; return 0; }
|
|
637
|
+
else { cout << failed << " tests failed" << endl; return 1; }
|
|
638
|
+
}
|
|
639
|
+
CPPEOF
|
|
640
|
+
;;
|
|
641
|
+
"190") # reverseBits
|
|
642
|
+
cat > "$test_file" << 'CPPEOF'
|
|
643
|
+
#include <iostream>
|
|
644
|
+
#include <cstdint>
|
|
645
|
+
using namespace std;
|
|
646
|
+
CPPEOF
|
|
647
|
+
echo "$solution" >> "$test_file"
|
|
648
|
+
cat >> "$test_file" << 'CPPEOF'
|
|
649
|
+
int main() {
|
|
650
|
+
Solution s;
|
|
651
|
+
int passed = 0, failed = 0;
|
|
652
|
+
if (s.reverseBits(43261596) == 964176192) passed++; else failed++;
|
|
653
|
+
if (s.reverseBits(3) == 3221225472U) passed++; else failed++;
|
|
654
|
+
if (failed == 0) { cout << "All " << passed << " tests passed!" << endl; return 0; }
|
|
655
|
+
else { cout << failed << " tests failed" << endl; return 1; }
|
|
656
|
+
}
|
|
657
|
+
CPPEOF
|
|
658
|
+
;;
|
|
659
|
+
"268") # missingNumber
|
|
660
|
+
cat > "$test_file" << 'CPPEOF'
|
|
661
|
+
#include <iostream>
|
|
662
|
+
#include <vector>
|
|
663
|
+
using namespace std;
|
|
664
|
+
CPPEOF
|
|
665
|
+
echo "$solution" >> "$test_file"
|
|
666
|
+
cat >> "$test_file" << 'CPPEOF'
|
|
667
|
+
int main() {
|
|
668
|
+
Solution s;
|
|
669
|
+
int passed = 0, failed = 0;
|
|
670
|
+
vector<int> nums1 = {3, 0, 1};
|
|
671
|
+
if (s.missingNumber(nums1) == 2) passed++; else failed++;
|
|
672
|
+
vector<int> nums2 = {0, 1};
|
|
673
|
+
if (s.missingNumber(nums2) == 2) passed++; else failed++;
|
|
674
|
+
vector<int> nums3 = {9, 6, 4, 2, 3, 5, 7, 0, 1};
|
|
675
|
+
if (s.missingNumber(nums3) == 8) passed++; else failed++;
|
|
676
|
+
if (failed == 0) { cout << "All " << passed << " tests passed!" << endl; return 0; }
|
|
677
|
+
else { cout << failed << " tests failed" << endl; return 1; }
|
|
678
|
+
}
|
|
679
|
+
CPPEOF
|
|
680
|
+
;;
|
|
681
|
+
"371") # getSum
|
|
682
|
+
cat > "$test_file" << 'CPPEOF'
|
|
683
|
+
#include <iostream>
|
|
684
|
+
using namespace std;
|
|
685
|
+
CPPEOF
|
|
686
|
+
echo "$solution" >> "$test_file"
|
|
687
|
+
cat >> "$test_file" << 'CPPEOF'
|
|
688
|
+
int main() {
|
|
689
|
+
Solution s;
|
|
690
|
+
int passed = 0, failed = 0;
|
|
691
|
+
if (s.getSum(1, 2) == 3) passed++; else failed++;
|
|
692
|
+
if (s.getSum(20, 30) == 50) passed++; else failed++;
|
|
693
|
+
if (s.getSum(-1, 1) == 0) passed++; else failed++;
|
|
694
|
+
if (failed == 0) { cout << "All " << passed << " tests passed!" << endl; return 0; }
|
|
695
|
+
else { cout << failed << " tests failed" << endl; return 1; }
|
|
696
|
+
}
|
|
697
|
+
CPPEOF
|
|
698
|
+
;;
|
|
699
|
+
"007") # reverse
|
|
700
|
+
cat > "$test_file" << 'CPPEOF'
|
|
701
|
+
#include <iostream>
|
|
702
|
+
#include <climits>
|
|
703
|
+
using namespace std;
|
|
704
|
+
CPPEOF
|
|
705
|
+
echo "$solution" >> "$test_file"
|
|
706
|
+
cat >> "$test_file" << 'CPPEOF'
|
|
707
|
+
int main() {
|
|
708
|
+
Solution s;
|
|
709
|
+
int passed = 0, failed = 0;
|
|
710
|
+
if (s.reverse(123) == 321) passed++; else failed++;
|
|
711
|
+
if (s.reverse(-123) == -321) passed++; else failed++;
|
|
712
|
+
if (s.reverse(120) == 21) passed++; else failed++;
|
|
713
|
+
if (s.reverse(0) == 0) passed++; else failed++;
|
|
714
|
+
if (s.reverse(1534236469) == 0) passed++; else failed++;
|
|
715
|
+
if (failed == 0) { cout << "All " << passed << " tests passed!" << endl; return 0; }
|
|
716
|
+
else { cout << failed << " tests failed" << endl; return 1; }
|
|
717
|
+
}
|
|
718
|
+
CPPEOF
|
|
719
|
+
;;
|
|
720
|
+
*)
|
|
721
|
+
echo -e " ${YELLOW}SKIP${NC} C++ - No test harness for problem $padded_id"
|
|
722
|
+
SKIPPED=$((SKIPPED + 1))
|
|
723
|
+
rm -f "$test_file" "$bin_file"
|
|
724
|
+
return
|
|
725
|
+
;;
|
|
726
|
+
esac
|
|
727
|
+
|
|
728
|
+
local output
|
|
729
|
+
if output=$(g++ -std=c++17 -O2 -o "$bin_file" "$test_file" 2>&1); then
|
|
730
|
+
if output=$("$bin_file" 2>&1); then
|
|
731
|
+
echo -e " ${GREEN}PASS${NC} C++"
|
|
732
|
+
PASSED=$((PASSED + 1))
|
|
733
|
+
else
|
|
734
|
+
echo -e " ${RED}FAIL${NC} C++"
|
|
735
|
+
echo " $output"
|
|
736
|
+
FAILED=$((FAILED + 1))
|
|
737
|
+
fi
|
|
738
|
+
else
|
|
739
|
+
echo -e " ${RED}FAIL${NC} C++ (compilation error)"
|
|
740
|
+
echo " $output"
|
|
741
|
+
FAILED=$((FAILED + 1))
|
|
742
|
+
fi
|
|
743
|
+
rm -f "$test_file" "$bin_file"
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
# Run tests for a single problem
|
|
747
|
+
run_problem_tests() {
|
|
748
|
+
local padded_id=$1
|
|
749
|
+
local func=$2
|
|
750
|
+
|
|
751
|
+
echo "Problem $padded_id ($func):"
|
|
752
|
+
|
|
753
|
+
if [[ "$HAS_BUN" == "1" ]]; then
|
|
754
|
+
test_js "$padded_id" "$func"
|
|
755
|
+
else
|
|
756
|
+
echo -e " ${YELLOW}SKIP${NC} JavaScript (bun not installed)"
|
|
757
|
+
SKIPPED=$((SKIPPED + 1))
|
|
758
|
+
fi
|
|
759
|
+
|
|
760
|
+
if [[ "$HAS_PYTHON" == "1" ]]; then
|
|
761
|
+
test_python "$padded_id" "$func"
|
|
762
|
+
else
|
|
763
|
+
echo -e " ${YELLOW}SKIP${NC} Python (python3 not installed)"
|
|
764
|
+
SKIPPED=$((SKIPPED + 1))
|
|
765
|
+
fi
|
|
766
|
+
|
|
767
|
+
if [[ "$HAS_GCC" == "1" ]]; then
|
|
768
|
+
test_c "$padded_id" "$func"
|
|
769
|
+
else
|
|
770
|
+
echo -e " ${YELLOW}SKIP${NC} C (gcc not installed)"
|
|
771
|
+
SKIPPED=$((SKIPPED + 1))
|
|
772
|
+
fi
|
|
773
|
+
|
|
774
|
+
if [[ "$HAS_GPP" == "1" ]]; then
|
|
775
|
+
test_cpp "$padded_id" "$func"
|
|
776
|
+
else
|
|
777
|
+
echo -e " ${YELLOW}SKIP${NC} C++ (g++ not installed)"
|
|
778
|
+
SKIPPED=$((SKIPPED + 1))
|
|
779
|
+
fi
|
|
780
|
+
|
|
781
|
+
echo ""
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
# Run all tests
|
|
785
|
+
run_problem_tests "001" "twoSum"
|
|
786
|
+
run_problem_tests "217" "containsDuplicate"
|
|
787
|
+
run_problem_tests "242" "isAnagram"
|
|
788
|
+
run_problem_tests "049" "groupAnagrams"
|
|
789
|
+
run_problem_tests "347" "topKFrequent"
|
|
790
|
+
run_problem_tests "338" "countBits"
|
|
791
|
+
run_problem_tests "190" "reverseBits"
|
|
792
|
+
run_problem_tests "268" "missingNumber"
|
|
793
|
+
run_problem_tests "371" "getSum"
|
|
794
|
+
run_problem_tests "007" "reverse"
|
|
795
|
+
|
|
796
|
+
echo "========================================"
|
|
797
|
+
echo " Summary"
|
|
798
|
+
echo "========================================"
|
|
799
|
+
echo -e "${GREEN}Passed:${NC} $PASSED"
|
|
800
|
+
echo -e "${RED}Failed:${NC} $FAILED"
|
|
801
|
+
echo -e "${YELLOW}Skipped:${NC} $SKIPPED"
|
|
802
|
+
echo ""
|
|
803
|
+
|
|
804
|
+
if [[ $FAILED -eq 0 && $PASSED -gt 0 ]]; then
|
|
805
|
+
echo -e "${GREEN}All executed tests passed!${NC}"
|
|
806
|
+
exit 0
|
|
807
|
+
elif [[ $FAILED -eq 0 ]]; then
|
|
808
|
+
echo -e "${YELLOW}No tests executed${NC}"
|
|
809
|
+
exit 0
|
|
810
|
+
else
|
|
811
|
+
echo -e "${RED}Some tests failed${NC}"
|
|
812
|
+
exit 1
|
|
813
|
+
fi
|