diff --git a/src/__tests__/money.test.ts b/src/__tests__/money.test.ts index d794737..9889a10 100644 --- a/src/__tests__/money.test.ts +++ b/src/__tests__/money.test.ts @@ -1,7 +1,7 @@ // import { Dollar } from '../dollar'; // import { Franc } from '../franc'; -import { Bank } from '../bank'; import { Money } from '../money'; +import { Bank } from '../bank'; test('equals', () => { expect(Money.dollar(5).equals(Money.dollar(5))).toBeTruthy(); @@ -34,7 +34,7 @@ test('times', () => { }); test('simple addition', () => { - const sum :Money = Money.dollar(5).plus(Money.dollar(5)); + const sum = Money.dollar(5).plus(Money.dollar(5)); expect(sum).toEqual(Money.dollar(10)); const bank = new Bank(); diff --git a/src/bank.ts b/src/bank.ts index aa52ce7..7b32108 100644 --- a/src/bank.ts +++ b/src/bank.ts @@ -1,7 +1,8 @@ +import { Expression } from './expression'; import { Money } from './money'; export class Bank { - reduce(sum: Money, currency: string):Money { + reduce(sum: Expression, currency: string):Money { return Money.dollar(10); } } diff --git a/src/expression.ts b/src/expression.ts new file mode 100644 index 0000000..6640bef --- /dev/null +++ b/src/expression.ts @@ -0,0 +1,2 @@ +export interface Expression{ +} diff --git a/src/money.ts b/src/money.ts index 442019b..e735f36 100644 --- a/src/money.ts +++ b/src/money.ts @@ -1,4 +1,6 @@ -export class Money { +import { Expression } from "./expression"; + +export class Money implements Expression { constructor(protected readonly amount: number, public readonly currency: string) { } @@ -26,7 +28,7 @@ export class Money { return `${this.amount} ${this.currency}` } - plus(addend: Money):Money { + plus(addend: Money):Expression { return new Money(this.amount + addend.amount, this.currency) } }