-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ 【第5章 原則をあえて破るとき】 重複排除を行わず開発速度重視でフランを追加する
TDDの順序は以下の通りで今回は 4 に該当する 1. テストを書く 2. コンパイラを通す 3. テストを走らせ、失敗を確認する 4. テストを通す 5. 重複を排除する フランの追加でいきなり重複の排除を書こうとするとすぐには書けないため、開発速度重視で良い設計の原則を破ることとする
- Loading branch information
1 parent
9add075
commit 9abaafc
Showing
3 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
- [x] equals()メソッドの実装 | ||
- [ ] hashCode() | ||
- [ ] 他のオブジェクトとの等価性比較 | ||
- [ ] 5CHF * 2 = 10CHF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Franc } from '../franc'; | ||
|
||
test('times', () => { | ||
const five = new Franc(5); | ||
|
||
expect(five.times(2)).toEqual(new Franc(10)); | ||
expect(five.times(3)).toEqual(new Franc(15)); | ||
}); | ||
|
||
test('equals', () => { | ||
expect(new Franc(5).equals(new Franc(5))).toBeTruthy(); | ||
expect(new Franc(5).equals(new Franc(6))).toBeFalsy(); | ||
}); | ||
|
||
test('null equals', () => { | ||
const five = new Franc(5); | ||
const ten = five.times(2); | ||
|
||
expect(ten.equals(null)).toBeFalsy(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export class Franc { | ||
constructor(private readonly amount: number) { | ||
} | ||
|
||
times(multiplier: number) { | ||
return new Franc(this.amount * multiplier) | ||
} | ||
|
||
equals(franc: Franc | null) { | ||
if (franc === null) { | ||
return false; | ||
} | ||
|
||
return this.amount === franc.amount | ||
} | ||
} |