RegressionTests__IntegerTest.st
changeset 1307 f2b5a843d7df
parent 1305 d8800e68af7a
child 1312 b7172ac2c2bd
equal deleted inserted replaced
1306:9b2ba728b70e 1307:f2b5a843d7df
   840     "
   840     "
   841      self basicNew testConstants
   841      self basicNew testConstants
   842     "
   842     "
   843 !
   843 !
   844 
   844 
   845 testDivision
   845 testDivision1
   846     |a b op rslt|
   846     |a b op rslt|
   847 
   847 
   848     "/ 10 divMod:3       -> #(3 1)   because 3*3 + 1 = 10
   848     "/ 10 divMod:3       -> #(3 1)   because 3*3 + 1 = 10
   849     "/ 10 divMod:-3      -> #(-4 -2) because -4*-3 + (-2) = 10
   849     "/ 10 divMod:-3      -> #(-4 -2) because -4*-3 + (-2) = 10
   850     "/ -10 divMod:3      -> #(-4 2)  because -4*3 + 3 = -10   
   850     "/ -10 divMod:3      -> #(-4 2)  because -4*3 + 3 = -10   
  1174     self assert:((rslt := 16 perform:#quo: with: b) == 2).
  1174     self assert:((rslt := 16 perform:#quo: with: b) == 2).
  1175     self assert:((rslt := a perform:#quo: with: b) == 2).
  1175     self assert:((rslt := a perform:#quo: with: b) == 2).
  1176 
  1176 
  1177     "
  1177     "
  1178      self basicNew testDivision
  1178      self basicNew testDivision
       
  1179     "
       
  1180 !
       
  1181 
       
  1182 testDivision2
       
  1183     |nr|
       
  1184     
       
  1185     2 to:17 do:[:m |
       
  1186         nr := 1.
       
  1187         1 to:1000 do:[:n |
       
  1188             nr := nr * m
       
  1189         ].
       
  1190         1 to:1000 do:[:n |
       
  1191             nr := nr / m
       
  1192         ].
       
  1193         self assert:(nr == 1).
       
  1194     ].
       
  1195 
       
  1196     "
       
  1197      self new testDivision2
       
  1198     "
       
  1199 !
       
  1200 
       
  1201 testDivision3
       
  1202     |nr|
       
  1203     
       
  1204     #( 
       
  1205         16r00000000000000003F 
       
  1206         16r000000000000003FFF 
       
  1207         16r0000000000003FFFFF 
       
  1208         16r00000000003FFFFFFF 
       
  1209         16r000000003FFFFFFFFF
       
  1210         16r0000003FFFFFFFFFFF
       
  1211         16r00003FFFFFFFFFFFFF
       
  1212         16r003FFFFFFFFFFFFFFF
       
  1213         16r3FFFFFFFFFFFFFFFFF
       
  1214 
       
  1215         16r000000000000000040 
       
  1216         16r0000000000000040FF 
       
  1217         16r00000000000040FFFF 
       
  1218         16r000000000040FFFFFF 
       
  1219         16r0000000040FFFFFFFF
       
  1220         16r00000040FFFFFFFFFF
       
  1221         16r000040FFFFFFFFFFFF
       
  1222         16r0040FFFFFFFFFFFFFF
       
  1223         16r40FFFFFFFFFFFFFFFF
       
  1224 
       
  1225         16r00000000000000007F 
       
  1226         16r000000000000007FFF 
       
  1227         16r0000000000007FFFFF 
       
  1228         16r00000000007FFFFFFF 
       
  1229         16r000000007FFFFFFFFF
       
  1230         16r0000007FFFFFFFFFFF
       
  1231         16r00007FFFFFFFFFFFFF
       
  1232         16r007FFFFFFFFFFFFFFF
       
  1233         16r7FFFFFFFFFFFFFFFFF
       
  1234 
       
  1235         16r0000000000000000FF 
       
  1236         16r00000000000000FFFF 
       
  1237         16r000000000000FFFFFF 
       
  1238         16r0000000000FFFFFFFF 
       
  1239         16r00000000FFFFFFFFFF
       
  1240         16r000000FFFFFFFFFFFF
       
  1241         16r0000FFFFFFFFFFFFFF
       
  1242         16r00FFFFFFFFFFFFFFFF
       
  1243         16rFFFFFFFFFFFFFFFFFF
       
  1244     ) do:[:m |
       
  1245         nr := 1.
       
  1246         1 to:1000 do:[:n |
       
  1247             nr := nr * m
       
  1248         ].
       
  1249         1 to:1000 do:[:n |
       
  1250             nr := nr / m
       
  1251         ].
       
  1252         self assert:(nr == 1).
       
  1253     ].
       
  1254 
       
  1255     "
       
  1256      self new testDivision2
  1179     "
  1257     "
  1180 !
  1258 !
  1181 
  1259 
  1182 testEncodeDecode
  1260 testEncodeDecode
  1183     self assert:(1 encodeAsBCD hexPrintString = '1').
  1261     self assert:(1 encodeAsBCD hexPrintString = '1').
  3468     t := Integer readFrom:'10000000000' radix:16.
  3546     t := Integer readFrom:'10000000000' radix:16.
  3469     self assert:((t + 1) hexPrintString = '10000000001').
  3547     self assert:((t + 1) hexPrintString = '10000000001').
  3470 
  3548 
  3471     "
  3549     "
  3472      self basicNew testReading1
  3550      self basicNew testReading1
       
  3551     "
       
  3552 !
       
  3553 
       
  3554 testReadingPrinting1
       
  3555     |nr inString outString|
       
  3556 
       
  3557     #(2 3 4 5 8 10 16) do:[:radix |
       
  3558         Transcript showCR:('testing radix %1...' bindWith:radix).
       
  3559         1 to:1000 do:[:len |
       
  3560             inString := '1',(String new:len withAll:$0).
       
  3561             nr := Integer readFrom:inString radix:radix.
       
  3562             outString := nr printStringRadix:radix.
       
  3563             self assert:(outString = inString).
       
  3564         ].    
       
  3565     ].
       
  3566     
       
  3567     "
       
  3568      self basicNew testReadingPrinting1
  3473     "
  3569     "
  3474 !
  3570 !
  3475 
  3571 
  3476 testSmallIntegerArithmetic
  3572 testSmallIntegerArithmetic
  3477     "arithmetic tests.
  3573     "arithmetic tests.