-
Notifications
You must be signed in to change notification settings - Fork 19
/
run_tests.sh
55 lines (44 loc) · 1.07 KB
/
run_tests.sh
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
#!/bin/bash
# Function to compile a C++ file
compile_cpp() {
local filename="$1"
g++ -o "$filename" "$filename.cpp" # Compile the C++ file
if [[ $? -ne 0 ]]; then
echo "Error compiling $filename.cpp"
exit 1
fi
chmod +x "$filename" # Add execute permission to the compiled executable
}
# Function to compare outputs
compare_outputs() {
if diff brute_out.txt sol_out.txt >/dev/null 2>&1; then
let test_case_number+=1
echo "Test case $test_case_number passed, running again..."
else
echo "Wrong answer on following input:"
cat in.txt
echo "Expected output:"
cat brute_out.txt
echo "Your output:"
cat sol_out.txt
exit 1
fi
}
# Initialize test case counter
test_case_number=0
# Loop until wrong answer is found
while true; do
# Compile gen.cpp
compile_cpp gen
# Generate input
./gen > in.txt
# Compile brute.cpp and sol.cpp
compile_cpp brute
compile_cpp sol
# Run brute force solution
./brute < in.txt > brute_out.txt
# Run your solution
./sol < in.txt > sol_out.txt
# Compare outputs
compare_outputs
done