Skip to content

Commit 57dc57d

Browse files
Ansi says to use rounded rather than truncated : ``` 5.6.2.16.Message: asInteger Synopsis Answer an integer approximating the receiver. Definition: <number> Answer the result of sending #rounded to the receiver. ```` Changed to `rounded`, ran all the tests that seemed relevant, and added a testcase for the issue at hand.
1 parent d328533 commit 57dc57d

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"
2+
A MagnitudeTest is a test class for testing the behavior of Magnitude
3+
"
4+
Class {
5+
#name : #MagnitudeTest,
6+
#superclass : #TestCase,
7+
#category : #'Kernel-Tests-Numbers'
8+
}

src/Kernel-Tests/NumberTest.class.st

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ Class {
77
#category : #'Kernel-Tests-Numbers'
88
}
99

10+
{ #category : #test }
11+
NumberTest >> testAsInteger [
12+
self assert: 0.5 asInteger equals: 1.
13+
self assert: (1/2) asInteger equals: 1
14+
15+
]
16+
1017
{ #category : #tests }
1118
NumberTest >> testFractionPart [
1219

src/Kernel/Number.class.st

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ Number >> asFloat [
266266
Number >> asInteger [
267267
"Answer an Integer nearest the receiver toward zero."
268268

269-
^self truncated
269+
^self rounded
270270
]
271271

272272
{ #category : #converting }

0 commit comments

Comments
 (0)