-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_checker.sh
executable file
·126 lines (123 loc) · 2.62 KB
/
test_checker.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
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
#!/bin/bash
## Setup
FILE="checker"
## Constant Variable
GREEN="\033[1;32m"
GRAY="\033[1;37m"
CYAN="\033[1;36m"
BLUE="\033[1;34m"
YELLOW="\033[1;33m"
MAGENTA="\033[1;35m"
LRED="\033[1;91m"
RED="\033[1;31m"
BOLD="\033[1m"
RESET="\033[0m"
print_compare()
{
INPUT=$1
ARG=$2
EXPECT=$3
OUTPUT=$(echo -en $INPUT | ./$FILE $ARG 2>&1)
if [[ $EXPECT == "Error" ]]; then
ERR=error.log
OUTPUT=$(echo -en $INPUT | ./$FILE $ARG 2>$ERR && cat $ERR)
if [ -z $(cat $ERR) ]; then
echo -en $RED"STDERR"
elif [[ $(cat $ERR) == $EXPECT ]]; then
echo -en $GREEN"PASS"
else
echo -en $RED"FAIL"
fi
if [ -f $ERR ]; then
/bin/rm $ERR
fi
else
OUTPUT=$(echo -en $INPUT | ./$FILE $ARG 2>&1)
if [[ $OUTPUT == $EXPECT ]]; then
echo -en $GREEN"PASS"
else
echo -en $RED"FAIL"
fi
fi
echo -en $RESET
echo -en "\t$OUTPUT/$EXPECT"
echo
}
## Execute Test
echo -e $BLUE"Test Input"$RESET
printf "$BOLD%-27s%-10s%s$RESET\n" "Name" "Status" "Result/Expect"
#1
printf "1. %-25s" "Invalid \$ARG"
INPUT=""
ARG="abc"
print_compare "$INPUT" "$ARG" "Error"
#2
printf "2. %-25s" "Mixin invalid \$ARG"
INPUT=""
ARG="1 2 a"
print_compare "$INPUT" "$ARG" "Error"
#2
printf "2. %-25s" "Dupplicated \$ARG"
INPUT=""
ARG="1 2 1"
print_compare "$INPUT" "$ARG" "Error"
#4
printf "4. %-25s" "MAX_INT++"
INPUT=""
ARG="9999999999"
print_compare "$INPUT" "$ARG" "Error"
#5
printf "5. %-25s" "Mixin MAX_INT++"
INPUT=""
ARG="1 2 3 9999999999"
print_compare "$INPUT" "$ARG" "Error"
#6
printf "6. %-25s" "No \$ARG"
INPUT=""
ARG=
print_compare "$INPUT" "$ARG" ""
#7
printf "7. %-25s" "Empty \$ARG"
INPUT=""
ARG=""
print_compare "$INPUT" "$ARG" ""
#8
printf "8. %-25s" "All input"
INPUT="sa\nsb\nss\nra\nrb\nrr\nrra\nrrb\nrrr\npa\npb\n"
ARG="1 2 3"
print_compare "$INPUT" "$ARG" "KO"
#9
printf "9. %-25s" "No opteration input"
INPUT="abcd\n"
ARG="1 2 3"
print_compare "$INPUT" "$ARG" "Error"
#10
printf "10.%-25s" "Space input"
INPUT="\s\s\s\s\ssa\n"
ARG="1 2 3"
print_compare "$INPUT" "$ARG" "Error"
#11
printf "11.%-25s" "Tab input"
INPUT="sa\t\n"
ARG="1 2 3"
print_compare "$INPUT" "$ARG" "Error"
#12
printf "12.%-25s" "Newline input"
INPUT="\n"
ARG="1 2 3"
print_compare "$INPUT" "$ARG" "Error"
#13
printf "13.%-25s" "KO Test"
INPUT="sa\npb\nrrr\n"
ARG="0 9 1 8 2 7 3 6 4 5"
print_compare "$INPUT" "$ARG" "KO"
#14
printf "14.%-25s" "Sorted input"
INPUT="ra\nsa\n"
ARG="3 2 1"
print_compare "$INPUT" "$ARG" "OK"
#15
printf "15.%-25s" "OK Test"
INPUT="pb\nra\npb\nra\nsa\nra\npa\npa\n"
ARG="0 9 1 8 2"
print_compare "$INPUT" "$ARG" "OK"