-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnum-test
executable file
·132 lines (107 loc) · 8.19 KB
/
num-test
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
127
128
129
130
131
132
#!/bin/sh
passed=0
total=0
assert_within_tol() {
expect="$1"; actual="$2"; msg="$3"
tol="0.00001";
let "total += 1"
if [ $(echo "$expect-$actual < $tol && $expect-$actual > -$tol" | bc -l) == "1" ]; then
let "passed += 1"
echo "assert_within_tol $msg expect:$expect actual:$actual SUCCESS"
else
echo "assert_within_tol $msg expect:$expect actual:$actual FAILURE"
fi
}
assert_eq() {
expect="$1"; actual="$2"; msg="$3"
let "total += 1"
if [ "$expect" == "$actual" ]; then
let "passed += 1"
echo "assert_eq $msg expect:$expect actual:$actual SUCCESS"
else
echo "assert_eq $msg expect:$expect actual:$actual FAILURE"
fi
}
assert_eq_todo() {
assert_eq "TODO" "$2" "$3"
}
x=$(echo "1 2 4" | ./num all) && assert_eq "1 2 4" "$x" "all"
x=$(echo "1 2 4" | ./num first) && assert_eq 1 "$x" "first"
x=$(echo "1 2 4" | ./num last) && assert_eq 4 "$x" "last"
x=$(echo "1 2 4" | ./num n) && assert_eq 3 "$x" "n"
x=$(echo "1 2 4" | ./num count) && assert_eq 3 "$x" "count"
x=$(echo "1 2 4" | ./num length) && assert_eq 3 "$x" "length"
x=$(echo "1 2 4" | ./num minimum) && assert_eq 1 "$x" "minimum"
x=$(echo "1 2 4" | ./num min) && assert_eq 1 "$x" "min"
x=$(echo "1 2 4" | ./num maximum) && assert_eq 4 "$x" "maximum"
x=$(echo "1 2 4" | ./num max) && assert_eq 4 "$x" "max"
x=$(echo "1 2 4" | ./num range) && assert_eq 3 "$x" "range"
x=$(echo "1 2 4" | ./num spread) && assert_eq 3 "$x" "spread"
x=$(echo "1 2 4" | ./num sum) && assert_eq 7 "$x" "sum"
x=$(echo "1 2 4" | ./num total) && assert_eq 7 "$x" "total"
x=$(echo "1 2 4" | ./num mean) && assert_within_tol 2.33333 "$x" "mean"
x=$(echo "1 2 4" | ./num average) && assert_within_tol 2.33333 "$x" "average"
x=$(echo "1 2 4" | ./num avg) && assert_within_tol 2.33333 "$x" "avg"
x=$(echo "1 2 4" | ./num median) && assert_eq 2 "$x" "median with exact"
x=$(echo "1 2 4" | ./num med) && assert_eq 2 "$x" "med with exact"
x=$(echo "1 2 3 4" | ./num median) && assert_within_tol 2.5 "$x" "median with average"
x=$(echo "1 2 3 4" | ./num med) && assert_within_tol 2.5 "$x" "med with average"
x=$(echo "1 2 4" | ./num median-low) && assert_eq 2 "$x" "median-low with median"
x=$(echo "1 2 4" | ./num medianlow) && assert_eq 2 "$x" "medianlow with median"
x=$(echo "1 2 4" | ./num med-low) && assert_eq 2 "$x" "med-low with median"
x=$(echo "1 2 4" | ./num medlow) && assert_eq 2 "$x" "medlow with median"
x=$(echo "1 2 3 4" | ./num median-low) && assert_eq 2 "$x" "median-low with low"
x=$(echo "1 2 3 4" | ./num medianlow) && assert_eq 2 "$x" "medianlow with low"
x=$(echo "1 2 3 4" | ./num med-low) && assert_eq 2 "$x" "med-low with low"
x=$(echo "1 2 3 4" | ./num medlow) && assert_eq 2 "$x" "medlow with low"
x=$(echo "1 2 4" | ./num median-high) && assert_eq 2 "$x" "median-high with median"
x=$(echo "1 2 4" | ./num medianhigh) && assert_eq 2 "$x" "medianhigh with median"
x=$(echo "1 2 4" | ./num med-high) && assert_eq 2 "$x" "med-high with median"
x=$(echo "1 2 4" | ./num medhigh) && assert_eq 2 "$x" "medhigh with median"
x=$(echo "1 2 3 4" | ./num median-high) && assert_eq 3 "$x" "median-high with high"
x=$(echo "1 2 3 4" | ./num medianhigh) && assert_eq 3 "$x" "medianhigh with high"
x=$(echo "1 2 3 4" | ./num med-high) && assert_eq 3 "$x" "med-high with high"
x=$(echo "1 2 3 4" | ./num medhigh) && assert_eq 3 "$x" "medhigh with high"
x=$(echo "1 2 2 3" | ./num mode) && assert_eq "2" "$x" "modes with unimodal"
x=$(echo "1 1 2 3 3" | ./num mode) && assert_eq "1 3" "$x" "modes with bimodal"
x=$(echo "1 2 3" | ./num mode) && assert_eq "1 2 3" "$x" "modes with multimodal"
x=$(echo "1 2 2 3" | ./num modelow) && assert_eq "2" "$x" "mode-low with unimodal"
x=$(echo "1 2 2 3" | ./num mode-low) && assert_eq "2" "$x" "mode-low with unimodal"
x=$(echo "1 2 2 3" | ./num modelow) && assert_eq "2" "$x" "modelow with unimodal"
x=$(echo "1 1 2 3 3" | ./num mode-low) && assert_eq "1" "$x" "mode-low with bimodal"
x=$(echo "1 1 2 3 3" | ./num modelow) && assert_eq "1" "$x" "modelow with bimodal"
x=$(echo "1 2 3" | ./num mode-low) && assert_eq "1" "$x" "mode-low with multimodal"
x=$(echo "1 2 3" | ./num modelow) && assert_eq "1" "$x" "modelow with multimodal"
x=$(echo "1 2 2 3" | ./num mode-high) && assert_eq "2" "$x" "mode-high with unimodal"
x=$(echo "1 2 2 3" | ./num modehigh) && assert_eq "2" "$x" "modehigh with unimodal"
x=$(echo "1 1 2 3 3" | ./num mode-high) && assert_eq "3" "$x" "mode-high with bimodal"
x=$(echo "1 1 2 3 3" | ./num modehigh) && assert_eq "3" "$x" "modehigh with bimodal"
x=$(echo "1 2 3" | ./num mode-high) && assert_eq "3" "$x" "mode-high with multimodal"
x=$(echo "1 2 3" | ./num modehigh) && assert_eq "3" "$x" "modehigh with multimodal"
x=$(echo "1 2 4" | ./num sum-of-squares) && assert_within_tol 4.66667 "$x" "sum-of-squares"
x=$(echo "1 2 4" | ./num sumofsquares) && assert_within_tol 4.66667 "$x" "sumofsquares"
x=$(echo "1 2 4" | ./num sum-squares) && assert_within_tol 4.66667 "$x" "sum-squares"
x=$(echo "1 2 4" | ./num sumsquares) && assert_within_tol 4.66667 "$x" "sum-squares"
x=$(echo "1 2 4" | ./num sum2) && assert_within_tol 4.66667 "$x" "sum2"
x=$(echo "1 2 4" | ./num ss) && assert_within_tol 4.66667 "$x" "ss"
x=$(echo "1 2 4" | ./num variance) && assert_within_tol 1.55556 "$x" "variance"
x=$(echo "1 2 4" | ./num var) && assert_within_tol 1.55556 "$x" "var"
x=$(echo "1 2 4" | ./num standard-deviation) && assert_within_tol 1.24722 "$x" "standard-deviation"
x=$(echo "1 2 4" | ./num standarddeviation) && assert_within_tol 1.24722 "$x" "standarddeviation"
x=$(echo "1 2 4" | ./num stdev) && assert_within_tol 1.24722 "$x" "stdev"
x=$(echo "1 2 4" | ./num sd) && assert_within_tol 1.24722 "$x" "sd"
x=$(echo "1 2 4" | ./num coefficient-of-variance) && assert_within_tol 0.534522 "$x" "coefficient-of-variance"
x=$(echo "1 2 4" | ./num coefficientofvariance) && assert_within_tol 0.534522 "$x" "coefficientofvariance"
x=$(echo "1 2 4" | ./num coefficient-variance) && assert_within_tol 0.534522 "$x" "coefficient-variance"
x=$(echo "1 2 4" | ./num coefficientvariance) && assert_within_tol 0.534522 "$x" "coefficientvariance"
x=$(echo "1 2 4" | ./num co-var) && assert_within_tol 0.534522 "$x" "co-var"
x=$(echo "1 2 4" | ./num covar) && assert_within_tol 0.534522 "$x" "covar"
x=$(echo "1 2 4" | ./num cv) && assert_within_tol 0.534522 "$x" "cv"
echo "$passed tests passed of $total"
if [ "$passed" == "$total" ]; then
echo "SUCCESS"
exit 0
else
echo "FAILURE"
exit 1
fi