Integer Arithmetic

The computer relies on arithmetic. Here we test a variety of arithmetic operations expressed as 32 bit two's complement binary numbers (Java's int).
 
eg.ArithmeticFixture
x y + - * /
0 0 0 0 0 0
Illegal division by zero at lib/Test/C2FIT/eg/ArithmeticFixture.pm line 56.
1 2 3 -1 2 0.5 expected
0 actual
1 -1 0 2 -1 -1
10000 10000 20000 0 100000000 1
100000 100000 200000 0 10000000000 1
1000000 1000000 2000000 0 1000000000000 1


Now we try something similar using automatic type conversion offered by ColumnFixtures (BFL1).

eg.ArithmeticColumnFixture
x y plus() times() divide() floating()
2 3 5 6 0 0.6666667
0 0 0 0 error error
0 0 0 0 error error
200 300 500 60000 0 0.6666667
2 3 10 expected
5 actual
10 expected
6 actual
10 expected
0 actual
200 3 5 expected
203 actual
6 expected
600 actual
0 expected
66 actual
0.6666667 expected
66.6666666666667 actual
2 -3 -1 -6 -0 -0.6666667


fit.Summary
counts 40 right, 8 wrong, 0 ignores, 1 exceptions
input file input/arithmetic.html
input update Sat Apr 22 22:26:16 2006
output file output/arithmetic.html
run date Wed May  3 18:11:04 2006
run elapsed time 0 wallclock secs ( 0.02 usr +  0.01 sys =  0.03 CPU)

Document prepaired by Ward Cunningham
First Version July 11, 2002
Last Update August 17, 2002