Skip to content

Commit

Permalink
✨ 【第12章 設計とメタファー】 $5 + 5 CHF を達成するためにまずは簡単な $5 + $5 の実装から始める
Browse files Browse the repository at this point in the history
・$5 + 5 CHF を達成するには熟考する必要があるため、まずは簡単な $5 + $5 ができるようなメソッドを実装する
  • Loading branch information
dodonki1223 committed Dec 19, 2021
1 parent f7a5ed8 commit f293db0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
9 changes: 5 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
- [ ] $5 + 10 CHF = $10(レートが 2:1 の場合)
- [x] $5 + $5 = $10
- [ ] Money の丸め処理どうする?
- [ ] hashCode()
- [ ] 他のオブジェクトとの等価性比較
- [ ] 5CHF * 2 = 10CHF
- [x] $5 * 2 = $10
- [x] amount を private にする
- [x] Dollar の副作用どうする?
- [ ] Money の丸め処理どうする?
- [x] nullとの等価性比較
- [x] equals()メソッドの実装
- [ ] hashCode()
- [ ] 他のオブジェクトとの等価性比較
- [ ] 5CHF * 2 = 10CHF
- [x] Dollar と Franc の重複
- [x] equalsの一般化
- [x] timesの一般化
Expand Down
5 changes: 5 additions & 0 deletions src/__tests__/money.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ test('times', () => {
expect(five.times(2)).toEqual(Money.dollar(10));
expect(five.times(3)).toEqual(Money.dollar(15));
});

test('simple addition', () => {
const sum :Money = Money.dollar(5).plus(Money.dollar(5));
expect(sum).toEqual(Money.dollar(10));
});
4 changes: 4 additions & 0 deletions src/money.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ export class Money {
toString() {
return `${this.amount} ${this.currency}`
}

plus(addend: Money):Money {
return new Money(this.amount + addend.amount, this.currency)
}
}

0 comments on commit f293db0

Please sign in to comment.