Skip to content

Commit

Permalink
✨ 【第3章 三角測量】equals メソッドのテストを実装しとりあえずテストが成功するまで実装する
Browse files Browse the repository at this point in the history
なぜ equals メソッドを実装しなければならないのか?(以下の理由をつらつらと記載
・今回使っている Dollar オブジェクトは Value Object パターンと呼ばれている。
・Value Object には、コンストラクタで設定したインスタンス変数の値が変わってはならないという制約がある
・Value Object であるためには操作はすべて新しいオブジェクトを返さなければならない
・Value Object は equals メソッドを実装しなければならい
  • Loading branch information
dodonki1223 committed Dec 7, 2021
1 parent 0570b0f commit cae0187
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
- [ ] amount を private にする
- [x] Dollar の副作用どうする?
- [ ] Money の丸め処理どうする?
- [ ] equals()メソッドの実装
5 changes: 5 additions & 0 deletions src/__tests__/dollar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ test('times', () => {
expect(five.times(2).amount).toBe(10);
expect(five.times(3).amount).toBe(15);
});

test('equals', () => {
expect(new Dollar(5).equals(new Dollar(5))).toBeTruthy();
expect(new Dollar(5).equals(new Dollar(6))).toBeFalsy();
});
4 changes: 4 additions & 0 deletions src/dollar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ export class Dollar {
times(multiplier: number) {
return new Dollar(this.amount * multiplier)
}

equals(dollar: Dollar) {
return true
}
}

0 comments on commit cae0187

Please sign in to comment.