'From Squeak3.7beta of ''1 April 2004'' [latest update: #5923] on 24 November 2004 at 6:54:08 pm'! "Change Set: NumberParsingTest-dtl Date: 24 November 2004 Author: David T. Lewis Test cases for numbers parsed from strings or streams. This test case is a companion to ScaledDecimalTest, which has already been added to the Squeak 3.9 release stream. These tests demonstrate three failures in the current 3.9 image. See NumberReadFromFixes-2-dtl for patches that correct these failures as well as those demonstrated by ScaledDecimalTest."! TestCase subclass: #NumberParsingTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Kernel-Numbers-Tests'! !NumberParsingTest commentStamp: 'dtl 11/24/2004 15:35' prior: 0! Tests to verify parsing of numbers from streams and strings. Note: ScaledDecimalTest contains related tests for parsing ScaledDecimal.! !NumberParsingTest methodsFor: 'testing-Integer' stamp: 'dtl 11/24/2004 14:05'! testIntegerFromString "This covers parsing in Number>>readFrom: Trailing decimal points should be ignored." self assert: ('123' asNumber == 123). self assert: ('-123' asNumber == -123). self assert: ('123.' asNumber == 123). self assert: ('-123.' asNumber == -123). self assert: ('123This is not to be read' asNumber == 123). self assert: ('123s could be confused with a ScaledDecimal' asNumber == 123). self assert: ('123e could be confused with a Float' asNumber == 123). ! ! !NumberParsingTest methodsFor: 'testing-Integer' stamp: 'dtl 11/24/2004 14:04'! testIntegerReadFrom "Ensure remaining characters in a stream are not lost when parsing an integer." | rs i s | rs _ ReadStream on: '123s could be confused with a ScaledDecimal'. i _ Number readFrom: rs. self assert: i == 123. s _ rs upToEnd. self assert: 's could be confused with a ScaledDecimal' = s. rs _ ReadStream on: '123.s could be confused with a ScaledDecimal'. i _ Number readFrom: rs. self assert: i == 123. s _ rs upToEnd. self assert: '.s could be confused with a ScaledDecimal' = s ! ! !NumberParsingTest methodsFor: 'testing-Integer' stamp: 'dtl 11/24/2004 18:18'! testIntegerReadWithRadix "This covers parsing in Number>>readFrom: Note: In most Smalltalk dialects, the radix notation is not used for numbers with exponents. In Squeak, a string with radix and exponent can be parsed, and the exponent is always treated as base 10 (not the base indicated in the radix prefix). I am not sure if this is a feature, a bug, or both, but the Squeak behavior is documented in this test. -dtl" | aNumber rs | aNumber _ '2r1e26' asNumber. self assert: 67108864 = aNumber. self assert: (Number readFrom: '2r1e26') = (2 raisedTo: 26). rs _ '2r1e26eee' readStream. self assert: (Number readFrom: rs) = 67108864. self assert: rs upToEnd = 'eee' ! ! !NumberParsingTest methodsFor: 'testing-Float' stamp: 'dtl 11/24/2004 14:29'! testFloatFromStreamAsNumber "This covers parsing in Number>>readFrom:" | rs aFloat | rs _ '10r-12.3456' readStream. aFloat _ Number readFrom: rs. self assert: -12.3456 = aFloat. self assert: rs atEnd. rs _ '10r-12.3456e2' readStream. aFloat _ Number readFrom: rs. self assert: -1234.56 = aFloat. self assert: rs atEnd. rs _ '10r-12.3456e2e2' readStream. aFloat _ Number readFrom: rs. self assert: -1234.56 = aFloat. self assert: rs upToEnd = 'e2'. rs _ '10r-12.3456d2' readStream. aFloat _ Number readFrom: rs. self assert: -1234.56 = aFloat. self assert: rs atEnd. rs _ '10r-12.3456q2' readStream. aFloat _ Number readFrom: rs. self assert: -1234.56 = aFloat. self assert: rs atEnd. rs _ '-12.3456q2' readStream. aFloat _ Number readFrom: rs. self assert: -1234.56 = aFloat. self assert: rs atEnd. rs _ '12.3456q2' readStream. aFloat _ Number readFrom: rs. self assert: 1234.56 = aFloat. self assert: rs atEnd. rs _ '12.3456z2' readStream. aFloat _ Number readFrom: rs. self assert: 12.3456 = aFloat. self assert: rs upToEnd = 'z2'. ! ! !NumberParsingTest methodsFor: 'testing-Float' stamp: 'dtl 11/24/2004 14:37'! testFloatFromStreamWithExponent "This covers parsing in Number>>readFrom:" | rs aFloat | rs _ '1.0e-14' readStream. aFloat _ Number readFrom: rs. self assert: 1.0e-14 = aFloat. self assert: rs atEnd. rs _ '1.0e-14 1' readStream. aFloat _ Number readFrom: rs. self assert: 1.0e-14 = aFloat. self assert: rs upToEnd = ' 1'. rs _ '1.0e-14eee' readStream. aFloat _ Number readFrom: rs. self assert: 1.0e-14 = aFloat. self assert: rs upToEnd = 'eee'. rs _ '1.0e14e10' readStream. aFloat _ Number readFrom: rs. self assert: 1.0e14 = aFloat. self assert: rs upToEnd = 'e10'. rs _ '1.0e+14e' readStream. "Plus sign is not parseable" aFloat _ Number readFrom: rs. self assert: 1.0 = aFloat. self assert: rs upToEnd = 'e+14e'. ! ! !NumberParsingTest methodsFor: 'testing-Float' stamp: 'dtl 11/24/2004 14:07'! testFloatFromStringAsNumber "This covers parsing in Number>>readFrom:" | aFloat | aFloat _ '10r-12.3456' asNumber. self assert: -12.3456 = aFloat. aFloat _ '10r-12.3456e2' asNumber. self assert: -1234.56 = aFloat. aFloat _ '10r-12.3456d2' asNumber. self assert: -1234.56 = aFloat. aFloat _ '10r-12.3456q2' asNumber. self assert: -1234.56 = aFloat. aFloat _ '-12.3456q2' asNumber. self assert: -1234.56 = aFloat. aFloat _ '12.3456q2' asNumber. self assert: 1234.56 = aFloat. ! ! !NumberParsingTest methodsFor: 'testing-Float' stamp: 'dtl 11/24/2004 14:12'! testFloatFromStringWithExponent "This covers parsing in Number>>readFrom:" | aFloat | aFloat _ '1.0e-14' asNumber. self assert: 1.0e-14 = aFloat. aFloat _ '1.0e-14 1' asNumber. self assert: 1.0e-14 = aFloat. aFloat _ '1.0e-14e' asNumber. self assert: 1.0e-14 = aFloat. aFloat _ '1.0e14e' asNumber. self assert: 1.0e14 = aFloat. aFloat _ '1.0e+14e' asNumber. "Plus sign is not parseable" self assert: 1.0 = aFloat. ! ! !NumberParsingTest methodsFor: 'testing-Float' stamp: 'dtl 11/24/2004 18:16'! testFloatReadWithRadix "This covers parsing in Number>>readFrom: Note: In most Smalltalk dialects, the radix notation is not used for numbers with exponents. In Squeak, a string with radix and exponent can be parsed, and the exponent is always treated as base 10 (not the base indicated in the radix prefix). I am not sure if this is a feature, a bug, or both, but the Squeak behavior is documented in this test. -dtl" | aNumber rs | aNumber _ '2r1.0101e9' asNumber. self assert: 672.0 = aNumber. self assert: (Number readFrom: '2r1.0101e9') = (1.3125 * (2 raisedTo: 9)). rs _ ReadStream on: '2r1.0101e9e9'. self assert: (Number readFrom: rs) = 672.0. self assert: rs upToEnd = 'e9' ! ! !NumberParsingTest reorganize! ('testing-Integer' testIntegerFromString testIntegerReadFrom testIntegerReadWithRadix) ('testing-Float' testFloatFromStreamAsNumber testFloatFromStreamWithExponent testFloatFromStringAsNumber testFloatFromStringWithExponent testFloatReadWithRadix) !