Skip to content

Commit

Permalink
✨ 【第15章 テスト任せとコンパイラ任せ】 換算処理が抜けていたため追加する
Browse files Browse the repository at this point in the history
  • Loading branch information
dodonki1223 committed Dec 30, 2021
1 parent 6f3652d commit fa24b22
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/__tests__/money.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,12 @@ test('test reduce money different currency', () => {
const result = bank.reduce(Money.franc(2), 'USD');
expect(Money.dollar(1)).toEqual(result);
})

test('test mixed addition', () => {
const fiveBucks = Money.dollar(5);
const tenFrancs = Money.franc(10);
const bank = new Bank();
bank.addRate('CHF', 'USD', 2);
const result = bank.reduce(fiveBucks.plus(tenFrancs), 'USD');
expect(result).toEqual(Money.dollar(10));
})
4 changes: 3 additions & 1 deletion src/sum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export class Sum implements Expression {
}

reduce(bank: Bank, to: Currency):Money {
const amount :number = this.augend.amount + this.addend.amount;
const amount :number =
this.augend.reduce(bank, to).amount
+ this.addend.reduce(bank, to).amount;
return new Money(amount, to);
}
}

0 comments on commit fa24b22

Please sign in to comment.