The Trunk: KernelTests-nice.270.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: KernelTests-nice.270.mcz

commits-2
Nicolas Cellier uploaded a new version of KernelTests to project The Trunk:
http://source.squeak.org/trunk/KernelTests-nice.270.mcz

==================== Summary ====================

Name: KernelTests-nice.270
Author: nice
Time: 13 May 2014, 12:29:32.57 am
UUID: 6b9c8bc1-8328-4722-9416-461c68aac39a
Ancestors: KernelTests-eem.269

Document the new possibility to specify a ScaledDecimal with implicit scale like 12.34s
Rather than duplicating NumberParsingTest job, document current behavior of (Integer readFrom: stringOrStream) which is far from obvious
For example:
        (Fraction readFrom: '4e3') -> 4000 but (Integer readFrom: '4e3') -> 4
        (Fraction readFrom: '2r101') -> 5 but (Integer readFrom: '2r101') -> 2
IMO, this should be changed, old behavior is still accessible thru (Integer readFrom: '4e3' base: 10)
Remove other redundant number parsing tests from IntegerTest (a deeper refactoring of number parsing tests would be welcome)

=============== Diff against KernelTests-eem.269 ===============

Item was changed:
  ----- Method: IntegerTest>>testReadFrom (in category 'tests - instance creation') -----
  testReadFrom
  "Ensure remaining characters in a stream are not lost when parsing an integer."
 
+ #(
+ ('12' 12 '')
+ ('-350' -350 '')
+ ('+27' 27 '')
+ ('2r101 embedded radix are not allowed' 2 'r101 embedded radix are not allowed')
+ ('25e3 exponent is ignored' 25 'e3 exponent is ignored')
+ ('25s2 scale is ignored' 25 's2 scale is ignored')
+ ('25. decimal separator is ignored' 25 '. decimal separator is ignored')
+ ('25.30 fraction part is ignored' 25 '.30 fraction part is ignored')
+ ('123r is not a radix specification' 123 'r is not a radix specification')
+ ) do: [:each |
+ [:string :numericValue :expectedRest |
+ | readStream result rest |
+ readStream := string readStream.
+ result := Integer readFrom: readStream.
+ rest := readStream upToEnd.
+ self assert: result isInteger.
+ self assert: result = numericValue.
+ self assert: rest = expectedRest.
+ ] valueWithArguments: each]!
- | rs i s |
- rs := ReadStream on: '123s could be confused with a ScaledDecimal'.
- i := Number readFrom: rs.
- self assert: (i isInteger and: [ 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.0.
- s := rs upToEnd.
- self assert: 's could be confused with a ScaledDecimal' = s
- !

Item was removed:
- ----- Method: IntegerTest>>testStringAsNumber (in category 'tests - instance creation') -----
- testStringAsNumber
- "This covers parsing in Number>>readFrom:
- Trailing decimal points should be ignored."
-
- #(
- ('123' isInteger 123)
- ('-123' isInteger -123)
- ('123.' isFloat 123)
- ('-123.' isFloat -123)
- ('123This is not to be read' isInteger 123)
- ('123s could be confused with a ScaledDecimal' isInteger 123)
- ('123e could be confused with a Float' isInteger 123)) do: [ :each |
- [ :string :typeSelector :numericValue |
- | result |
- result := string asNumber.
- self assert: (result perform: typeSelector).
- self assert: result = numericValue ] valueWithArguments: each ]!

Item was changed:
  ----- Method: NumberParsingTest>>testIntegerFromString (in category 'tests - Integer') -----
  testIntegerFromString
+ "This covers parsing in Number>>readFrom:"
- "This covers parsing in Number>>readFrom:
- Trailing decimal points should be ignored."
 
  #(
+ ('123'  123)
+ ('-123'  -123)
+ ('123.'  123.0)
+ ('-123.'  -123.0)
+ ('123This is not to be read'  123)
+ ('123s is a ScaledDecimal'  123s0)
+ ('123sin is not a ScaledDecimal, s could be part of message sin'  123)
+ ('123e could be confused with a Float' 123)) do: [ :each |
+ [ :string :numericValue |
- ('123' isInteger 123)
- ('-123' isInteger -123)
- ('123.' isFloat 123)
- ('-123.' isFloat -123)
- ('123This is not to be read' isInteger 123)
- ('123s could be confused with a ScaledDecimal' isInteger 123)
- ('123e could be confused with a Float' isInteger 123)) do: [ :each |
- [ :string :typeSelector :numericValue |
  | result |
  result := string asNumber.
+ self assert: result = numericValue.
+ self assert: result class = numericValue class] valueWithArguments: each ]
- self assert: (result perform: typeSelector).
- self assert: result = numericValue ] valueWithArguments: each ]
  !

Item was changed:
  ----- Method: NumberParsingTest>>testIntegerReadFrom (in category 'tests - Integer') -----
  testIntegerReadFrom
  "Ensure remaining characters in a stream are not lost when parsing an integer."
 
+ #(
+ ('13r96 has a radix specification'  123 ' has a radix specification')
+ ('123r is not a radix specification here'  123 'r is not a radix specification here')
+ ('-123e has no exponent'  -123 'e has no exponent')
+ ('-123.e has no exponent'  -123.0 'e has no exponent')
+ ('-123e2 has an exponent'  -12300 ' has an exponent')
+ ('123This is not to be read'  123 'This is not to be read')
+ ('123s is a ScaledDecimal'  123s0 ' is a ScaledDecimal')
+ ('-123.s is a ScaledDecimal'  -123s0 ' is a ScaledDecimal')
+ ('123sin is not a ScaledDecimal, s could be part of message sin'  123 'sin is not a ScaledDecimal, s could be part of message sin')
+ ('123.sin is not a ScaledDecimal, s could be part of message sin'  123.0 'sin is not a ScaledDecimal, s could be part of message sin')
+ ) do: [ :each |
+ [ :string :numericValue :expectedRest |
+ | readStream result rest |
+ readStream := string readStream.
+ result := Number readFrom: readStream.
+ rest := readStream upToEnd.
+ self assert: result = numericValue.
+ self assert: result class = numericValue class.
+ self assert: rest = expectedRest] valueWithArguments: each ]
- | rs i s |
- rs := ReadStream on: '123s could be confused with a ScaledDecimal'.
- i := Number readFrom: rs.
- self assert: (i isInteger and: [ 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.
- rs := ReadStream on: '123sA has unary message sA'.
- i := Number readFrom: rs.
- self assert: (i isInteger and: [ i = 123 ]).
- s := rs upToEnd.
- self assert: 'sA has unary message sA' = s.
- rs := ReadStream on: '123sB has unary message sB'.
- i := Number readFrom: rs.
- self assert: (i isInteger and: [ i = 123 ])..
- s := rs upToEnd.
- self assert: 'sB has unary message sB' = s.
  !

Item was changed:
  ----- Method: SqNumberParserTest>>testFloatReadError (in category 'tests - Float') -----
  testFloatReadError
  "This covers parsing in Number>>readFrom:"
 
  | rs num |
  rs := '1e' readStream.
  num := SqNumberParser parse: rs.
  self assert: 1 = num.
  self assert: rs upToEnd = 'e'.
 
- rs := '1s' readStream.
- num := SqNumberParser parse: rs.
- self assert: 1 = num.
- self assert: rs upToEnd = 's'.
-
  rs := '1.' readStream.
  num := SqNumberParser parse: rs.
  self assert: 1 = num.
  self assert: num isInteger.
  self assert: rs upToEnd = '.'.
 
  rs := '' readStream.
  self should: [SqNumberParser parse: rs] raise: Error.
 
  rs := 'foo' readStream.
  self should: [SqNumberParser parse: rs] raise: Error.
 
  rs := 'radix' readStream.
  self should: [SqNumberParser parse: rs] raise: Error.
 
  rs := '.e0' readStream.
  self should: [SqNumberParser parse: rs] raise: Error.
 
  rs := '-.e0' readStream.
  self should: [SqNumberParser parse: rs] raise: Error.
 
  rs := '--1' readStream.
  self should: [SqNumberParser parse: rs] raise: Error.!

Item was changed:
  ----- Method: SqNumberParserTest>>testIntegerReadFrom (in category 'tests - Integer') -----
  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 := SqNumberParser parse: rs.
- self assert: (i isInteger and: [ 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 := SqNumberParser parse: rs.
  self assert: (i isInteger and: [ i = 123 ]).
  s := rs upToEnd.
  self assert: '.s could be confused with a ScaledDecimal' = s
  !

Item was added:
+ ----- Method: SqNumberParserTest>>testScaledDecimalWithImplicitScale (in category 'tests - ScaledDecimal') -----
+ testScaledDecimalWithImplicitScale
+ "Implicit scale is automatically adjusted to the number of fractional digits specified"
+
+ #(
+ ('123s' 123s0)
+ ('0.5s' 0.5s1)
+ ('1.60s' 1.60s2)
+ ('23.070s' 23.070s3)
+ ) do: [:each |
+ [:string :scaledDecimal |
+ | value |
+ value := SqNumberParser parse: string readStream.
+ self assert: value = scaledDecimal.
+ self assert: value class = scaledDecimal class.
+ self assert: value scale = scaledDecimal scale] valueWithArguments: each]!