Skip to content

Commit

Permalink
Franc (CHF) multiplication
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiosilveira committed Sep 28, 2022
2 parents 4db49eb + 7f75e45 commit 2afe45b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/franc/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Franc from '.';

describe('Franc', () => {
describe('multiplication', () => {
it('should multiply $5 by 2 and get $10', () => {
const five = new Franc(5);
const product = five.times(2);
expect(product.equals(new Franc(10))).toBe(true);
});

it('should preserve the initial dollar amount when multiplying multiple times', () => {
const five = new Franc(5);
let product: Franc = five.times(2);
expect(product.equals(new Franc(10))).toBe(true);
product = five.times(3);
expect(product.equals(new Franc(15))).toBe(true);
});
});
});
15 changes: 15 additions & 0 deletions src/franc/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default class Franc {
private amount: number;

constructor(amount: number) {
this.amount = amount;
}

times(multiplier: number): Franc {
return new Franc(this.amount * multiplier);
}

equals(dollar: Object): boolean {
return this.amount == (dollar as Franc).amount;
}
}

0 comments on commit 2afe45b

Please sign in to comment.