% $Id: FloatTesting.oz,v 1.5 2008/03/24 15:43:04 leavens Exp leavens $ % Testing for floating point numbers. % AUTHOR: Gary T. Leavens \insert 'FloatPredicates.oz' \insert 'TestingNoStop.oz' declare %% 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 20} # ' ' # Connective # ' ' # {Value.toVirtualString Expected 5 20}} else {System.showInfo 'TEST FAILURE: ' # {Value.toVirtualString Actual 5 20} # ' ' # Connective # ' ' # {Value.toVirtualString Expected 5 20} } end end end WithinTest = {TestMaker Within WithinLists StandardTolerance} RelativeTest = {TestMaker Relative RelativeLists StandardTolerance}