Skip to content

Commit

Permalink
Merge pull request #1628 from astares/22246-Provide-digitSum-in-Integ…
Browse files Browse the repository at this point in the history
…er--tests

22246 Provide #digitSum in Integer + tests
  • Loading branch information
Ducasse committed Jul 13, 2018
2 parents 9d83892 + e081a55 commit 87fa773
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Kernel-Tests/IntegerTest.class.st
Expand Up @@ -457,6 +457,18 @@ IntegerTest >> testDifferentBases [
self assert: -36rZYXWVUTSRQPONMLKJIHGFEDCBA9876543210 equals: -106300512100105327644605138221229898724869759421181854980.
]

{ #category : #'tests - other' }
IntegerTest >> testDigitSum [

self assert: 1234 digitSum equals: 10
]

{ #category : #'tests - other' }
IntegerTest >> testDigitSumOnNegative [

self assert: -1234 digitSum equals: 10
]

{ #category : #'tests - basic' }
IntegerTest >> testDigitsAccess [

Expand Down
7 changes: 7 additions & 0 deletions src/Kernel/Integer.class.st
Expand Up @@ -951,6 +951,13 @@ Integer >> digitSubtract: arg [
^ sum normalize
]

{ #category : #accessing }
Integer >> digitSum [
"Returns the digit sum of the receiver"

^self abs asString inject: 0 into: [:value :new| value + new digitValue]
]

{ #category : #'truncation and round off' }
Integer >> floor [
"Refer to the comment in Number|floor."
Expand Down

0 comments on commit 87fa773

Please sign in to comment.