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
java.lang.ArithmeticException: / by zero
at eg.ArithmeticFixture.doCell(Unknown Source)
at fit.Fixture.doCells(Unknown Source)
at fit.Fixture.doRow(Unknown Source)
at fit.Fixture.doRows(Unknown Source)
at eg.ArithmeticFixture.doRows(Unknown Source)
at fit.Fixture.doTable(Unknown Source)
at fit.Fixture.interpretTables(Unknown Source)
at fit.Fixture.doTables(Unknown Source)
at fit.FileRunner.process(Unknown Source)
at fit.FileRunner.run(Unknown Source)
at fit.FileRunner.main(Unknown Source)
1 2 3 -1 2 0.5
java.lang.NumberFormatException: For input string: "0.5"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Long.parseLong(Long.java:403)
at java.lang.Long.parseLong(Long.java:452)
at fit.PrimitiveFixture.parseLong(Unknown Source)
at fit.PrimitiveFixture.check(Unknown Source)
at eg.ArithmeticFixture.doCell(Unknown Source)
at fit.Fixture.doCells(Unknown Source)
at fit.Fixture.doRow(Unknown Source)
at fit.Fixture.doRows(Unknown Source)
at eg.ArithmeticFixture.doRows(Unknown Source)
at fit.Fixture.doTable(Unknown Source)
at fit.Fixture.interpretTables(Unknown Source)
at fit.Fixture.doTables(Unknown Source)
at fit.FileRunner.process(Unknown Source)
at fit.FileRunner.run(Unknown Source)
at fit.FileRunner.main(Unknown Source)
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 (BFL1).

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 error NaN
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.666664 actual
2 -3 -1 -6 -0 -0.6666667


fit.Summary
counts 37 right, 10 wrong, 0 ignored, 2 exceptions
input file C:\projects\fit\imp\java\..\..\examples\arithmetic.html
input update Tue Sep 16 17:43:29 PDT 2003
output file C:\projects\fit\imp\java\output\examples\arithmetic.html
run date Thu Apr 07 23:25:18 PDT 2005
run elapsed time 0:00.11

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