Skip to content

Commit

Permalink
Money addition
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiosilveira authored Sep 29, 2022
2 parents 9ecc895 + bd7cb75 commit ba93485
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/bank/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Expression from '../expression';
import Money from '../money';

export default class Bank {
reduce(to: Expression, currency: string): Money {
return Money.dollar(10);
}
}
1 change: 1 addition & 0 deletions src/expression/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default interface Expression {}
14 changes: 14 additions & 0 deletions src/money/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import Expression from '../expression';
import Money from '../money';
import Bank from '../bank';

describe('Money', () => {
it.todo('should sum $5 + 10CHF as being $10 if exchange rate is 2:1');

describe('addition', () => {
it('should sum $5 + $5 and get $10', () => {
const five: Money = Money.dollar(5);
const sum: Expression = five.plus(five);
const bank = new Bank();

const reduced: Money = bank.reduce(sum, 'USD');

expect(reduced).toEqual(Money.dollar(10));
});
});

describe('multiplication', () => {
it('should multiply $5 by 2 and get $10', () => {
const five: Money = Money.dollar(5);
Expand Down
6 changes: 6 additions & 0 deletions src/money/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Expression from '../expression';

export default class Money {
private _amount: number;
private _currency: string;
Expand Down Expand Up @@ -28,6 +30,10 @@ export default class Money {
return new Money(this.amount * multiplier, this.currency);
}

plus(money: Money): Expression {
return {};
}

get currency(): string {
return this._currency;
}
Expand Down

0 comments on commit ba93485

Please sign in to comment.