Skip to content

Commit

Permalink
✨ 【第5章 原則をあえて破るとき】 重複排除を行わず開発速度重視でフランを追加する
Browse files Browse the repository at this point in the history
TDDの順序は以下の通りで今回は 4 に該当する
 1. テストを書く
 2. コンパイラを通す
 3. テストを走らせ、失敗を確認する
 4. テストを通す
 5. 重複を排除する

フランの追加でいきなり重複の排除を書こうとするとすぐには書けないため、開発速度重視で良い設計の原則を破ることとする
  • Loading branch information
dodonki1223 committed Dec 12, 2021
1 parent 9add075 commit 9abaafc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
- [x] equals()メソッドの実装
- [ ] hashCode()
- [ ] 他のオブジェクトとの等価性比較
- [ ] 5CHF * 2 = 10CHF
20 changes: 20 additions & 0 deletions src/__tests__/franc.test.ts
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();
});
16 changes: 16 additions & 0 deletions src/franc.ts
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
}
}

0 comments on commit 9abaafc

Please sign in to comment.