Levente Uzonyi uploaded a new version of KernelTests to project The Trunk:
http://source.squeak.org/trunk/KernelTests-ul.168.mcz ==================== Summary ==================== Name: KernelTests-ul.168 Author: ul Time: 16 November 2010, 4:57:24.463 am UUID: acc5874d-ac2d-2a45-911b-940188567f6d Ancestors: KernelTests-nice.167 - use #= for integer comparison instead of #== (http://bugs.squeak.org/view.php?id=2788 ) =============== Diff against KernelTests-nice.167 =============== 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." | rs i s | rs := ReadStream on: '123s could be confused with a ScaledDecimal'. i := Number readFrom: rs. + self assert: (i isInteger and: [ i = 123 ]). - 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.0. s := rs upToEnd. self assert: 's could be confused with a ScaledDecimal' = s ! Item was changed: ----- 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 ]! - self assert: ('123' asNumber == 123). - self assert: ('-123' asNumber == -123). - self assert: ('123.' asNumber = 123). - self assert: ('123.' asNumber) isFloat. - self assert: ('-123.' asNumber = -123). - self assert: ('-123.' asNumber) isFloat. - 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). - ! Item was changed: ----- Method: LargeNegativeIntegerTest>>testDenormalizedPrintString (in category 'tests') ----- testDenormalizedPrintString "Check that an un-normalized instance behaves reasonably." | i i0 | i := LargeNegativeInteger new: 4. i basicAt: 2 put: 255. + self assert: i size = 4. - self assert: i size == 4. self assert: i printString = '-65280'. "-256*255" + self assert: i normalize = -65280. + self assert: (i normalize isMemberOf: SmallInteger). - self assert: i normalize == -65280. i0 := LargeNegativeInteger new: 0. + self assert: i0 size = 0. - self assert: i0 size == 0. self assert: i0 printString = '-0'. + self assert: i0 normalize = 0. + self assert: (i0 normalize isMemberOf: SmallInteger)! - self assert: i0 normalize == 0.! Item was changed: ----- Method: LargeNegativeIntegerTest>>testEmptyTemplate (in category 'tests') ----- testEmptyTemplate "Check that an uninitialized instance behaves reasonably." | i | i := LargeNegativeInteger new: 4. + self assert: i size = 4. - self assert: i size == 4. self assert: i printString = '-0'. + self assert: i normalize = 0. + self assert: (i normalize isMemberOf: SmallInteger)! - self assert: i normalize == 0! Item was changed: ----- Method: LargePositiveIntegerTest>>testDenormalizedPrintString (in category 'tests') ----- testDenormalizedPrintString "Check that an un-normalized instance behaves reasonably." | i i0 | i := LargePositiveInteger new: 4. i basicAt: 2 put: 255. + self assert: i size = 4. - self assert: i size == 4. self assert: i printString = '65280'. "256*255" + self assert: i normalize = 65280. + self assert: (i normalize isMemberOf: SmallInteger). - self assert: i normalize == 65280. i0 := LargePositiveInteger new: 0. + self assert: i0 size = 0. - self assert: i0 size == 0. self assert: i0 printString = '0'. + self assert: i0 normalize = 0. + self assert: (i0 normalize isMemberOf: SmallInteger)! - self assert: i0 normalize == 0.! Item was changed: ----- Method: LargePositiveIntegerTest>>testEmptyTemplate (in category 'tests') ----- testEmptyTemplate "Check that an uninitialized instance behaves reasonably." | i | i := LargePositiveInteger new: 4. + self assert: i size = 4. - self assert: i size == 4. self assert: i printString = '0'. + self assert: i normalize = 0. + self assert: (i normalize isMemberOf: SmallInteger)! - self assert: i normalize == 0! Item was changed: ----- Method: MethodContextTest>>privRestartTest (in category 'private') ----- privRestartTest "This tests may loop endlessly if incorrect, so call it from another method testing it does not time out" |a firstTimeThrough | firstTimeThrough := true. a := 10. self assert: 30 equals: [|b| + self assert: 10 = a . - self assert: 10 == a . self assert: nil == b. b := a + 20. firstTimeThrough ifTrue: [ firstTimeThrough := false. thisContext restart.]. b] value ! Item was changed: ----- Method: NumberParsingTest>>testIntegerFromString (in category 'tests - Integer') ----- testIntegerFromString "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 ] - self assert: ('123' asNumber == 123). - self assert: ('-123' asNumber == -123). - self assert: ('123.' asNumber = 123). - self assert: ('123.' asNumber) isFloat. - self assert: ('-123.' asNumber = -123). - self assert: ('-123.' asNumber) isFloat. - 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). ! Item was changed: ----- Method: NumberParsingTest>>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 := Number readFrom: rs. + self assert: (i isInteger and: [ i = 123 ]). - 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. rs := ReadStream on: '123sA has unary message sA'. i := Number readFrom: rs. + self assert: (i isInteger and: [ i = 123 ]). - self assert: 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 ]).. - self assert: i == 123. s := rs upToEnd. self assert: 'sB has unary message sB' = s. ! Item was changed: ----- Method: ScaledDecimalTest>>testAsNumber (in category 'tests') ----- testAsNumber "Ensure no loss of precision" | sd | sd := '1.40s2' asNumber. self assert: ScaledDecimal == sd class. + self assert: sd scale = 2. - self assert: sd scale == 2. self assert: '1.40s2' = sd printString. ! Item was changed: ----- Method: ScaledDecimalTest>>testAsNumberNegatedWithoutDecimalPoint (in category 'tests') ----- testAsNumberNegatedWithoutDecimalPoint | sd | sd := '-123s0' asNumber. self assert: ScaledDecimal == sd class. + self assert: sd scale = 0. - self assert: sd scale == 0. self assert: '-123s0' = sd printString. ! Item was changed: ----- Method: ScaledDecimalTest>>testAsNumberNegatedWithoutDecimalPoint2 (in category 'tests') ----- testAsNumberNegatedWithoutDecimalPoint2 | sd | sd := '-123s2' asNumber. self assert: ScaledDecimal == sd class. + self assert: sd scale = 2. - self assert: sd scale == 2. self assert: '-123.00s2' = sd printString. ! Item was changed: ----- Method: ScaledDecimalTest>>testAsNumberWithExtendedScale (in category 'tests') ----- testAsNumberWithExtendedScale | sd | sd := '123s2' asNumber. self assert: ScaledDecimal == sd class. + self assert: sd scale = 2. - self assert: sd scale == 2. self assert: '123.00s2' = sd printString. ! Item was changed: ----- Method: ScaledDecimalTest>>testAsNumberWithRadix (in category 'tests') ----- testAsNumberWithRadix | sd | sd := '10r-22.2s5' asNumber. self assert: ScaledDecimal == sd class. + self assert: sd scale = 5. - self assert: sd scale == 5. self assert: '-22.20000s5' = sd printString. ! Item was changed: ----- Method: ScaledDecimalTest>>testAsNumberWithSuperfluousDecimalPoint (in category 'tests') ----- testAsNumberWithSuperfluousDecimalPoint | sd | sd := '123.s2' asNumber. self assert: ScaledDecimal == sd class. + self assert: sd scale = 2. - self assert: sd scale == 2. self assert: '123.00s2' = sd printString. ! Item was changed: ----- Method: ScaledDecimalTest>>testAsNumberWithoutDecimalPoint (in category 'tests') ----- testAsNumberWithoutDecimalPoint | sd | sd := '123s0' asNumber. self assert: ScaledDecimal == sd class. + self assert: sd scale = 0. - self assert: sd scale == 0. self assert: '123s0' = sd printString. ! Item was changed: ----- Method: ScaledDecimalTest>>testAsNumberWithoutDecimalPoint2 (in category 'tests') ----- testAsNumberWithoutDecimalPoint2 | sd | sd := '123s2' asNumber. self assert: ScaledDecimal == sd class. + self assert: sd scale = 2. - self assert: sd scale == 2. self assert: '123.00s2' = sd printString. ! Item was changed: ----- Method: ScaledDecimalTest>>testConvertFromFloat (in category 'tests') ----- testConvertFromFloat | aFloat sd f2 diff | aFloat := 11/13 asFloat. sd := aFloat asScaledDecimal: 2. + self assert: 2 = sd scale. - self assert: 2 == sd scale. self assert: '0.84s2' = sd printString. f2 := sd asFloat. diff := f2 - aFloat. self assert: diff < 1.0e-9. "actually, f = f2, but this is not a requirement" ! Item was changed: ----- Method: ScaledDecimalTest>>testConvertFromFractionWithScale (in category 'tests') ----- testConvertFromFractionWithScale | sd | sd := (13 / 11) asScaledDecimal: 6. self assert: ScaledDecimal == sd class. self assert: ('1.181818s6' = sd printString). + self assert: 6 = sd scale - self assert: 6 == sd scale ! Item was changed: ----- Method: ScaledDecimalTest>>testLiteral (in category 'tests') ----- testLiteral | sd | sd := 1.40s2. self assert: ScaledDecimal == sd class. + self assert: sd scale = 2. - self assert: sd scale == 2. self assert: '1.40s2' = sd printString! 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 ]). - 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 := SqNumberParser parse: rs. + self assert: (i isInteger and: [ i = 123 ]). - self assert: i == 123. s := rs upToEnd. self assert: '.s could be confused with a ScaledDecimal' = s ! |
Free forum by Nabble | Edit this page |