diff --git a/packages/kcms/src/match/model/main.test.ts b/packages/kcms/src/match/model/main.test.ts index 51604944..a7f5da18 100644 --- a/packages/kcms/src/match/model/main.test.ts +++ b/packages/kcms/src/match/model/main.test.ts @@ -40,7 +40,7 @@ describe('MainMatch', () => { runResults: [], }); // 2か4以外は足せない - if (j == 2 || j == 4) { + if (j == 1 || j == 2 || j == 4) { expect(() => { mainMatch.appendRunResults( [...Array(j)].map((_, i) => { @@ -74,6 +74,52 @@ describe('MainMatch', () => { } }); + it('走行結果を追加できる', () => { + for (let i = 1; i <= 2; i++) { + const mainMatch = MainMatch.new({ + id: '1' as MainMatchID, + courseIndex: 1, + matchIndex: 1, + departmentType: config.departmentTypes[0], + teamId1: '2' as TeamID, + teamId2: '3' as TeamID, + winnerId: '2' as TeamID, + runResults: [], + }); + for (let j = 1; j < 8; j++) { + if (j === 1 || j == 2) { + expect(() => { + mainMatch.appendRunResults( + [...Array(i)].map((_, i) => { + return RunResult.new({ + id: String(i) as RunResultID, + goalTimeSeconds: i * 10, + points: 10 + i, + teamID: i % 2 == 0 ? ('2' as TeamID) : ('3' as TeamID), + finishState: 'FINISHED', + }); + }) + ); + }).not.toThrow(new Error('RunResult length must be 2 or 4')); + } else { + expect(() => { + mainMatch.appendRunResults( + [...Array(i)].map((_, i) => { + return RunResult.new({ + id: String(i) as RunResultID, + goalTimeSeconds: i * 10, + points: 10 + i, + teamID: i % 2 == 0 ? ('2' as TeamID) : ('3' as TeamID), + finishState: 'FINISHED', + }); + }) + ); + }).toThrow(new Error('RunResult length must be 2 or 4')); + } + } + } + }); + it('勝者を指定できる', () => { const args: CreateMainMatchArgs = { id: '1' as MainMatchID, diff --git a/packages/kcms/src/match/model/main.ts b/packages/kcms/src/match/model/main.ts index 84a45a98..b7f2814d 100644 --- a/packages/kcms/src/match/model/main.ts +++ b/packages/kcms/src/match/model/main.ts @@ -91,7 +91,7 @@ export class MainMatch { appendRunResults(results: RunResult[]) { // 1チームが2つずつ結果を持つので、2 または 4個 const appendedLength = this.runResults.length + results.length; - if (appendedLength !== 4 && appendedLength !== 2) { + if (appendedLength !== 4 && appendedLength !== 2 && appendedLength !== 1) { throw new Error('RunResult length must be 2 or 4'); } this.runResults.push(...results);