Skip to content

Commit

Permalink
add plus operation to Expression interface
Browse files Browse the repository at this point in the history
Task list:
- $5 + 10CHF = $10 if rate is 2:1 🎯 πŸŽ‰ ✨
- $5 + $5 = $10 βœ…
- Return Money from $5 + $5
- Bank.reduce(Money) βœ…
- Reduce Money with conversion βœ…
- Reduce(Bank, String) βœ…
- Sum.plus
- Expression.times
  • Loading branch information
kaiosilveira committed Sep 29, 2022
1 parent d6d7a43 commit d6ebef8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/expression/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Money from '../money';

export default interface Expression {
reduce(bank: Bank, to: string): Money;
plus(addend: Expression): Expression;
}

export class Sum implements Expression {
Expand All @@ -27,4 +28,8 @@ export class Sum implements Expression {
this.augend.reduce(bank, to).amount + this.addend.reduce(bank, to).amount;
return new Money(amount, to);
}

plus(addend: Expression): Expression {
throw new Error('Method not implemented.');
}
}
4 changes: 2 additions & 2 deletions src/money/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import Bank from '../bank';

describe('Money', () => {
it('should sum $5 + 10CHF as being $10 if exchange rate is 2:1', () => {
const fiveBucks: Money = Money.dollar(5);
const tenFrancs: Money = Money.franc(10);
const fiveBucks: Expression = Money.dollar(5);
const tenFrancs: Expression = Money.franc(10);
const bank: Bank = new Bank();
bank.addRate('CHF', 'USD', 2);

Expand Down

0 comments on commit d6ebef8

Please sign in to comment.