--- a/RegressionTests__ScaledDecimalTest.st Tue Aug 09 21:22:24 2011 +0200
+++ b/RegressionTests__ScaledDecimalTest.st Tue Aug 09 21:31:54 2011 +0200
@@ -26,7 +26,16 @@
!ScaledDecimalTest methodsFor:'tests'!
-testAsNumber
+test01_ParserDefaultIsToSupportFixedPointLiterals
+ "the old setting was to disallow by default;
+ it is now on, by default"
+
+ self assert:(ParserFlags allowFixedPointLiterals).
+
+ "Created: / 09-08-2011 / 21:23:56 / cg"
+!
+
+test02_AsNumber
"Ensure no loss of precision"
| sd |
@@ -40,9 +49,11 @@
] ifFalse:[
self assert: '1.40s2' = sd printString.
]
+
+ "Created: / 09-08-2011 / 21:25:31 / cg"
!
-testAsNumberNegatedWithoutDecimalPoint
+test03_AsNumberNegatedWithoutDecimalPoint
| sd |
sd := '-123s0' asNumber.
@@ -55,9 +66,11 @@
] ifFalse:[
self assert: '-123s0' = sd printString.
]
+
+ "Created: / 09-08-2011 / 21:25:43 / cg"
!
-testAsNumberNegatedWithoutDecimalPoint2
+test04_AsNumberNegatedWithoutDecimalPoint2
| sd |
sd := '-123s2' asNumber.
@@ -70,9 +83,11 @@
] ifFalse:[
self assert: '-123.00s2' = sd printString.
]
+
+ "Created: / 09-08-2011 / 21:25:54 / cg"
!
-testAsNumberWithExtendedScale
+test05_AsNumberWithExtendedScale
| sd |
sd := '123s2' asNumber.
@@ -85,9 +100,11 @@
] ifFalse:[
self assert: '123.00s2' = sd printString.
]
+
+ "Created: / 09-08-2011 / 21:25:59 / cg"
!
-testAsNumberWithRadix
+test06_AsNumberWithRadix
| sd oldSetting |
Smalltalk isSmalltalkX ifTrue:[
@@ -112,10 +129,10 @@
self assert: '-22.20000s5' = sd printString.
]
- "Modified: / 09-08-2011 / 20:57:54 / cg"
+ "Created: / 09-08-2011 / 21:26:05 / cg"
!
-testAsNumberWithSuperfluousDecimalPoint
+test07_AsNumberWithSuperfluousDecimalPoint
| sd |
sd := '123.s2' asNumber.
@@ -128,9 +145,11 @@
] ifFalse:[
self assert: '123.00s2' = sd printString.
]
+
+ "Created: / 09-08-2011 / 21:26:20 / cg"
!
-testAsNumberWithoutDecimalPoint
+test08_AsNumberWithoutDecimalPoint
| sd |
sd := '123s0' asNumber.
@@ -143,9 +162,11 @@
] ifFalse:[
self assert: '123s0' = sd printString.
]
+
+ "Created: / 09-08-2011 / 21:26:25 / cg"
!
-testAsNumberWithoutDecimalPoint2
+test09_AsNumberWithoutDecimalPoint2
| sd |
sd := '123s2' asNumber.
@@ -158,9 +179,11 @@
] ifFalse:[
self assert: '123.00s2' = sd printString.
]
+
+ "Created: / 09-08-2011 / 21:26:30 / cg"
!
-testConvertFromFloat
+test10_ConvertFromFloat
| aFloat sd f2 diff |
aFloat := 11/13 asFloat.
@@ -174,9 +197,11 @@
f2 := sd asFloat.
diff := f2 - aFloat.
self assert: diff < 1.0e-9. "actually, f = f2, but this is not a requirement"
+
+ "Created: / 09-08-2011 / 21:26:38 / cg"
!
-testConvertFromFraction
+test11_ConvertFromFraction
| sd |
sd := (13 / 11) asScaledDecimal: 6.
@@ -187,9 +212,11 @@
self assert: ('1.181818s6' = sd printString).
].
self assert: 6 == sd scale
+
+ "Created: / 09-08-2011 / 21:26:43 / cg"
!
-testConvertFromInteger
+test12_ConvertFromInteger
"Converting an Integer to a ScaledDecimal yields a ScaledDecimal with
scale 0, regardless of the scale specified in the #asScaledDecimal: message."
@@ -212,19 +239,21 @@
sd := -130000000013 asScaledDecimal: 6.
self assert: 0 = sd scale.
self assert: ('-130000000013s0' = sd printString)
+
+ "Created: / 09-08-2011 / 21:26:46 / cg"
!
-testLiteral1
+test13_Literal1
"s2 is not a message to be sent to a float"
self
shouldnt:[ self literal_helper1 ]
raise:MessageNotUnderstood
- "Created: / 09-08-2011 / 21:05:47 / cg"
+ "Created: / 09-08-2011 / 21:26:55 / cg"
!
-testLiteral2
+test14_Literal2
| sd |
sd := 1.40s2.
@@ -237,10 +266,10 @@
self assert: '1.40s2' = sd printString.
].
- "Created: / 09-08-2011 / 21:06:11 / cg"
+ "Created: / 09-08-2011 / 21:27:01 / cg"
!
-testLiteralInSTC
+test15_LiteralInSTC
|value|
Class withoutUpdatingChangesDo:[
@@ -263,10 +292,10 @@
self assert:( (value * 10) = 14 ).
self assert:( value asFloat = 1.4 ).
- "Created: / 09-08-2011 / 21:10:22 / cg"
+ "Created: / 09-08-2011 / 21:27:07 / cg"
!
-testPrintString
+test16_PrintString
"The printed representation of a ScaledDecimal is truncated, not rounded.
Not sure if this is right, so this test describes the current Squeak implementation.
If someone knows a reason that rounding would be preferable, then update
@@ -294,9 +323,11 @@
] ifFalse:[
self assert: ('1.18181s5' = sd printString).
].
+
+ "Created: / 09-08-2011 / 21:27:49 / cg"
!
-testStoreAndRead
+test17_StoreAndRead
|check|
check := [:originalNum |
@@ -314,6 +345,8 @@
check value:((FixedPoint fromString:'1.5') withScale:2 ).
check value:((FixedPoint fromString:'1.5') withScale:1 ).
check value:((FixedPoint fromString:'1.5') withScale:0 ).
+
+ "Created: / 09-08-2011 / 21:27:53 / cg"
! !
!ScaledDecimalTest class methodsFor:'documentation'!