-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
120 lines (106 loc) · 1.52 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
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
#!/bin/bash
# A simple test script, for unit-testing of the matching function of the Master Mind program
# function to check output from running $cmd against expected output
check () {
echo "Cmd: $cmd"
echo "Output: \n$out"
echo "Expected: \n$exp"
if [ "$out" = "$exp" ]
then echo ".. OK"
ok=$(( $ok + 1))
else echo "** WRONG"
ret=1
fi
n=$(( $n + 1))
}
# name of the application to run
cw=cw2
# return code; 0 = ok, anything else is an error
ret=0
ok=0
n=0
# -------------------------------------------------------
# a sequence of unit tests
cmd="./${cw} -u 123 321"
out="`$cmd`"
exp=$(cat <<EOS
1 exact
2 approximate
EOS
)
check
cmd="./${cw} -u 121 313"
out="`$cmd`"
exp=$(cat <<EOS
0 exact
1 approximate
EOS
)
check
cmd="./${cw} -u 132 321"
out="`$cmd`"
exp=$(cat <<EOS
0 exact
3 approximate
EOS
)
check
cmd="./${cw} -u 123 112"
out="`$cmd`"
exp=$(cat <<EOS
1 exact
1 approximate
EOS
)
check
cmd="./${cw} -u 112 233"
out="`$cmd`"
exp=$(cat <<EOS
0 exact
1 approximate
EOS
)
check
cmd="./${cw} -u 111 333"
out="`$cmd`"
exp=$(cat <<EOS
0 exact
0 approximate
EOS
)
check
cmd="./${cw} -u 331 223"
out="`$cmd`"
exp=$(cat <<EOS
0 exact
1 approximate
EOS
)
check
cmd="./${cw} -u 331 232"
out="`$cmd`"
exp=$(cat <<EOS
1 exact
0 approximate
EOS
)
check
cmd="./${cw} -u 232 331"
out="`$cmd`"
exp=$(cat <<EOS
1 exact
0 approximate
EOS
)
check
cmd="./${cw} -u 312 312"
out="`$cmd`"
exp=$(cat <<EOS
3 exact
0 approximate
EOS
)
check
# return status code (0 for ok, 1 for not)
echo "$ok of $n tests are OK"
exit $ret