% $Id: FloatTesting.oz,v 1.4 2006/10/27 08:57:49 leavens Exp $ % Testing for floating point numbers. % AUTHOR: Gary T. Leavens functor $ import System(showInfo) FloatComparisons export testMaker: TestMaker standardTolerance: StandardTolerance withinTest: WithinTest relativeTest: RelativeTest define %% TestMaker returns a procedure P such that {P Actual '=' Expected} %% is true if {FloatCompare Epsilon Actual Expected} (for Floats) %% or if {FloatListCompare Epsilon Actual Expected} (for lists of Floats) %% If so, print a message, otherwise throw an exception. fun {TestMaker FloatCompare FloatListCompare Epsilon} fun {Compare Actual Expected} if {IsFloat Actual} andthen {IsFloat Expected} then {FloatCompare Epsilon Actual Expected} elseif {IsList Actual} andthen {IsList Expected} then {FloatListCompare Epsilon Actual Expected} else false end end in proc {$ Actual Connective Expected} if {Compare Actual Expected} then {System.showInfo {Value.toVirtualString Actual 5 10} # ' ' # Connective # ' ' # {Value.toVirtualString Expected 5 10}} else {Exception.raiseError testFailed(actual:Actual connective:Connective expected:Expected debug:unit) } end end end StandardTolerance = 1.0e~3 WithinTest = {TestMaker FloatComparisons.within FloatComparisons.withinLists StandardTolerance} RelativeTest = {TestMaker FloatComparisons.relative FloatComparisons.relativeLists StandardTolerance} end