% $Id: FloatTesting.oz,v 1.3 2012/04/17 12:47:35 leavens Exp leavens $ % Testing for floating point numbers. % AUTHOR: Gary T. Leavens \insert 'TestingNoStop.oz' \insert 'FloatPredicates.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 note the failure. fun {TestMaker FloatCompare FloatListCompare Epsilon} fun {Compare Actual Expected} if {IsFloat Actual} andthen {IsFloat Expected} then {FloatCompare Epsilon Actual Expected} elseif {IsList Actual} andthen {All Actual IsFloat} andthen {IsList Expected} andthen {All Expected IsFloat} then {FloatListCompare Epsilon Actual Expected} else false end end in proc {$ Actual Connective Expected} if {Compare Actual Expected} then {ReportAbout {Value.toVirtualString Actual 5 20} # ' ' # Connective # ' ' # {Value.toVirtualString Expected 5 20}} else {NotifyAbout '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}