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(ArithmeticFixture.java:24)
	at fit.Fixture.doCells(Fixture.java:100)
	at fit.Fixture.doRow(Fixture.java:94)
	at fit.Fixture.doRows(Fixture.java:88)
	at eg.ArithmeticFixture.doRows(ArithmeticFixture.java:14)
	at fit.Fixture.doTable(Fixture.java:82)
	at fit.Fixture.doTables(Fixture.java:72)
	at fit.FrameworkTest.run(FrameworkTest.java:191)
	at fit.FrameworkTest.testRuns(FrameworkTest.java:175)
	at java.lang.reflect.Method.invoke(Native Method)
	at junit.framework.TestCase.runTest(TestCase.java:166)
	at junit.framework.TestCase.runBare(TestCase.java:140)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:131)
	at junit.framework.TestSuite.runTest(TestSuite.java:173)
	at junit.framework.TestSuite.run(TestSuite.java:168)
	at junit.swingui.TestRunner$17.run(TestRunner.java:644)
1 2 3 -1 2 0.5
java.lang.NumberFormatException: 0.5
	at java.lang.Long.parseLong(Long.java:314)
	at java.lang.Long.parseLong(Long.java:358)
	at fit.PrimitiveFixture.parseLong(PrimitiveFixture.java:12)
	at fit.PrimitiveFixture.check(PrimitiveFixture.java:30)
	at eg.ArithmeticFixture.doCell(ArithmeticFixture.java:24)
	at fit.Fixture.doCells(Fixture.java:100)
	at fit.Fixture.doRow(Fixture.java:94)
	at fit.Fixture.doRows(Fixture.java:88)
	at eg.ArithmeticFixture.doRows(ArithmeticFixture.java:14)
	at fit.Fixture.doTable(Fixture.java:82)
	at fit.Fixture.doTables(Fixture.java:72)
	at fit.FrameworkTest.run(FrameworkTest.java:191)
	at fit.FrameworkTest.testRuns(FrameworkTest.java:175)
	at java.lang.reflect.Method.invoke(Native Method)
	at junit.framework.TestCase.runTest(TestCase.java:166)
	at junit.framework.TestCase.runBare(TestCase.java:140)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:131)
	at junit.framework.TestSuite.runTest(TestSuite.java:173)
	at junit.framework.TestSuite.run(TestSuite.java:168)
	at junit.swingui.TestRunner$17.run(TestRunner.java:644)
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 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
run date Mon Nov 04 16:52:47 PST 2002
run elapsed time 0:00.02

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