Skip to content

Commit

Permalink
Use rest param for calculate
Browse files Browse the repository at this point in the history
  • Loading branch information
williamgrosset committed Mar 8, 2024
1 parent 0a1089e commit 0e5b982
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ match.addPlayers(
new Player('3', 800)
)

const results = match.calculate(['1', '2', '3'])
const results = match.calculate('1', '2', '3')

/*
[
Expand Down Expand Up @@ -164,7 +164,7 @@ team2.addPlayers(new Player('3', 800), new Player('4', 700))
team3.addPlayers(new Player('5', 600), new Player('6', 500))
match.addTeams(team1, team2, team3)

const results = match.calculate(['1', '2', '3'])
const results = match.calculate('1', '2', '3')

/*
[
Expand Down Expand Up @@ -291,7 +291,7 @@ new FreeForAll(options?: Options)
static create(options?: Options, ...players: Player[]): FreeForAll
addPlayer(player: Player): this
addPlayers(...players: Player[]): this
calculate(playerIds: string[]): PlayerResult[]
calculate(...playerIds: string[]): PlayerResult[]
getResults(): PlayerResult[]
```

Expand Down Expand Up @@ -345,7 +345,7 @@ new TeamFreeForAll(options?: Options)
static create(options?: Options, ...teams: Team[]): TeamFreeForAll
addTeam(team: Team): this
addTeams(...teams: Team[]): this
calculate(teamIds: string[]): TeamResult[]
calculate(...teamIds: string[]): TeamResult[]
getResults(): TeamResult[]
```

Expand Down
16 changes: 8 additions & 8 deletions src/main/matches/free-for-all/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('FreeForAll', () => {

match.addPlayers(player1, player2)

const results = match.calculate(['1', '2'])
const results = match.calculate('1', '2')

expect(results).toStrictEqual([
{
Expand All @@ -47,7 +47,7 @@ describe('FreeForAll', () => {

match.addPlayers(player1, player2)

const results = match.calculate(['2', '1'])
const results = match.calculate('2', '1')

expect(results).toStrictEqual([
{
Expand All @@ -69,7 +69,7 @@ describe('FreeForAll', () => {

match.addPlayers(player1, player2, player3)

const results = match.calculate(['1', '2', '3'])
const results = match.calculate('1', '2', '3')

expect(results).toStrictEqual([
{
Expand All @@ -95,7 +95,7 @@ describe('FreeForAll', () => {

match.addPlayers(player1, player2, player3)

const results = match.calculate(['2', '3', '1'])
const results = match.calculate('2', '3', '1')

expect(results).toStrictEqual([
{
Expand All @@ -121,7 +121,7 @@ describe('FreeForAll', () => {

match.addPlayers(player1, player2, player3)

const results = match.calculate(['3', '2', '1'])
const results = match.calculate('3', '2', '1')

expect(results).toStrictEqual([
{
Expand All @@ -147,7 +147,7 @@ describe('FreeForAll', () => {
}

const results = match.calculate(
Array.from({ length: 100 }, (_, i) => (i + 1).toString())
...Array.from({ length: 100 }, (_, i) => (i + 1).toString())
)

expect(results[0].elo).toBe(1016)
Expand All @@ -164,7 +164,7 @@ describe('FreeForAll', () => {
const match = new FreeForAll({ minPlayers: 3 })

match.addPlayers(player1, player2)
match.calculate(['1', '2'])
match.calculate('1', '2')
}).toThrow(ErrorType.MIN_PLAYERS)
})

Expand All @@ -175,7 +175,7 @@ describe('FreeForAll', () => {
const match = new FreeForAll()

match.addPlayers(player1, player2)
match.calculate(['1'])
match.calculate('1')
}).toThrow(ErrorType.SIZE_MISMATCH)
})
})
2 changes: 1 addition & 1 deletion src/main/matches/free-for-all/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class FreeForAll extends Match {
return this
}

calculate(playerIds: string[]): PlayerResult[] {
calculate(...playerIds: string[]): PlayerResult[] {
if (this.completed) {
throw new MatchError(ErrorType.MATCH_COMPLETE)
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/matches/team-free-for-all/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('TeamFreeForAll', () => {
})

test('calculates elo for team 1 winning', () => {
const results = match.calculate(['1', '2', '3'])
const results = match.calculate('1', '2', '3')
expect(results).toStrictEqual([
{
id: '1',
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('TeamFreeForAll', () => {
})

test('calculates elo for team 2 winning', () => {
const results = match.calculate(['2', '1', '3'])
const results = match.calculate('2', '1', '3')
expect(results).toStrictEqual([
{
id: '1',
Expand Down Expand Up @@ -130,7 +130,7 @@ describe('TeamFreeForAll', () => {
})

test('calculates elo for team 3 winning', () => {
const results = match.calculate(['3', '2', '1'])
const results = match.calculate('3', '2', '1')
expect(results).toStrictEqual([
{
id: '1',
Expand Down Expand Up @@ -184,7 +184,7 @@ describe('TeamFreeForAll', () => {
team2.addPlayer(new Player('2', 900))

match.addTeams(team1, team2)
match.calculate(['1', '2'])
match.calculate('1', '2')
}).toThrow(ErrorType.MIN_TEAMS)
})

Expand All @@ -198,7 +198,7 @@ describe('TeamFreeForAll', () => {
team2.addPlayer(new Player('2', 900))

match.addTeams(team1, team2)
match.calculate(['1'])
match.calculate('1')
}).toThrow(ErrorType.SIZE_MISMATCH)
})
})
2 changes: 1 addition & 1 deletion src/main/matches/team-free-for-all/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class TeamFreeForAll extends Match {
return this
}

calculate(teamIds: string[]): TeamResult[] {
calculate(...teamIds: string[]): TeamResult[] {
if (this.completed) {
throw new MatchError(ErrorType.MATCH_COMPLETE)
}
Expand Down

0 comments on commit 0e5b982

Please sign in to comment.