Skip to content

Commit

Permalink
Implement equality for Dollar
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiosilveira authored Sep 28, 2022
2 parents fd81150 + e75fb42 commit 07a740a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ describe('Multi currency money', () => {
expect(product.amount).toEqual(15);
});
});

describe('equality', () => {
it('should consider an object representing $5 equals to another object representing $5', () => {
expect(new Dollar(5).equals(new Dollar(5))).toBe(true);
});
});
});
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ export default class Dollar {
times(multiplier: number): Dollar {
return new Dollar(this.amount * multiplier);
}

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

0 comments on commit 07a740a

Please sign in to comment.