Skip to content

Commit

Permalink
fix:テスト内容を変更
Browse files Browse the repository at this point in the history
  • Loading branch information
speak-mentaiko committed Oct 24, 2024
1 parent 69d3bea commit 29191fa
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
48 changes: 47 additions & 1 deletion packages/kcms/src/match/model/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/kcms/src/match/model/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 29191fa

Please sign in to comment.