Skip to content

Commit

Permalink
Ch.16 done
Browse files Browse the repository at this point in the history
  • Loading branch information
yujihamaguchi committed Jan 5, 2020
1 parent 1cf9296 commit 7fc41c5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Example-TDD-Tests/MoneyTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ MoneyTest >> testPlusReturnsSum [
self assert: sum addend equals: five
]

{ #category : #tests }
MoneyTest >> testPlusSumMoney [
| fiveBucks bank tenFrancs sum result |
fiveBucks := Money dollar: 5.
tenFrancs := Money franc: 10.
bank := Bank new.
bank addRate: (Rate from: 'CHF' to: 'USD' rate: 2).
sum := (Sum augend: fiveBucks addend: tenFrancs) plus: fiveBucks .
result := sum reduceAt: bank to: 'USD'.
self assert: result equals: (Money dollar: 15)
]

{ #category : #tests }
MoneyTest >> testReduceMoney [
| bank result |
Expand Down Expand Up @@ -86,3 +98,15 @@ MoneyTest >> testSimpleAddtion [
reduced := bank reduce: sum to: 'USD'.
self assert: reduced equals: (Money dollar: 10)
]

{ #category : #tests }
MoneyTest >> testSumTimes [
| fiveBucks tenFrancs bank sum result |
fiveBucks := Money dollar: 5.
tenFrancs := Money franc: 10.
bank := Bank new.
bank addRate: (Rate from: 'CHF' to: 'USD' rate: 2).
sum := (Sum augend: fiveBucks addend: tenFrancs) times: 2.
result := sum reduceAt: bank to: 'USD'.
self assert: result equals: (Money dollar: 20)
]
12 changes: 12 additions & 0 deletions src/Example-TDD/Sum.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,22 @@ Sum >> augend: aMoney [
augend := aMoney
]

{ #category : #arithmetic }
Sum >> plus: anObject [
^ Sum augend: self addend: anObject
]

{ #category : #enumerating }
Sum >> reduceAt: aBank to: aCurrency [
| sum |
sum := (augend reduceAt: aBank to: aCurrency) amount
+ (addend reduceAt: aBank to: aCurrency) amount.
^ Money new setAmount: sum currency: aCurrency
]

{ #category : #arithmetic }
Sum >> times: aMultiplier [
^ Sum
augend: (self augend times: aMultiplier)
addend: (self addend times: aMultiplier)
]

0 comments on commit 7fc41c5

Please sign in to comment.