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
System.DivideByZeroException: Attempted to divide by zero.
   at eg.ArithmeticFixture.doCell(Parse cell, Int32 column) in C:\projects\fit\cs\src\eg\ArithmeticFixture.cs:line 29
   at fit.Fixture.doCells(Parse cells) in C:\projects\fit\cs\src\fit\Fixture.cs:line 109
1 2 3 -1 2 0.5
System.FormatException: Input string was not in a correct format.
   at System.Number.ParseInt64(String s, NumberStyles style, NumberFormatInfo info)
   at System.Int64.Parse(String s)
   at fit.PrimitiveFixture.parseLong(Parse cell) in C:\projects\fit\cs\src\fit\PrimitiveFixture.cs:line 13
   at fit.PrimitiveFixture.check(Parse cell, Int64 actual) in C:\projects\fit\cs\src\fit\PrimitiveFixture.cs:line 37
   at eg.ArithmeticFixture.doCell(Parse cell, Int32 column) in C:\projects\fit\cs\src\eg\ArithmeticFixture.cs:line 29
   at fit.Fixture.doCells(Parse cells) in C:\projects\fit\cs\src\fit\Fixture.cs:line 109
1 -1 0 2 -1 -1
10000 10000 20000 0 100000000 1
100000 100000 200000 0 10000000000 expected
1410065408 actual
1
1000000 1000000 2000000 0 1000000000000 expected
-727379968 actual
1


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

eg.ArithmeticColumnFixture
x y plus() times() divide() floating()
2 3 5 6 0 0.6666667
0 0 0 0 error error expected
NaN actual
0 0 0 0
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.666667 expected
66.66666 actual
2 -3 -1 -6 -0 -0.6666667


fit.Summary
run date 10/23/2002 11:33:43 PM
output file report\arithmetic.html
input update 10/2/2002 1:33:58 PM
input file ..\doc\arithmetic.html
fixture path build;build\bin;obj;bin;bin\Debug;bin\Release
counts 37 right, 10 wrong, 0 ignored, 2 exceptions

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