-
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.
・TypeScriptの循環参照でエラーになるため Dollar と Franc の実装を一旦 Money クラスに寄せる
- Loading branch information
1 parent
870259b
commit 76f6989
Showing
7 changed files
with
72 additions
and
32 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 |
---|---|---|
|
@@ -12,3 +12,4 @@ | |
- [x] equalsの一般化 | ||
- [ ] timesの一般化 | ||
- [x] FrancとDollarの比較 | ||
- [ ] 通貨の概念 |
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,8 +1,9 @@ | ||
import { Dollar } from '../dollar'; | ||
// import { Dollar } from '../dollar'; | ||
import { Money, Dollar } from '../money'; | ||
|
||
test('times', () => { | ||
const five = new Dollar(5); | ||
const five: Money = Money.dollar(5); | ||
|
||
expect(five.times(2)).toEqual(new Dollar(10)); | ||
expect(five.times(3)).toEqual(new Dollar(15)); | ||
}); |
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,8 +1,10 @@ | ||
import { Franc } from '../franc'; | ||
// import { Franc } from '../franc'; | ||
import { Money, Franc } from '../money'; | ||
|
||
test('times', () => { | ||
const five = new Franc(5); | ||
const five: Money = Money.franc(5); | ||
|
||
expect(five.times(2)).toEqual(new Franc(10)); | ||
expect(five.times(3)).toEqual(new Franc(15)); | ||
}); | ||
|
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,20 +1,23 @@ | ||
import { Dollar } from '../dollar'; | ||
import { Franc } from '../franc'; | ||
import { Money } from '../money'; | ||
// import { Dollar } from '../dollar'; | ||
// import { Franc } from '../franc'; | ||
import { Money, Dollar, Franc } from '../money'; | ||
|
||
test('equals', () => { | ||
expect(new Money(5).equals(new Money(5))).toBeTruthy(); | ||
expect(new Money(5).equals(new Money(6))).toBeFalsy(); | ||
expect(new Franc(5).equals(new Franc(5))).toBeTruthy(); | ||
expect(new Franc(5).equals(new Franc(6))).toBeFalsy(); | ||
expect(new Dollar(5).equals(new Dollar(5))).toBeTruthy(); | ||
expect(new Dollar(5).equals(new Dollar(6))).toBeFalsy(); | ||
}); | ||
|
||
test('null equals', () => { | ||
const five = new Money(5); | ||
const francFive = new Franc(5); | ||
expect(francFive.equals(null)).toBeFalsy(); | ||
|
||
expect(five.equals(null)).toBeFalsy(); | ||
const dollarFive = new Dollar(6); | ||
expect(dollarFive.equals(null)).toBeFalsy(); | ||
}); | ||
|
||
test('equals Franc = Dollar', () => { | ||
expect(new Franc(5).equals(new Dollar(5))).toBeTruthy(); | ||
expect(new Franc(5).equals(new Dollar(6))).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,11 +1,11 @@ | ||
import { Money } from "./money"; | ||
// import { Money } from "./money"; | ||
|
||
export class Dollar extends Money { | ||
constructor(amount: number) { | ||
super(amount); | ||
} | ||
// export class Dollar extends Money { | ||
// constructor(amount: number) { | ||
// super(amount); | ||
// } | ||
|
||
times(multiplier: number) { | ||
return new Dollar(this.amount * multiplier) | ||
} | ||
} | ||
// times(multiplier: number) { | ||
// return new Dollar(this.amount * multiplier) | ||
// } | ||
// } |
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,11 +1,11 @@ | ||
import { Money } from "./money"; | ||
// import { Money } from "./money"; | ||
|
||
export class Franc extends Money { | ||
constructor(amount: number) { | ||
super(amount); | ||
} | ||
// export class Franc extends Money { | ||
// constructor(amount: number) { | ||
// super(amount); | ||
// } | ||
|
||
times(multiplier: number) { | ||
return new Franc(this.amount * multiplier) | ||
} | ||
} | ||
// times(multiplier: number) { | ||
// return new Franc(this.amount * multiplier) | ||
// } | ||
// } |
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