-
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.
✨ 【第6章 テスト不足に気づいたら】 重複コード排除のため Money クラスに equals メソッドを追加する
- Loading branch information
1 parent
ce47286
commit e8384a9
Showing
6 changed files
with
23 additions
and
43 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
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
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,12 @@ | ||
import { Money } from '../money'; | ||
|
||
test('equals', () => { | ||
expect(new Money(5).equals(new Money(5))).toBeTruthy(); | ||
expect(new Money(5).equals(new Money(6))).toBeFalsy(); | ||
}); | ||
|
||
test('null equals', () => { | ||
const five = new Money(5); | ||
|
||
expect(five.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 |
---|---|---|
@@ -1,19 +1,11 @@ | ||
import { Money } from "./money"; | ||
|
||
export class Dollar extends Money { | ||
constructor(amount: number) { | ||
constructor(amount: number) { | ||
super(amount); | ||
} | ||
|
||
times(multiplier: number) { | ||
return new Dollar(this.amount * multiplier) | ||
} | ||
|
||
equals(dollar: Dollar | null) { | ||
if (dollar === null) { | ||
return false; | ||
} | ||
|
||
return this.amount === dollar.amount | ||
} | ||
} |
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 |
---|---|---|
@@ -1,19 +1,11 @@ | ||
import { Money } from "./money"; | ||
|
||
export class Franc extends Money { | ||
export class Franc extends Money { | ||
constructor(amount: number) { | ||
super(amount); | ||
} | ||
} | ||
|
||
times(multiplier: number) { | ||
return new Franc(this.amount * multiplier) | ||
} | ||
|
||
equals(franc: Franc | null) { | ||
if (franc === null) { | ||
return false; | ||
} | ||
|
||
return this.amount === franc.amount | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,12 @@ | ||
export class Money { | ||
constructor(protected readonly amount: number) { | ||
} | ||
|
||
equals(money: Money | null) { | ||
if (money === null) { | ||
return false; | ||
} | ||
|
||
return this.amount === money.amount | ||
} | ||
} |