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"