-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·53 lines (47 loc) · 1.81 KB
/
test.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
#!/bin/bash
# compile code
# SRC_DIR="$(find -name setup.py -printf '%h')"
# if [ "$SRC_DIR" == "" ]; then
# echo "Can't find setup.py"
# exit 1
# fi
# TEST_DIR="$(find -name test_data)"
# if [ "$TEST_DIR" == "" ]; then
# echo "Can't find test_data"
# exit 1
# fi
SRC_DIR="./"
TEST_DIR="./test_data"
# go to SRC_DIR and compile
pushd .
cd "$SRC_DIR"
python3 setup.py build_ext --inplace
popd
while read line; do
if [ "${line}" == "" ]; then break; fi
# e.g.: 2. k=7, max_iter = not provided, eps=0, input_2_db_1, input_2_db_2
k=$((cut -d "," -f 1 | cut -d "=" -f 2 | sed "s/ //g") <<< "${line}")
max_iter=$((cut -d "," -f 2 | cut -d "=" -f 2 | sed "s/ //g") <<< "${line}")
eps=$((cut -d "," -f 3 | cut -d "=" -f 2 | sed "s/ //g") <<< "${line}")
input_1=$((cut -d "," -f 4 | cut -d "=" -f 2 | sed "s/ //g") <<< "${line}")
input_2=$((cut -d "," -f 5 | cut -d "=" -f 2 | sed "s/ //g") <<< "${line}")
expected_output=$((cut -d "." -f 1) <<< "$line")
echo "Running test ${expected_output}..."
expected_output="$TEST_DIR/output_${expected_output}.txt"
input_1="$TEST_DIR/${input_1}.txt"
input_2="$TEST_DIR/${input_2}.txt"
# run the test
if [ "$max_iter" == "notprovided" ]; then
output=$(python3 $SRC_DIR/kmeans_pp.py "$k" "$eps" "$input_1" "$input_2")
else
output=$(python3 $SRC_DIR/kmeans_pp.py "$k" "$max_iter" "$eps" "$input_1" "$input_2")
fi
if ! diff /dev/stdin "$expected_output" <<< "$output" >/dev/null; then
echo -e "\e[31mWRONG OUTPUT!\e[0m"
diff /dev/stdin "$expected_output" <<< "$output"
echo "k is $k, max_iter is $max_iter, eps is $eps"
echo "inputs are $input_1 and $input_2"
echo "correct output in $expected_output"
fi
done < <(cat "$TEST_DIR/test_readme.txt"; echo -e "\n")
echo "Done!"