Nicolas Cellier uploaded a new version of KernelTests to project The Trunk:
http://source.squeak.org/trunk/KernelTests-nice.370.mcz ==================== Summary ==================== Name: KernelTests-nice.370 Author: nice Time: 22 August 2019, 12:34:59.288205 am UUID: b84345c4-295e-488a-a3bb-0e82f786d2f9 Ancestors: KernelTests-nice.369 Provide more systematic mixed float/int comparison tests for a good coverage of new spur64 primitive implementation. This new implementation follows the ideas proposed for resoution of https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/417 Move this material in FloatTest rather than SmallIntegerTest. =============== Diff against KernelTests-nice.369 =============== Item was changed: ClassTestCase subclass: #FloatTest + instanceVariableNames: 'exactInteger float greaterInexactInt smallerInexactInt greaterFloat smallerFloat boxedFloat greaterBoxedFloat smallerBoxedFloat' - instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'KernelTests-Numbers'! !FloatTest commentStamp: 'fbs 3/8/2004 22:13' prior: 0! I provide a test suite for Float values. Examine my tests to see how Floats should behave, and see how to use them.! Item was added: + ----- Method: FloatTest>>setUp (in category 'running') ----- + setUp + exactInteger := 1 << (Float precision + 2). + float := exactInteger asFloat. + greaterInexactInt := exactInteger + 1. + smallerInexactInt := exactInteger - 1. + greaterFloat := float successor. + smallerFloat := float predecessor. + + boxedFloat := Float new: 2. + boxedFloat basicAt: 1 put: (float basicAt: 1). + boxedFloat basicAt: 2 put: (float basicAt: 2). + greaterBoxedFloat := Float new: 2. + greaterBoxedFloat basicAt: 1 put: (greaterFloat basicAt: 1). + greaterBoxedFloat basicAt: 2 put: (greaterFloat basicAt: 2). + smallerBoxedFloat := Float new: 2. + smallerBoxedFloat basicAt: 1 put: (smallerFloat basicAt: 1). + smallerBoxedFloat basicAt: 2 put: (smallerFloat basicAt: 2).! Item was added: + ----- Method: FloatTest>>testComparisonSmallFromBoxed (in category 'tests - compare') ----- + testComparisonSmallFromBoxed + "Comparison should work the same, boxed or not" + + self assert: boxedFloat = float. + self deny: boxedFloat ~= float. + self deny: boxedFloat = smallerFloat. + self assert: boxedFloat ~= greaterFloat. + + self assert: boxedFloat < greaterFloat. + self assert: boxedFloat <= greaterFloat. + self deny: boxedFloat > greaterFloat. + self deny: boxedFloat >= greaterFloat. + + self deny: boxedFloat < smallerFloat. + self deny: boxedFloat <= smallerFloat. + self assert: boxedFloat > smallerFloat. + self assert: boxedFloat >= smallerFloat.! Item was added: + ----- Method: FloatTest>>testComparisonSmallWithBoxed (in category 'tests - compare') ----- + testComparisonSmallWithBoxed + "Comparison should work the same, boxed or not" + + self assert: float = boxedFloat. + self deny: float ~= boxedFloat. + self deny: float = smallerBoxedFloat. + self assert: float ~= greaterBoxedFloat. + + self assert: float < greaterBoxedFloat. + self assert: float <= greaterBoxedFloat. + self deny: float > greaterBoxedFloat. + self deny: float >= greaterBoxedFloat. + + self deny: float < smallerBoxedFloat. + self deny: float <= smallerBoxedFloat. + self assert: float > smallerBoxedFloat. + self assert: float >= smallerBoxedFloat.! Item was added: + ----- Method: FloatTest>>testExactComparisonFromSmallInt (in category 'tests - compare') ----- + testExactComparisonFromSmallInt + "Those tests works when using naive (integer asFloat = float) comparison. + This is because the conversion asFloat are exact." + + {float. boxedFloat} do: [:f | + self assert: exactInteger = f. + self deny: exactInteger ~= f. + self assert: exactInteger <= f. + self deny: exactInteger < f. + self assert: exactInteger >= f. + self deny: exactInteger > f]. + + {greaterFloat. greaterBoxedFloat} do: [:f | + self deny: exactInteger = f. + self assert: exactInteger ~= f. + self assert: exactInteger <= f. + self assert: exactInteger < f. + self deny: exactInteger >= f. + self deny: exactInteger > f]. + + {smallerFloat. smallerBoxedFloat} do: [:f | + self deny: exactInteger = f. + self assert: exactInteger ~= f. + self deny: exactInteger <= f. + self deny: exactInteger < f. + self assert: exactInteger >= f. + self assert: exactInteger > f].! Item was added: + ----- Method: FloatTest>>testExactComparisonWithSmallInt (in category 'tests - compare') ----- + testExactComparisonWithSmallInt + "Those tests works when using naive (integer asFloat = float) comparison. + This is because the conversion asFloat are exact." + + {float. boxedFloat} do: [:f | + self assert: f = exactInteger. + self deny: f ~= exactInteger. + self assert: f <= exactInteger. + self deny: f < exactInteger. + self assert: f >= exactInteger. + self deny: f > exactInteger]. + + {greaterFloat. greaterBoxedFloat} do: [:f | + self deny: f = exactInteger. + self assert: f ~= exactInteger. + self deny: f <= exactInteger. + self deny: f < exactInteger. + self assert: f >= exactInteger. + self assert: f > exactInteger]. + + {smallerFloat. smallerBoxedFloat} do: [:f | + self deny: f = exactInteger. + self assert: f ~= exactInteger. + self assert: f <= exactInteger. + self assert: f < exactInteger. + self deny: f >= exactInteger. + self deny: f > exactInteger].! Item was added: + ----- Method: FloatTest>>testInexactComparisonFromSmallInt (in category 'tests - compare') ----- + testInexactComparisonFromSmallInt + "Those tests would fail if using naive (integer asFloat = float) comparison. + This is because the conversion asFloat are inexact and loose bits." + + {float. boxedFloat} do: [:f | + self deny: smallerInexactInt = f. + self assert: greaterInexactInt ~= f. + + self assert: greaterInexactInt > f. + self deny: greaterInexactInt <= f. + self assert: smallerInexactInt < f. + self deny: smallerInexactInt >= f].! Item was added: + ----- Method: FloatTest>>testInexactComparisonOKFromSmallInt (in category 'tests - compare') ----- + testInexactComparisonOKFromSmallInt + "asFloat conversion is monotonic: + intA < intB ==> (intA asFloat <= intB asFloat). + Thus those tests would work if using naive (integer asFloat op: float) comparison, + even if asFloat conversion is inexact." + + {greaterFloat . greaterBoxedFloat} do: [:f | + self deny: smallerInexactInt = f. + self assert: smallerInexactInt ~= f. + + self assert: smallerInexactInt < f. + self assert: smallerInexactInt <= f. + self deny: smallerInexactInt > f. + self deny: smallerInexactInt >= f].! Item was added: + ----- Method: FloatTest>>testInexactComparisonOKWithSmallInt (in category 'tests - compare') ----- + testInexactComparisonOKWithSmallInt + "asFloat conversion is monotonic: + intA < intB ==> (intA asFloat <= intB asFloat). + Thus those tests would work if using naive (integer asFloat op: float) comparison, + even if asFloat conversion is inexact." + + {smallerFloat . smallerBoxedFloat} do: [:f | + self deny: f = greaterInexactInt. + self assert: f ~= greaterInexactInt. + + self assert: f < greaterInexactInt. + self assert: f <= greaterInexactInt. + self deny: f > greaterInexactInt. + self deny: f >= greaterInexactInt].! Item was added: + ----- Method: FloatTest>>testInexactComparisonWithSmallInt (in category 'tests - compare') ----- + testInexactComparisonWithSmallInt + "Those tests would fail if using naive (integer asFloat = float) comparison. + This is because the conversion asFloat are inexact and loose bits." + + {float. boxedFloat} do: [:f | + self deny: f = greaterInexactInt. + self assert: f ~= smallerInexactInt. + + self assert: f < greaterInexactInt. + self deny: f >= greaterInexactInt. + self assert: f > smallerInexactInt. + self deny: f <= smallerInexactInt].! Item was removed: - ----- Method: SmallIntegerTest>>testCompareWithBoxedFloat (in category 'tests - comparing') ----- - testCompareWithBoxedFloat - "In 64 bits, naive asFloat conversion should not be used" - - | bf sf si | - Smalltalk wordSize = 8 ifFalse: [^self]. - si := 1<<(Float precision + 2)+1. - sf := si asFloat. - (bf := BoxedFloat64 new: 2) basicAt: 1 put: (sf basicAt: 1);basicAt: 2 put: (sf basicAt: 2). - - self deny: si = bf. - self deny: bf = si.! Item was removed: - ----- Method: SmallIntegerTest>>testCompareWithSmallFloat (in category 'tests - comparing') ----- - testCompareWithSmallFloat - "In 64 bits, naive asFloat conversion should not be used" - - | sf si | - Smalltalk wordSize = 8 ifFalse: [^self]. - si := 1<<(Float precision + 2)+1. - sf := si asFloat. - self deny: sf = si. - self deny: si = sf.! |
Free forum by Nabble | Edit this page |