RegressionTests__NumberTest.st
author sr
Thu, 28 Sep 2017 16:49:57 +0200
changeset 1710 9ad2831a971b
parent 1628 27b3c920623a
child 1713 72bd587b1967
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1447
2351db93aa5b package changes
Claus Gittinger <cg@exept.de>
parents: 1072
diff changeset
     1
"{ Package: 'stx:goodies/regression' }"
242
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"{ NameSpace: RegressionTests }"
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
TestCase subclass:#NumberTest
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
	instanceVariableNames:'a b'
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
	classVariableNames:''
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
	poolDictionaries:''
1072
ee32c0daddfb category
Claus Gittinger <cg@exept.de>
parents: 670
diff changeset
     9
	category:'tests-Regression-Numbers'
242
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
!
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
!NumberTest methodsFor:'accessing'!
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
a
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
    ^ a
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
!
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
a:something
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
    a := something.
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
b
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
    ^ b
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
!
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
b:something
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
    b := something.
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
! !
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
670
4fd7b73a1c19 added: #tearDown
Stefan Vogel <sv@exept.de>
parents: 610
diff changeset
    31
!NumberTest methodsFor:'running'!
327
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
    32
670
4fd7b73a1c19 added: #tearDown
Stefan Vogel <sv@exept.de>
parents: 610
diff changeset
    33
tearDown
4fd7b73a1c19 added: #tearDown
Stefan Vogel <sv@exept.de>
parents: 610
diff changeset
    34
    Class withoutUpdatingChangesDo:[
1447
2351db93aa5b package changes
Claus Gittinger <cg@exept.de>
parents: 1072
diff changeset
    35
	self class removeSelector:#testEQ
670
4fd7b73a1c19 added: #tearDown
Stefan Vogel <sv@exept.de>
parents: 610
diff changeset
    36
    ].
327
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
    37
! !
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
    38
315
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
    39
!NumberTest methodsFor:'tests-concrete bugs'!
242
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
test_eqNumberBug
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    "reported 09-09-2004;
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
     stc generated wrong code for some inlined = - compare (shame)."
1710
9ad2831a971b *** empty log message ***
sr
parents: 1628
diff changeset
    44
	 
9ad2831a971b *** empty log message ***
sr
parents: 1628
diff changeset
    45
    self 
9ad2831a971b *** empty log message ***
sr
parents: 1628
diff changeset
    46
        skipIf:Smalltalk isStandAloneApp 
9ad2831a971b *** empty log message ***
sr
parents: 1628
diff changeset
    47
        description:'Usually there are no compiler settings in standalone environments'.
9ad2831a971b *** empty log message ***
sr
parents: 1628
diff changeset
    48
	 
242
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
    Class withoutUpdatingChangesDo:[
610
efb13a71ed4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    50
	self class
efb13a71ed4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    51
	    compile:
242
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
'testEQ
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
    a = b ifTrue:[^ false].
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
    ^ true.
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
'
610
efb13a71ed4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    56
	    classified:'temporary'.
242
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    ].
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
    self assert: (
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
       (self
610
efb13a71ed4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    61
	   a:0;
efb13a71ed4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    62
	   b:0) testEQ ) == false.
242
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
    self assert: (
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
       (self
610
efb13a71ed4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    66
	   a:0;
efb13a71ed4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    67
	   b:0.0) testEQ ) == false.
242
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
    self assert: (
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
       (self
610
efb13a71ed4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    71
	   a:0.0;
efb13a71ed4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    72
	   b:0) testEQ ) == false.
242
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
    self assert: (
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
       (self
610
efb13a71ed4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    76
	   a:0.0;
efb13a71ed4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    77
	   b:0.0) testEQ ) == false.
242
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
    Class withoutUpdatingChangesDo:[
610
efb13a71ed4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    80
	Compiler stcCompileMethod:(self class compiledMethodAt:#testEQ).
242
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
    ].
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
    self assert: (
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
       (self
610
efb13a71ed4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    85
	   a:0;
efb13a71ed4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    86
	   b:0) testEQ ) == false.
242
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
    self assert: (
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
       (self
610
efb13a71ed4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    90
	   a:0;
efb13a71ed4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    91
	   b:0.0) testEQ ) == false.
242
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
    self assert: (
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
       (self
610
efb13a71ed4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    95
	   a:0.0;
efb13a71ed4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
    96
	   b:0) testEQ ) == false.
242
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
    self assert: (
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
       (self
610
efb13a71ed4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
   100
	   a:0.0;
efb13a71ed4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
   101
	   b:0.0) testEQ ) == false.
242
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
    Class withoutUpdatingChangesDo:[
610
efb13a71ed4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 327
diff changeset
   104
	self class removeSelector:#testEQ
242
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
    ].
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
    "
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
     self new test_eqNumberBug
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
    "
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
! !
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
327
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   112
!NumberTest methodsFor:'tests-conversion-rounding'!
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   113
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   114
test_conversion
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   115
    "reported as Bug 388
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   116
     Current implementation neither truncate nor round to nearest Floating point
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   117
     value, it just accumulate round off errors."
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   118
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   119
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   120
    self assert: 16r1FFFFFFFFFFFF0801 asDouble ~= 16r1FFFFFFFFFFFF0800 asDouble.
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   121
    "this test is on 65 bits"
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   122
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   123
    self assert: 16r1FFFFFFFFFFFF0802 asDouble ~= 16r1FFFFFFFFFFFF0800 asDouble.
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   124
    "this test is on 64 bits"
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   125
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   126
    self assert: 16r1FFFFFFFFFFF1F800 asDouble = 16r1FFFFFFFFFFF20000 asDouble.
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   127
    "nearest even is upper"
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   128
    self assert: 16r1FFFFFFFFFFFF0800 asDouble = 16r1FFFFFFFFFFFF0000 asDouble.
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   129
    "nearest even is lower"
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   130
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   131
    "Created: / 24-10-2006 / 15:31:20 / cg"
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   132
! !
05cf0c282e59 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 315
diff changeset
   133
1628
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   134
!NumberTest methodsFor:'tests-printing'!
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   135
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   136
testPrintf
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   137
    "/ Float
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   138
    
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   139
    self assert:( (PrintfScanf printf:'%4f' argument:ShortFloat pi) = '3.14159' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   140
    self assert:( (PrintfScanf printf:'%4f' argument:Float pi)      = '3.141593' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   141
    self assert:( (PrintfScanf printf:'%4f' argument:LongFloat pi)  = '3.14159265' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   142
    self assert:( (PrintfScanf printf:'%4f' argument:QDouble pi)    = '3.14159265358979323846' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   143
    self assert:( (PrintfScanf printf:'%4f' argument:Fraction pi)   = '3.141593' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   144
    self assert:( (PrintfScanf printf:'%4f' argument:FixedPoint pi) = '3.141593' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   145
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   146
    "/ too small
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   147
    self assert:( (Float pi printfPrintString:'%4f') = '3.141593' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   148
    self assert:( (Float pi printfPrintString:'%5f') = '3.141593' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   149
    self assert:( (Float pi printfPrintString:'%6f') = '3.141593' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   150
    self assert:( (Float pi printfPrintString:'%7f') = '3.141593' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   151
    "/ fit
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   152
    self assert:( (Float pi printfPrintString:'%8f') = '3.141593' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   153
    self assert:( (Float pi printfPrintString:'%4.2f') = '3.14' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   154
    "/ left filled
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   155
    self assert:( (Float pi printfPrintString:'%9f') = ' 3.141593' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   156
    "/ right filled
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   157
    self assert:( (Float pi printfPrintString:'%-9f') = '3.141593 ' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   158
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   159
    "/ ShortFloat
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   160
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   161
    "/ too small
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   162
    self assert:( (ShortFloat pi printfPrintString:'%4f') = '3.141593' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   163
    self assert:( (ShortFloat pi printfPrintString:'%5f') = '3.141593' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   164
    self assert:( (ShortFloat pi printfPrintString:'%6f') = '3.141593' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   165
    self assert:( (ShortFloat pi printfPrintString:'%7f') = '3.141593' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   166
    "/ fit
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   167
    self assert:( (ShortFloat pi printfPrintString:'%8f') = '3.141593' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   168
    self assert:( (ShortFloat pi printfPrintString:'%4.2f') = '3.14' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   169
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   170
    "/ left filled
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   171
    self assert:( (ShortFloat pi printfPrintString:'%9f') = ' 3.141593' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   172
    "/ right filled
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   173
    self assert:( (ShortFloat pi printfPrintString:'%-9f') = '3.141593 ' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   174
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   175
    "/ LongFloat
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   176
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   177
    "/ too small
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   178
    self assert:( (LongFloat pi printfPrintString:'%4Lf') = '3.141593' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   179
    self assert:( (LongFloat pi printfPrintString:'%5Lf') = '3.141593' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   180
    self assert:( (LongFloat pi printfPrintString:'%6Lf') = '3.141593' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   181
    self assert:( (LongFloat pi printfPrintString:'%7Lf') = '3.141593' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   182
    "/ fit
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   183
    self assert:( (LongFloat pi printfPrintString:'%8Lf') = '3.141593' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   184
    self assert:( (LongFloat pi printfPrintString:'%4.2Lf') = '3.14' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   185
    "/ left filled
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   186
    self assert:( (LongFloat pi printfPrintString:'%9Lf') = ' 3.141593' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   187
    "/ right filled
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   188
    self assert:( (LongFloat pi printfPrintString:'%-9Lf') = '3.141593 ' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   189
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   190
    "/ QuadDouble
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   191
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   192
    "/ too small
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   193
    self assert:( (QDouble pi printfPrintString:'%4Lf') = '3.14159265358979323846' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   194
    self assert:( (QDouble pi printfPrintString:'%5Lf') = '3.14159265358979323846' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   195
    self assert:( (QDouble pi printfPrintString:'%6Lf') = '3.14159265358979323846' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   196
    self assert:( (QDouble pi printfPrintString:'%7Lf') = '3.14159265358979323846' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   197
    self assert:( (QDouble pi printfPrintString:'%18Lf') = '3.14159265358979323846' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   198
    self assert:( (QDouble pi printfPrintString:'%19Lf') = '3.14159265358979323846' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   199
    self assert:( (QDouble pi printfPrintString:'%20Lf') = '3.14159265358979323846' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   200
    self assert:( (QDouble pi printfPrintString:'%21Lf') = '3.14159265358979323846' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   201
    "/ fit
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   202
    self assert:( (QDouble pi printfPrintString:'%22Lf') = '3.14159265358979323846' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   203
    self assert:( (QDouble pi printfPrintString:'%4.2Lf') = '3.14' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   204
    "/ left filled
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   205
    self assert:( (QDouble pi printfPrintString:'%23Lf') = ' 3.14159265358979323846' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   206
    self assert:( (QDouble pi printfPrintString:'%30Lf') = '        3.14159265358979323846' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   207
    "/ right filled
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   208
    self assert:( (QDouble pi printfPrintString:'%-30Lf') = '3.14159265358979323846        ' ).
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   209
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   210
    "Created: / 03-07-2017 / 15:01:50 / cg"
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   211
! !
27b3c920623a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1622
diff changeset
   212
309
f5c2d68a0ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   213
!NumberTest methodsFor:'tests-reading'!
f5c2d68a0ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   214
f5c2d68a0ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   215
testReadFrom
f5c2d68a0ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   216
    self assert: 1.0e-14    = (Number readFrom: '1.0e-14').
f5c2d68a0ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   217
315
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
   218
    self assert: ('1' asNumber = 1).
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
   219
    self assert: ('10' asNumber = 10).
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
   220
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
   221
    self assert: ('-1' asNumber = -1).
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
   222
    self assert: ('-10' asNumber = -10).
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
   223
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
   224
    self assert: ('1e' asNumber = 1).
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
   225
    self assert: ('1e1' asNumber = 10).
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
   226
    self assert: ('1e10' asNumber = 10000000000).
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
   227
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
   228
    self assert: ('-1e' asNumber = -1).
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
   229
    self assert: ('-1e1' asNumber = -10).
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
   230
    self assert: ('-1e10' asNumber = -10000000000).
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
   231
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
   232
    self assert: ('1.0e' asNumber = 1.0).
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
   233
    self assert: ('1.0e1' asNumber = 10.0).
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
   234
    self assert: ('1.0e10' asNumber = 10000000000.0).
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
   235
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
   236
    self assert: ('-1.0e' asNumber = -1.0).
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
   237
    self assert: ('-1.0e1' asNumber = -10.0).
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
   238
    self assert: ('-1.0e10' asNumber = -10000000000.0).
dca04b42fcf3 read checks
Claus Gittinger <cg@exept.de>
parents: 311
diff changeset
   239
311
097badcf10ec more tests
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   240
    self assert: ('22.2' asNumber = 22.2).
097badcf10ec more tests
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   241
    self assert: ('-22.2' asNumber = -22.2).
097badcf10ec more tests
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   242
309
f5c2d68a0ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   243
    Smalltalk isSmalltalkX ifTrue:[
1622
ced5fda31c2e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1447
diff changeset
   244
        "/ st/x requires this:
311
097badcf10ec more tests
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   245
1622
ced5fda31c2e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1447
diff changeset
   246
        self assert: ((Number readSmalltalkSyntaxFrom:'10r22.2') = 22.2).
ced5fda31c2e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1447
diff changeset
   247
        self assert: ((Number readSmalltalkSyntaxFrom:'10r22.2s5') = 22.2).
ced5fda31c2e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1447
diff changeset
   248
ced5fda31c2e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1447
diff changeset
   249
        self assert: ((Number readSmalltalkSyntaxFrom:'10r-22.2') = -22.2).
ced5fda31c2e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1447
diff changeset
   250
        self assert: ((Number readSmalltalkSyntaxFrom:'10r-22.2s5') = -22.2).
311
097badcf10ec more tests
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   251
1622
ced5fda31c2e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1447
diff changeset
   252
        self assert: 2r1e26     = (Number readSmalltalkSyntaxFrom: '2r1e26').
311
097badcf10ec more tests
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   253
1622
ced5fda31c2e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1447
diff changeset
   254
        self assert: ('-1q' asNumber = -1).
ced5fda31c2e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1447
diff changeset
   255
        self assert: ('-1q' asNumber class == LongFloat).
ced5fda31c2e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1447
diff changeset
   256
ced5fda31c2e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1447
diff changeset
   257
        self assert: ('-1q1' asNumber = -10).
ced5fda31c2e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1447
diff changeset
   258
        self assert: ('-1q10' asNumber = -10000000000).
ced5fda31c2e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1447
diff changeset
   259
309
f5c2d68a0ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   260
    ] ifFalse:[
1622
ced5fda31c2e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1447
diff changeset
   261
        "/ squeak allows this:
ced5fda31c2e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1447
diff changeset
   262
        self assert: 2r1e26     = (Number readFrom: '2r1e26').
ced5fda31c2e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1447
diff changeset
   263
ced5fda31c2e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1447
diff changeset
   264
        self assert: ('10r22.2' asNumber = 22.2).
ced5fda31c2e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1447
diff changeset
   265
        self assert: ('10r22.2s5' asNumber = 22.2).
311
097badcf10ec more tests
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   266
1622
ced5fda31c2e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1447
diff changeset
   267
        self assert: ('10r-22.2' asNumber = -22.2).
ced5fda31c2e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1447
diff changeset
   268
        self assert: ('10r-22.2s5' asNumber = -22.2).
ced5fda31c2e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1447
diff changeset
   269
    ].
311
097badcf10ec more tests
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   270
1622
ced5fda31c2e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 1447
diff changeset
   271
    "Modified: / 20-06-2017 / 14:05:37 / cg"
309
f5c2d68a0ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   272
! !
f5c2d68a0ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   273
242
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   274
!NumberTest class methodsFor:'documentation'!
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   276
version
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   277
    ^ '$Header$'
43a9bab802ff initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   278
! !
1072
ee32c0daddfb category
Claus Gittinger <cg@exept.de>
parents: 670
diff changeset
   279