blob: b26b9c45f727c107316683aa69997194b7ac826b (
plain)
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
|
MAX_SINT="2147483647"
MIN_SINT="-2147483648"
(( FAIL = 0 ))
(( PASS = 0 ))
run_test () {
echo "Running $1"
`$1 &>/dev/null`
if [ $? -eq 1 ]; then
echo "Failed"
(( FAIL++ ))
else
echo "Passed"
(( PASS++ ))
fi
}
################################################################################
#Integer Add #
################################################################################
#Test random add
run_test "./math-int add 1 2 3"
#Same as above with arguments reversed
run_test "./math-int add 2 1 3"
#Test negative plus positive
run_test "./math-int add -5 10 5"
#Test negative plus negative
run_test "./math-int add -1 -4 -5"
################################################################################
#Integer Multiply #
################################################################################
#Test random multiply
run_test "./math-int mul 4 5 20"
#Test multiply by 0
run_test "./math-int mul 8 0 0"
#Test multiply negative by positive
run_test "./math-int mul -3 8 -24"
#Test multiply negative by negative
run_test "./math-int mul -12 -6 72"
################################################################################
#Integer divide #
################################################################################
#Test even divide
run_test "./math-int div 20 5 4"
#Test divide with remainder
run_test "./math-int div 23 5 4"
#Test divide by 1
run_test "./math-int div 30 1 30"
#Test divide by -1
run_test "./math-int div 57 -1 -57"
#Test divide by a negative number
run_test "./math-int div 10 -2 -5"
#Test divide by a negative number with remainder
run_test "./math-int div 17 -3 -5"
#Test divide a negative number
run_test "./math-int div -28 2 -14"
#Test divide a negative number with remainder
run_test "./math-int div -8 3 -2"
#Two negative args
run_test "./math-int div -25 -5 5"
#Two nefative args with remainder
run_test "./math-int div -24 -5 4"
################################################################################
#Integer Modulo #
################################################################################
#Test Modulo is zero
run_test "./math-int mod 18 6 0"
#Test Modulo is non-zero
run_test "./math-int mod 59 12 11"
#Test arg0 negative modulo is zero
run_test "./math-int mod -20 5 0"
#Test arg0 negative modulo is non-zero (In the real world -18 % 5 = 2)
run_test "./math-int mod -18 5 -3"
#Test arg1 negative modulo is zero
run_test "./math-int mod 50 -10 0"
#Test arg1 negative modulo is non-zero (In the real world 16 % -3 = -2)
run_test "./math-int mod 16 -3 1"
#Test arg1 = MAX_SINT
run_test "./math-int mod ${MAX_SINT} 12345 9172"
#Test arg1 = MIN_SINT (In the real world MIN_SING % 476 = 348)
run_test "./math-int mod ${MIN_SINT} 476 -128"
#Test arg0 < arg1
run_test "./math-int mod 10 20 10"
#Test division paths with a constant divisor that are optimized with shifts
#(The second argument to these tests is ignored)
#Constant non-power of two divisor, modulo is zero
run_test "./math-int mod_nine 18 9 0"
#Constant non-power of two divisor, modulo is non-zero
run_test "./math-int mod_nine 23 9 5"
#Constant power of two divisor, modulo is zero
run_test "./math-int mod_four 20 4 0"
#Constant power of two divisor, modulo is non-zero
run_test "./math-int mod_four 5 4 1"
echo "$PASS passes, $FAIL fails"
|