help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] Re: numerics tests


From: Paolo Bonzini
Subject: [Help-smalltalk] Re: numerics tests
Date: Tue, 22 May 2007 08:58:13 +0200
User-agent: Thunderbird 2.0.0.0 (Macintosh/20070326)

Paolo Bonzini wrote:
Enabling them found a bug in Fractions. Which shows that this patch series is good! :-)

ENOPATCH

Paolo
2007-05-22  Paolo Bonzini  <address@hidden>

        * kernel/Fraction.st: Fix multiplication/division by zero.
        * numerics/Basic.st: Fix rounding.

        * numerics/NumericsAdds.st: Make all tests pass.
        * numerics/NumericsTests.st: Update usage of SUnit logging API.

--- orig/kernel/Fraction.st
+++ mod/kernel/Fraction.st
@@ -92,6 +92,8 @@ numerator
     (aNumber generality = self generality)
        ifFalse: [^self retryMultiplicationCoercing: aNumber].
 
+    aNumber numerator = 0 ifTrue: [ ^aNumber ].
+    self numerator = 0 ifTrue: [ ^self ].
     num := numerator * aNumber numerator.
     den := denominator * aNumber denominator.
 
@@ -165,6 +167,8 @@ numerator
     (aNumber generality = self generality)
        ifFalse: [^self retryDivisionCoercing: aNumber].
 
+    aNumber numerator = 0 ifTrue: [ ^self zeroDivide ].
+    self numerator = 0 ifTrue: [ ^self ].
     num := numerator * aNumber denominator.
     den := denominator * aNumber numerator.
     gcd := (numerator gcd: aNumber numerator) * 


--- orig/numerics/Basic.st
+++ mod/numerics/Basic.st
@@ -676,7 +676,7 @@ normalize: aNumber 
                 Initial code: 9/6/99 "
 
     exponent := (self class digits - (aNumber log: 10)) floor.
-    mantissa := (aNumber * (10 raisedToInteger: exponent)) truncated.
+    mantissa := (aNumber * (10 raisedToInteger: exponent)) rounded.
     ^self! !
 
 



--- orig/numerics/NumericsAdds.st
+++ mod/numerics/NumericsAdds.st
@@ -35,11 +35,11 @@ random
 !Smalltalk.Number class methodsFor: 'numerics'!
 
 random
-    "Answers a random number between 0 and the receiver
+    "Answers a random number between 0 and 1.
      (c) Copyrights Didier BESSET, 1999, all rights reserved.
      Initial code: 17/2/99 "
 
-    ^Dhb.DhbMitchellMooreGenerator new floatValue * self! !
+    ^Dhb.DhbMitchellMooreGenerator new floatValue! !
 
 !Smalltalk.Number methodsFor: 'numerics'!
 
@@ -205,7 +205,7 @@ positiveRectangle
 
 asVector
     ^(Dhb.DhbVector new: self size)
-        replaceElementsFrom: 1 to: self size withArray: self startingAt: 1
+        replaceFrom: 1 to: self size with: self startingAt: 1
 ! !
 
 !Dhb.DhbPolynomial methodsFor: 'numerics'!


--- orig/numerics/NumericsTests.st
+++ mod/numerics/NumericsTests.st
@@ -23,7 +23,7 @@ TestCase subclass:#DhbTestCase
 
 !DhbTestCase methodsFor: 'logging'!
 
-logPolicy
+defaultLogPolicyClass
     ^TestVerboseLog
 ! !
 


--- orig/packages.xml.in
+++ mod/packages.xml.in
@@ -239,7 +239,10 @@
 <package>
   <name>DhbNumericalMethods</name>
   <namespace>Dhb</namespace>
+
+  <tests>Dhb.DhbTestCase*</tests>
   <prereq>SUnit</prereq>
+
   <filein>Basic.st</filein>
   <filein>Statistics.st</filein>
   <filein>RNG.st</filein>


--- orig/tests/testsuite.at
+++ mod/tests/testsuite.at
@@ -139,6 +139,7 @@ AT_ANSI_TEST([ZeroDivideFactoryANSITest]
 
 AT_BANNER([Other packages.])
 AT_PACKAGE_TEST([Continuations])
+AT_PACKAGE_TEST([DhbNumericalMethods])
 AT_OPTIONAL_PACKAGE_TEST([GDBM])
 AT_PACKAGE_TEST([MD5])
 AT_OPTIONAL_PACKAGE_TEST([ZLib])




reply via email to

[Prev in Thread] Current Thread [Next in Thread]