Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/lib/match/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class TestMatch extends Match {
this.completed = true
return []
}

addPlayer(player: Player) {
this.addContestant(player)
}
}

describe('Match', () => {
Expand All @@ -20,8 +24,8 @@ describe('Match', () => {
const player2 = new Player('2', 900)
const match = new TestMatch()

match.addContestant(player1)
match.addContestant(player2)
match.addPlayer(player1)
match.addPlayer(player2)

expect(match.size).toBe(2)
})
Expand All @@ -31,8 +35,8 @@ describe('Match', () => {
const player2 = new Player('2', 900)
const match = new TestMatch()

match.addContestant(player1)
match.addContestant(player2)
match.addPlayer(player1)
match.addPlayer(player2)
match.calculate('1')

const results = match.getResults()
Expand All @@ -55,8 +59,8 @@ describe('Match', () => {
const player2 = new Player('2', 900)
const match = new TestMatch()

match.addContestant(player1)
match.addContestant(player2)
match.addPlayer(player1)
match.addPlayer(player2)
match.getResults()
}).toThrow(ErrorType.MATCH_INCOMPLETE)
})
Expand Down
16 changes: 8 additions & 8 deletions src/lib/match/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,20 @@ export abstract class Match {
return elos
}

getResults(): Results {
if (!this._completed) {
throw new MatchError(ErrorType.MATCH_INCOMPLETE)
protected addContestant(contestant: Contestant) {
if (this._completed) {
throw new MatchError(ErrorType.MATCH_COMPLETE)
}

return this.contestantMapToResults()
this._contestants.set(contestant.id, contestant)
}

addContestant(contestant: Contestant) {
if (this._completed) {
throw new MatchError(ErrorType.MATCH_COMPLETE)
getResults(): Results {
if (!this._completed) {
throw new MatchError(ErrorType.MATCH_INCOMPLETE)
}

this._contestants.set(contestant.id, contestant)
return this.contestantMapToResults()
}

abstract calculate(contestantIds: string | string[]): Results
Expand Down
Loading