diff --git a/src/lib/match/index.test.ts b/src/lib/match/index.test.ts index 40a577e..bc617ea 100644 --- a/src/lib/match/index.test.ts +++ b/src/lib/match/index.test.ts @@ -23,7 +23,7 @@ describe('Match', () => { match.addContestant(player1) match.addContestant(player2) - expect(match.contestants.size).toBe(2) + expect(match.size).toBe(2) }) test('gets results of match', () => { diff --git a/src/lib/match/index.ts b/src/lib/match/index.ts index 2c62dc5..2ba586b 100644 --- a/src/lib/match/index.ts +++ b/src/lib/match/index.ts @@ -30,6 +30,10 @@ export abstract class Match { return this._contestants } + get size(): number { + return this._contestants.size + } + get completed(): boolean { return this._completed } diff --git a/src/main/matches/duel/index.test.ts b/src/main/matches/duel/index.test.ts index add7292..b8a2605 100644 --- a/src/main/matches/duel/index.test.ts +++ b/src/main/matches/duel/index.test.ts @@ -12,7 +12,7 @@ describe('Duel', () => { const match = Duel.create([Player.create('1', 1000), Player.create('2', 900)]) expect(match).toBeDefined() expect(match).toBeInstanceOf(Duel) - expect(match.contestants.size).toBe(2) + expect(match.size).toBe(2) }) test('throws error when adding more than 2 players', () => { diff --git a/src/main/matches/duel/index.ts b/src/main/matches/duel/index.ts index f52eb01..32e9e0d 100644 --- a/src/main/matches/duel/index.ts +++ b/src/main/matches/duel/index.ts @@ -24,7 +24,7 @@ export class Duel extends Match { } addPlayer(player: Player): this { - if (this.contestants.size === DUEL_SIZE) { + if (this.size === DUEL_SIZE) { throw new MatchError(ErrorType.MAX_PLAYERS) } @@ -43,7 +43,7 @@ export class Duel extends Match { throw new MatchError(ErrorType.MATCH_COMPLETE) } - if (this.contestants.size !== DUEL_SIZE) { + if (this.size !== DUEL_SIZE) { throw new MatchError(ErrorType.MIN_PLAYERS) } diff --git a/src/main/matches/free-for-all/index.test.ts b/src/main/matches/free-for-all/index.test.ts index 374d14d..7631fd5 100644 --- a/src/main/matches/free-for-all/index.test.ts +++ b/src/main/matches/free-for-all/index.test.ts @@ -12,7 +12,7 @@ describe('FreeForAll', () => { const match = FreeForAll.create([Player.create('1', 1000), Player.create('2', 900)]) expect(match).toBeDefined() expect(match).toBeInstanceOf(FreeForAll) - expect(match.contestants.size).toBe(2) + expect(match.size).toBe(2) }) test('calculates elo for player 1 win with 2 players', () => { diff --git a/src/main/matches/free-for-all/index.ts b/src/main/matches/free-for-all/index.ts index 73aa1fa..9d3fdcd 100644 --- a/src/main/matches/free-for-all/index.ts +++ b/src/main/matches/free-for-all/index.ts @@ -27,7 +27,7 @@ export class FreeForAll extends Match { } addPlayer(player: Player): this { - if (this.contestants.size === this.maxContestants) { + if (this.size === this.maxContestants) { throw new MatchError(ErrorType.MAX_PLAYERS) } @@ -46,11 +46,11 @@ export class FreeForAll extends Match { throw new MatchError(ErrorType.MATCH_COMPLETE) } - if (this.contestants.size < this.minContestants) { + if (this.size < this.minContestants) { throw new MatchError(ErrorType.MIN_PLAYERS) } - if (this.contestants.size !== playerIds.length) { + if (this.size !== playerIds.length) { throw new MatchError(ErrorType.SIZE_MISMATCH) } diff --git a/src/main/matches/team-duel/index.test.ts b/src/main/matches/team-duel/index.test.ts index b62af0d..232050f 100644 --- a/src/main/matches/team-duel/index.test.ts +++ b/src/main/matches/team-duel/index.test.ts @@ -24,11 +24,11 @@ describe('TeamDuel', () => { ]) expect(match).toBeDefined() expect(match).toBeInstanceOf(TeamDuel) - expect(match.contestants.size).toBe(2) + expect(match.size).toBe(2) }) test('adds teams to match', () => { - expect(match.contestants.size).toBe(2) + expect(match.size).toBe(2) }) test('throws error when adding more than 2 teams to match', () => { diff --git a/src/main/matches/team-duel/index.ts b/src/main/matches/team-duel/index.ts index 8edb81f..724adc5 100644 --- a/src/main/matches/team-duel/index.ts +++ b/src/main/matches/team-duel/index.ts @@ -24,7 +24,7 @@ export class TeamDuel extends Match { } addTeam(team: Team): this { - if (this.contestants.size === DUEL_SIZE) { + if (this.size === DUEL_SIZE) { throw new MatchError(ErrorType.MAX_TEAMS) } @@ -43,7 +43,7 @@ export class TeamDuel extends Match { throw new MatchError(ErrorType.MATCH_COMPLETE) } - if (this.contestants.size !== DUEL_SIZE) { + if (this.size !== DUEL_SIZE) { throw new MatchError(ErrorType.MIN_TEAMS) } diff --git a/src/main/matches/team-free-for-all/index.test.ts b/src/main/matches/team-free-for-all/index.test.ts index 00a5ec3..bce509e 100644 --- a/src/main/matches/team-free-for-all/index.test.ts +++ b/src/main/matches/team-free-for-all/index.test.ts @@ -26,11 +26,11 @@ describe('TeamFreeForAll', () => { ]) expect(match).toBeDefined() expect(match).toBeInstanceOf(TeamFreeForAll) - expect(match.contestants.size).toBe(3) + expect(match.size).toBe(3) }) test('adds teams to match', () => { - expect(match.contestants.size).toBe(3) + expect(match.size).toBe(3) }) test('calculates elo for team 1 winning', () => { diff --git a/src/main/matches/team-free-for-all/index.ts b/src/main/matches/team-free-for-all/index.ts index 192560f..613f5a0 100644 --- a/src/main/matches/team-free-for-all/index.ts +++ b/src/main/matches/team-free-for-all/index.ts @@ -27,7 +27,7 @@ export class TeamFreeForAll extends Match { } addTeam(team: Team): this { - if (this.contestants.size === this.maxContestants) { + if (this.size === this.maxContestants) { throw new MatchError(ErrorType.MAX_TEAMS) } @@ -46,11 +46,11 @@ export class TeamFreeForAll extends Match { throw new MatchError(ErrorType.MATCH_COMPLETE) } - if (this.contestants.size < this.minContestants) { + if (this.size < this.minContestants) { throw new MatchError(ErrorType.MIN_TEAMS) } - if (this.contestants.size !== teamIds.length) { + if (this.size !== teamIds.length) { throw new MatchError(ErrorType.SIZE_MISMATCH) }