-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/andreasalstrup/CoShare into…
… GroupScreen
- Loading branch information
Showing
3 changed files
with
61 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { calculateBalance, Expense } from '../../helpers/calculateBalance'; | ||
|
||
describe('calculateBalance', () => { | ||
it('should handle no balances', () => { | ||
const result = calculateBalance([]); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
it('should handle a single user balance', () => { | ||
const expenses: Expense[] = [ | ||
{ user: 'Alice', amount: 50 }, | ||
]; | ||
const expectedBalance: Expense[] = [ | ||
{ user: 'Alice', amount: 0 } | ||
]; | ||
const result = calculateBalance(expenses); | ||
expect(result).toEqual(expect.arrayContaining(expectedBalance)); | ||
}); | ||
|
||
it('should handle multiple user balances', () => { | ||
const expenses: Expense[] = [ | ||
{ user: 'Alice', amount: 50 }, | ||
{ user: 'Bob', amount: 0 }, | ||
]; | ||
const expectedBalance: Expense[] = [ | ||
{ user: 'Alice', amount: 25 }, | ||
{ user: 'Bob', amount: -25 }, | ||
]; | ||
const result = calculateBalance(expenses); | ||
expect(result).toEqual(expect.arrayContaining(expectedBalance)); | ||
}); | ||
|
||
it('should handle multiple users with no balance', () => { | ||
const expenses: Expense[] = [ | ||
{ user: 'Alice', amount: 0 }, | ||
{ user: 'Bob', amount: 0 }, | ||
{ user: 'Charlie', amount: 0 }, | ||
]; | ||
const expectedBalance: Expense[] = [ | ||
{ user: 'Alice', amount: 0 }, | ||
{ user: 'Bob', amount: 0 }, | ||
{ user: 'Charlie', amount: 0 }, | ||
]; | ||
const result = calculateBalance(expenses); | ||
expect(result).toEqual(expect.arrayContaining(expectedBalance)); | ||
}); | ||
|
||
it('should handle large numbers', () => { | ||
const expenses: Expense[] = [ | ||
{ user: 'Alice', amount: Number.MAX_VALUE }, | ||
{ user: 'Bob', amount: 0 }, | ||
]; | ||
const expectedBalance: Expense[] = [ | ||
{ user: 'Alice', amount: Number.MAX_VALUE/2 }, | ||
{ user: 'Bob', amount: -Number.MAX_VALUE/2 }, | ||
]; | ||
const result = calculateBalance(expenses); | ||
expect(result).toEqual(expect.arrayContaining(expectedBalance)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
type Expense = { | ||
export type Expense = { | ||
user: string; | ||
amount: number; | ||
}; | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.