[squeak-dev] The Trunk: KernelTests-nice.221.mcz
commits at source.squeak.org
commits at source.squeak.org
Tue May 22 20:46:54 UTC 2012
Nicolas Cellier uploaded a new version of KernelTests to project The Trunk:
http://source.squeak.org/trunk/KernelTests-nice.221.mcz
==================== Summary ====================
Name: KernelTests-nice.221
Author: nice
Time: 22 May 2012, 10:46:19.006 pm
UUID: c4f656c0-9acc-426f-b05e-f80f3623ff33
Ancestors: KernelTests-nice.220
Now that Float print exactly, avoid using low level private implementation #absPrintExactlyOn:base: in tests.
We might deprecate it in the future.
=============== Diff against KernelTests-nice.220 ===============
Item was changed:
----- Method: SqNumberParserTest>>testFloatGradualUnderflow (in category 'tests - Float') -----
testFloatGradualUnderflow
"Gradual underflow are tricky.
This is a non regression test for http://bugs.squeak.org/view.php?id=6976"
| float trueFraction str |
"as a preamble, use a base 16 representation to avoid round off error and check that number parsing is correct"
trueFraction := 16r2D2593D58B4FC4 / (16 raisedTo: 256+13).
"Parse the number in base 16 if possible - it is impossible if lowercase letter are allowed digits due to exponent letter ambiguity."
float := self areLowercaseDigitsAllowed
ifFalse: [SqNumberParser parse: '16r2.D2593D58B4FC4e-256']
ifTrue: [trueFraction asFloat]..
self assert: float asTrueFraction = trueFraction.
self assert: float = trueFraction asFloat.
"now print in base 10"
str := (String new: 32) writeStream.
+ float printOn: str base: 10.
- float absPrintExactlyOn: str base: 10.
"verify if SqNumberParser can read it back"
self assert: (SqNumberParser parse: str contents) = float. !
Item was changed:
----- Method: SqNumberParserTest>>testFloatPrintString (in category 'tests - Float') -----
testFloatPrintString
"self debug: #testFloatPrintString"
| f r bases |
f := Float basicNew: 2.
r := Random new seed: 1234567.
"printing a Float in base other than 10 is broken if lowercase digits are allowed"
bases := self areLowercaseDigitsAllowed
ifTrue: [#(10)]
ifFalse: [#(2 8 10 16)].
100
timesRepeat: [f basicAt: 1 put: (r nextInt: 16r100000000)- 1.
f basicAt: 2 put: (r nextInt: 16r100000000) - 1.
bases
do: [:base | | str |
str := (String new: 64) writeStream.
f negative ifTrue: [str nextPut: $-].
str print: base; nextPut: $r.
+ f abs printOn: str base: base.
- f absPrintExactlyOn: str base: base.
self assert: (SqNumberParser parse: str contents) = f]].
"test big num near infinity"
10
timesRepeat: [f basicAt: 1 put: 16r7FE00000 + ((r nextInt: 16r100000) - 1).
f basicAt: 2 put: (r nextInt: 16r100000000) - 1.
bases
do: [:base | | str |
str := (String new: 64) writeStream.
f negative ifTrue: [str nextPut: $-].
str print: base; nextPut: $r.
+ f abs printOn: str base: base.
- f absPrintExactlyOn: str base: base.
self assert: (SqNumberParser parse: str contents) = f]].
"test infinitesimal (gradual underflow)"
10
timesRepeat: [f basicAt: 1 put: 0 + ((r nextInt: 16r100000) - 1).
f basicAt: 2 put: (r nextInt: 16r100000000) - 1.
bases
do: [:base | | str |
str := (String new: 64) writeStream.
f negative ifTrue: [str nextPut: $-].
str print: base; nextPut: $r.
+ f abs printOn: str base: base.
- f absPrintExactlyOn: str base: base.
self assert: (SqNumberParser parse: str contents) = f]].!
More information about the Squeak-dev
mailing list
|