volleyballsimtypes 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -5
- package/src/data/index.ts +0 -2
- package/src/data/models/block.ts +0 -159
- package/src/data/models/coach.ts +0 -94
- package/src/data/models/country.ts +0 -105
- package/src/data/models/event.ts +0 -83
- package/src/data/models/index.ts +0 -22
- package/src/data/models/league.ts +0 -90
- package/src/data/models/libero-replacement.ts +0 -104
- package/src/data/models/match-set-stats.ts +0 -204
- package/src/data/models/match-set.ts +0 -152
- package/src/data/models/match.ts +0 -106
- package/src/data/models/performance-stats.ts +0 -136
- package/src/data/models/player.ts +0 -370
- package/src/data/models/rally-position.ts +0 -79
- package/src/data/models/rally.ts +0 -229
- package/src/data/models/reception.ts +0 -113
- package/src/data/models/score.ts +0 -99
- package/src/data/models/season-teams.ts +0 -67
- package/src/data/models/season.ts +0 -103
- package/src/data/models/serve.ts +0 -113
- package/src/data/models/set.ts +0 -113
- package/src/data/models/spike.ts +0 -113
- package/src/data/models/substitution.ts +0 -98
- package/src/data/models/team.ts +0 -193
- package/src/data/transformers/block.ts +0 -117
- package/src/data/transformers/coach.ts +0 -33
- package/src/data/transformers/country.ts +0 -23
- package/src/data/transformers/court-position.ts +0 -43
- package/src/data/transformers/court-target.ts +0 -58
- package/src/data/transformers/event-type.ts +0 -35
- package/src/data/transformers/formation.ts +0 -16
- package/src/data/transformers/index.ts +0 -27
- package/src/data/transformers/league.ts +0 -26
- package/src/data/transformers/libero-replacement.ts +0 -62
- package/src/data/transformers/match-set-stats.ts +0 -101
- package/src/data/transformers/match-set.ts +0 -59
- package/src/data/transformers/match.ts +0 -48
- package/src/data/transformers/performance-stats.ts +0 -40
- package/src/data/transformers/player.ts +0 -109
- package/src/data/transformers/rally-position.ts +0 -24
- package/src/data/transformers/rally.ts +0 -139
- package/src/data/transformers/reception.ts +0 -98
- package/src/data/transformers/role.ts +0 -31
- package/src/data/transformers/score.ts +0 -43
- package/src/data/transformers/season.ts +0 -42
- package/src/data/transformers/serve.ts +0 -100
- package/src/data/transformers/set.ts +0 -98
- package/src/data/transformers/spike.ts +0 -102
- package/src/data/transformers/substitution.ts +0 -42
- package/src/data/transformers/team.ts +0 -45
- package/src/data/transformers/trait.ts +0 -37
- package/src/index.ts +0 -7
- package/src/routing/events.ts +0 -60
- package/src/routing/index.ts +0 -5
- package/src/routing/league.ts +0 -15
- package/src/routing/match.ts +0 -52
- package/src/routing/player.ts +0 -24
- package/src/routing/team.ts +0 -14
- package/src/service/coach/__stubs__/index.ts +0 -46
- package/src/service/coach/coach.test.ts +0 -10
- package/src/service/coach/coach.ts +0 -30
- package/src/service/coach/formation.test.ts +0 -10
- package/src/service/coach/formation.ts +0 -160
- package/src/service/coach/index.ts +0 -2
- package/src/service/country/__stubs__/index.ts +0 -13
- package/src/service/country/country.test.ts +0 -10
- package/src/service/country/country.ts +0 -23
- package/src/service/country/index.ts +0 -1
- package/src/service/event/__stubs__/index.ts +0 -25
- package/src/service/event/block.test.ts +0 -100
- package/src/service/event/block.ts +0 -69
- package/src/service/event/in-play-event.ts +0 -37
- package/src/service/event/libero-replacement.test.ts +0 -37
- package/src/service/event/libero-replacement.ts +0 -25
- package/src/service/event/rally-event.ts +0 -33
- package/src/service/event/reception.test.ts +0 -50
- package/src/service/event/reception.ts +0 -38
- package/src/service/event/score.test.ts +0 -29
- package/src/service/event/score.ts +0 -22
- package/src/service/event/serve.test.ts +0 -50
- package/src/service/event/serve.ts +0 -39
- package/src/service/event/set.test.ts +0 -50
- package/src/service/event/set.ts +0 -38
- package/src/service/event/spike.test.ts +0 -64
- package/src/service/event/spike.ts +0 -46
- package/src/service/event/substitution.ts +0 -16
- package/src/service/index.ts +0 -17
- package/src/service/league/index.ts +0 -3
- package/src/service/league/league.ts +0 -112
- package/src/service/league/season.ts +0 -41
- package/src/service/league/standing.ts +0 -82
- package/src/service/main.ts +0 -52
- package/src/service/match/__stubs__/index.ts +0 -119
- package/src/service/match/court-position.test.ts +0 -73
- package/src/service/match/court-position.ts +0 -46
- package/src/service/match/court-target.test.ts +0 -39
- package/src/service/match/court-target.ts +0 -30
- package/src/service/match/index.ts +0 -6
- package/src/service/match/match-set.test.ts +0 -174
- package/src/service/match/match-set.ts +0 -140
- package/src/service/match/match-team.test.ts +0 -16
- package/src/service/match/match-team.ts +0 -13
- package/src/service/match/match.test.ts +0 -80
- package/src/service/match/match.ts +0 -63
- package/src/service/match/rally.test.ts +0 -94
- package/src/service/match/rally.ts +0 -79
- package/src/service/player/__stubs__/index.ts +0 -1433
- package/src/service/player/index.ts +0 -5
- package/src/service/player/performance-stats.test.ts +0 -24
- package/src/service/player/performance-stats.ts +0 -47
- package/src/service/player/player.test.ts +0 -51
- package/src/service/player/player.ts +0 -101
- package/src/service/player/role.test.ts +0 -29
- package/src/service/player/role.ts +0 -33
- package/src/service/player/stats.test.ts +0 -23
- package/src/service/player/stats.ts +0 -29
- package/src/service/player/trait.test.ts +0 -10
- package/src/service/player/trait.ts +0 -124
- package/src/service/team/__stubs__/index.ts +0 -290
- package/src/service/team/index.ts +0 -1
- package/src/service/team/team.test.ts +0 -30
- package/src/service/team/team.ts +0 -45
- package/src/service/utils/enum-utils.test.ts +0 -10
- package/src/service/utils/enum-utils.ts +0 -6
- package/src/service/utils/index.ts +0 -4
- package/src/service/utils/object-utils.ts +0 -1
- package/src/service/utils/rng-utils.test.ts +0 -32
- package/src/service/utils/rng-utils.ts +0 -41
- package/src/service/utils/string-utils.test.ts +0 -28
- package/src/service/utils/string-utils.ts +0 -13
- package/src/service/utils/testing-utils.ts +0 -2
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { Rally } from '../rally'
|
|
2
|
-
import { MatchSet } from '../match-set'
|
|
3
|
-
import { MatchTeam } from '../match-team'
|
|
4
|
-
import { team } from '../../team/__stubs__'
|
|
5
|
-
import { libero, rosters } from '../../player/__stubs__'
|
|
6
|
-
import { Match } from '../match'
|
|
7
|
-
import { Team } from '../../team'
|
|
8
|
-
import { coaches } from '../../coach/__stubs__'
|
|
9
|
-
import { country } from '../../country/__stubs__'
|
|
10
|
-
|
|
11
|
-
export const newRally: Rally = new Rally({
|
|
12
|
-
servingTeam: team,
|
|
13
|
-
events: [],
|
|
14
|
-
order: 1,
|
|
15
|
-
id: '0ac3ba3a-d710-42dc-a1e7-7066b8df5fd9',
|
|
16
|
-
homePlayerPosition: [],
|
|
17
|
-
awayPlayerPosition: []
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
export const newSet: MatchSet = new MatchSet({
|
|
21
|
-
id: 'bf337ec2-9fee-495e-8d5a-d834b307d537',
|
|
22
|
-
stats: [],
|
|
23
|
-
rallies: [],
|
|
24
|
-
order: 0,
|
|
25
|
-
homeScore: 0,
|
|
26
|
-
awayScore: 0,
|
|
27
|
-
isTieBreak: false,
|
|
28
|
-
homeLibero: libero,
|
|
29
|
-
awayLibero: libero
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
export const finishedSet: MatchSet = (() => {
|
|
33
|
-
const set = new MatchSet({
|
|
34
|
-
id: 'c959fcf6-873f-4eae-80aa-a820e25329c4',
|
|
35
|
-
stats: [],
|
|
36
|
-
rallies: [],
|
|
37
|
-
order: 0,
|
|
38
|
-
homeScore: 0,
|
|
39
|
-
awayScore: 0,
|
|
40
|
-
isTieBreak: false,
|
|
41
|
-
homeLibero: libero,
|
|
42
|
-
awayLibero: libero
|
|
43
|
-
})
|
|
44
|
-
set.nextState()
|
|
45
|
-
for (let i = 0; i < 25; i++) {
|
|
46
|
-
set.increaseScore(MatchTeam.HOME)
|
|
47
|
-
}
|
|
48
|
-
set.nextState()
|
|
49
|
-
return set
|
|
50
|
-
})()
|
|
51
|
-
export const inProgressSet: MatchSet = (() => {
|
|
52
|
-
const set = new MatchSet({
|
|
53
|
-
id: 'c1095b6c-9e70-4f9d-9942-d54aaa8655d0',
|
|
54
|
-
stats: [],
|
|
55
|
-
rallies: [],
|
|
56
|
-
order: 0,
|
|
57
|
-
homeScore: 0,
|
|
58
|
-
awayScore: 0,
|
|
59
|
-
isTieBreak: false,
|
|
60
|
-
homeLibero: libero,
|
|
61
|
-
awayLibero: libero
|
|
62
|
-
})
|
|
63
|
-
set.nextState()
|
|
64
|
-
for (let i = 0; i < 20; i++) {
|
|
65
|
-
set.increaseScore(MatchTeam.AWAY)
|
|
66
|
-
}
|
|
67
|
-
return set
|
|
68
|
-
})()
|
|
69
|
-
|
|
70
|
-
export const teams: Team[] = [
|
|
71
|
-
new Team({
|
|
72
|
-
id: '334ca929-6e71-4011-a2f0-5ca4fa83dbe5',
|
|
73
|
-
name: 'Jaloo',
|
|
74
|
-
shortName: 'JAL',
|
|
75
|
-
country,
|
|
76
|
-
roster: rosters[0],
|
|
77
|
-
coach: coaches[0]
|
|
78
|
-
}),
|
|
79
|
-
new Team({
|
|
80
|
-
id: 'f244d62d-f0ec-4005-8eb2-d955b0b8b191',
|
|
81
|
-
name: 'Fatz',
|
|
82
|
-
shortName: 'FAT',
|
|
83
|
-
country,
|
|
84
|
-
roster: rosters[1],
|
|
85
|
-
coach: coaches[1]
|
|
86
|
-
}),
|
|
87
|
-
new Team({
|
|
88
|
-
id: '749a5755-5c8b-4b07-aca9-1365a26c9a2e',
|
|
89
|
-
name: 'Tagtune',
|
|
90
|
-
shortName: 'TAG',
|
|
91
|
-
country,
|
|
92
|
-
roster: rosters[2],
|
|
93
|
-
coach: coaches[2]
|
|
94
|
-
}),
|
|
95
|
-
new Team({
|
|
96
|
-
id: 'd3dd532d-4898-44a3-853f-25f6fbdb3534',
|
|
97
|
-
name: 'Gigabox',
|
|
98
|
-
shortName: 'GIG',
|
|
99
|
-
country,
|
|
100
|
-
roster: rosters[3],
|
|
101
|
-
coach: coaches[3]
|
|
102
|
-
})
|
|
103
|
-
]
|
|
104
|
-
|
|
105
|
-
export const match: Match = new Match({
|
|
106
|
-
id: '59aa2ea0-cf71-4081-b817-48dfdd454841',
|
|
107
|
-
homeTeam: teams[0],
|
|
108
|
-
awayTeam: teams[1],
|
|
109
|
-
sets: [],
|
|
110
|
-
scheduledDate: new Date('2023-07-26T21:48:12.273Z')
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
export const match2: Match = new Match({
|
|
114
|
-
id: 'dfd87bdc-20c2-4383-92ea-b5c36a8ba7aa',
|
|
115
|
-
homeTeam: teams[2],
|
|
116
|
-
awayTeam: teams[3],
|
|
117
|
-
sets: [],
|
|
118
|
-
scheduledDate: new Date('2023-07-26T21:48:12.273Z')
|
|
119
|
-
})
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from '@jest/globals'
|
|
2
|
-
import { CourtPosition, CourtRow } from './court-position'
|
|
3
|
-
|
|
4
|
-
describe('CourtPosition Test Module', () => {
|
|
5
|
-
const positions: CourtPosition[] = [CourtPosition.LEFT_BACK, CourtPosition.MIDDLE_BACK, CourtPosition.RIGHT_BACK,
|
|
6
|
-
CourtPosition.LEFT_FRONT, CourtPosition.MIDDLE_FRONT, CourtPosition.RIGHT_FRONT]
|
|
7
|
-
|
|
8
|
-
// getPositions Tests
|
|
9
|
-
test('Should get all positions', () => {
|
|
10
|
-
expect(CourtPosition.getPositions()).toEqual(positions)
|
|
11
|
-
})
|
|
12
|
-
// rotatePosition Tests
|
|
13
|
-
test('Should return correct positions for rotation', () => {
|
|
14
|
-
expect(CourtPosition.rotatePosition(1)).toEqual(CourtPosition.MIDDLE_BACK)
|
|
15
|
-
expect(CourtPosition.rotatePosition(2)).toEqual(CourtPosition.RIGHT_BACK)
|
|
16
|
-
expect(CourtPosition.rotatePosition(3)).toEqual(CourtPosition.RIGHT_FRONT)
|
|
17
|
-
expect(CourtPosition.rotatePosition(4)).toEqual(CourtPosition.MIDDLE_FRONT)
|
|
18
|
-
expect(CourtPosition.rotatePosition(5)).toEqual(CourtPosition.LEFT_FRONT)
|
|
19
|
-
expect(CourtPosition.rotatePosition(6)).toEqual(CourtPosition.LEFT_BACK)
|
|
20
|
-
})
|
|
21
|
-
test('Should throw Error when rotating an invalid position', () => {
|
|
22
|
-
function rotate (): void { CourtPosition.rotatePosition(0) }
|
|
23
|
-
|
|
24
|
-
expect(rotate).toThrow(/^POSITION_INDEX_OUT_OF_BOUNDS$/)
|
|
25
|
-
})
|
|
26
|
-
// isFrontRow Tests
|
|
27
|
-
test('Should return true for front-row positions', () => {
|
|
28
|
-
expect(CourtPosition.isFrontRow(CourtPosition.LEFT_FRONT)).toEqual(true)
|
|
29
|
-
expect(CourtPosition.isFrontRow(CourtPosition.MIDDLE_FRONT)).toEqual(true)
|
|
30
|
-
expect(CourtPosition.isFrontRow(CourtPosition.RIGHT_FRONT)).toEqual(true)
|
|
31
|
-
})
|
|
32
|
-
test('Should return false for back-row positions', () => {
|
|
33
|
-
expect(CourtPosition.isFrontRow(CourtPosition.LEFT_BACK)).toEqual(false)
|
|
34
|
-
expect(CourtPosition.isFrontRow(CourtPosition.MIDDLE_BACK)).toEqual(false)
|
|
35
|
-
expect(CourtPosition.isFrontRow(CourtPosition.RIGHT_BACK)).toEqual(false)
|
|
36
|
-
})
|
|
37
|
-
test('Should throw Error providing an invalid position', () => {
|
|
38
|
-
function front (): void { CourtPosition.isFrontRow(0) }
|
|
39
|
-
|
|
40
|
-
expect(front).toThrow(/^POSITION_INDEX_OUT_OF_BOUNDS$/)
|
|
41
|
-
})
|
|
42
|
-
// isBackRow Tests
|
|
43
|
-
test('Should return true for back-row positions', () => {
|
|
44
|
-
expect(CourtPosition.isBackRow(CourtPosition.LEFT_BACK)).toEqual(true)
|
|
45
|
-
expect(CourtPosition.isBackRow(CourtPosition.MIDDLE_BACK)).toEqual(true)
|
|
46
|
-
expect(CourtPosition.isBackRow(CourtPosition.RIGHT_BACK)).toEqual(true)
|
|
47
|
-
})
|
|
48
|
-
test('Should return false for front-row positions', () => {
|
|
49
|
-
expect(CourtPosition.isBackRow(CourtPosition.LEFT_FRONT)).toEqual(false)
|
|
50
|
-
expect(CourtPosition.isBackRow(CourtPosition.MIDDLE_FRONT)).toEqual(false)
|
|
51
|
-
expect(CourtPosition.isBackRow(CourtPosition.RIGHT_FRONT)).toEqual(false)
|
|
52
|
-
})
|
|
53
|
-
test('Should throw Error providing an invalid position', () => {
|
|
54
|
-
function back (): void { CourtPosition.isBackRow(0) }
|
|
55
|
-
|
|
56
|
-
expect(back).toThrow(/^POSITION_INDEX_OUT_OF_BOUNDS: 0$/)
|
|
57
|
-
})
|
|
58
|
-
// getRow Tests
|
|
59
|
-
test('Should get all front-row positions', () => {
|
|
60
|
-
expect(CourtPosition.getRow(CourtRow.FRONT))
|
|
61
|
-
.toEqual([CourtPosition.LEFT_FRONT, CourtPosition.MIDDLE_FRONT, CourtPosition.RIGHT_FRONT])
|
|
62
|
-
})
|
|
63
|
-
test('Should get all back-row positions', () => {
|
|
64
|
-
expect(CourtPosition.getRow(CourtRow.BACK))
|
|
65
|
-
.toEqual([CourtPosition.LEFT_BACK, CourtPosition.MIDDLE_BACK, CourtPosition.RIGHT_BACK])
|
|
66
|
-
})
|
|
67
|
-
test('Should throw Error providing an invalid row', () => {
|
|
68
|
-
// @ts-expect-error
|
|
69
|
-
function row (): void { CourtPosition.getRow(CourtRow.FAKE) }
|
|
70
|
-
|
|
71
|
-
expect(row).toThrow(/^INVALID_ROW: undefined$/)
|
|
72
|
-
})
|
|
73
|
-
})
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
export enum CourtRow {
|
|
2
|
-
BACK = 'BACK_ROW',
|
|
3
|
-
FRONT = 'FRONT_ROW'
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export enum CourtPosition {
|
|
7
|
-
NOT_IN_COURT = -1, LIBERO_ZONE = 0,
|
|
8
|
-
// -----------------------------------------------------
|
|
9
|
-
LEFT_FRONT = 4, MIDDLE_FRONT = 3, RIGHT_FRONT = 2,
|
|
10
|
-
LEFT_BACK = 5, MIDDLE_BACK = 6, RIGHT_BACK = 1
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
14
|
-
export namespace CourtPosition {
|
|
15
|
-
const FRONT_ROW = [CourtPosition.LEFT_FRONT, CourtPosition.MIDDLE_FRONT, CourtPosition.RIGHT_FRONT]
|
|
16
|
-
const BACK_ROW = [CourtPosition.LEFT_BACK, CourtPosition.MIDDLE_BACK, CourtPosition.RIGHT_BACK]
|
|
17
|
-
|
|
18
|
-
export function getPositions (): CourtPosition[] {
|
|
19
|
-
return [...BACK_ROW, ...FRONT_ROW]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function rotatePosition (position: number): CourtPosition {
|
|
23
|
-
if (position < 1 || position > 6) throw new Error('POSITION_INDEX_OUT_OF_BOUNDS')
|
|
24
|
-
|
|
25
|
-
if (position > CourtPosition.RIGHT_BACK) return position - 1
|
|
26
|
-
else return CourtPosition.MIDDLE_BACK
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function isFrontRow (position: number): boolean {
|
|
30
|
-
if (position < 1 || position > 6) throw new Error('POSITION_INDEX_OUT_OF_BOUNDS')
|
|
31
|
-
|
|
32
|
-
return FRONT_ROW.includes(position)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function isBackRow (position: number): boolean {
|
|
36
|
-
if (position < 1 || position > 6) throw new Error(`POSITION_INDEX_OUT_OF_BOUNDS: ${position}`)
|
|
37
|
-
|
|
38
|
-
return BACK_ROW.includes(position)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function getRow (row: CourtRow): CourtPosition[] {
|
|
42
|
-
if (![CourtRow.BACK, CourtRow.FRONT].includes(row)) throw new Error(`INVALID_ROW: ${row}`)
|
|
43
|
-
|
|
44
|
-
return CourtRow.BACK === row ? [...BACK_ROW] : [...FRONT_ROW]
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from '@jest/globals'
|
|
2
|
-
import { CourtTarget } from './court-target'
|
|
3
|
-
|
|
4
|
-
describe('CourtTarget Test Module', () => {
|
|
5
|
-
// getSidePosition Tests
|
|
6
|
-
test('Should get correct court position', () => {
|
|
7
|
-
for (let i = 1; i < 7; i++) {
|
|
8
|
-
expect(CourtTarget.getSidePosition(i)).toBe(i)
|
|
9
|
-
expect(CourtTarget.getSidePosition(i + 6)).toBe(i)
|
|
10
|
-
}
|
|
11
|
-
})
|
|
12
|
-
test('Should throw Error when position is out of bounds', () => {
|
|
13
|
-
function position (): void { CourtTarget.getSidePosition(0) }
|
|
14
|
-
|
|
15
|
-
expect(position).toThrow(/^POSITION_INDEX_OUT_OF_BOUNDS$/)
|
|
16
|
-
})
|
|
17
|
-
// getTeamSide Tests
|
|
18
|
-
test('Should return team positions', () => {
|
|
19
|
-
const positions: CourtTarget[] = CourtTarget.getTeamSide()
|
|
20
|
-
|
|
21
|
-
expect(positions[0]).toBe(CourtTarget.TEAM_RIGHT_BACK)
|
|
22
|
-
expect(positions[1]).toBe(CourtTarget.TEAM_RIGHT_FRONT)
|
|
23
|
-
expect(positions[2]).toBe(CourtTarget.TEAM_MIDDLE_FRONT)
|
|
24
|
-
expect(positions[3]).toBe(CourtTarget.TEAM_LEFT_FRONT)
|
|
25
|
-
expect(positions[4]).toBe(CourtTarget.TEAM_LEFT_BACK)
|
|
26
|
-
expect(positions[5]).toBe(CourtTarget.TEAM_MIDDLE_BACK)
|
|
27
|
-
})
|
|
28
|
-
// getOpponentSide Tests
|
|
29
|
-
test('Should return opponent team positions', () => {
|
|
30
|
-
const positions: CourtTarget[] = CourtTarget.getOpponentSide()
|
|
31
|
-
|
|
32
|
-
expect(positions[0]).toBe(CourtTarget.OPPONENT_RIGHT_BACK)
|
|
33
|
-
expect(positions[1]).toBe(CourtTarget.OPPONENT_RIGHT_FRONT)
|
|
34
|
-
expect(positions[2]).toBe(CourtTarget.OPPONENT_MIDDLE_FRONT)
|
|
35
|
-
expect(positions[3]).toBe(CourtTarget.OPPONENT_LEFT_FRONT)
|
|
36
|
-
expect(positions[4]).toBe(CourtTarget.OPPONENT_LEFT_BACK)
|
|
37
|
-
expect(positions[5]).toBe(CourtTarget.OPPONENT_MIDDLE_BACK)
|
|
38
|
-
})
|
|
39
|
-
})
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { CourtPosition } from './court-position'
|
|
2
|
-
|
|
3
|
-
export enum CourtTarget {
|
|
4
|
-
NO_TARGET = 0,
|
|
5
|
-
OPPONENT_RIGHT_BACK = 7, OPPONENT_MIDDLE_BACK = 12, OPPONENT_LEFT_BACK = 11,
|
|
6
|
-
OPPONENT_RIGHT_FRONT = 8, OPPONENT_MIDDLE_FRONT = 9, OPPONENT_LEFT_FRONT = 10,
|
|
7
|
-
// --------------------------------------------------------------------------------
|
|
8
|
-
TEAM_LEFT_FRONT = 4, TEAM_MIDDLE_FRONT = 3, TEAM_RIGHT_FRONT = 2,
|
|
9
|
-
TEAM_LEFT_BACK = 5, TEAM_MIDDLE_BACK = 6, TEAM_RIGHT_BACK = 1,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
13
|
-
export namespace CourtTarget {
|
|
14
|
-
export function getTeamSide (): CourtTarget[] {
|
|
15
|
-
return [CourtTarget.TEAM_RIGHT_BACK, CourtTarget.TEAM_RIGHT_FRONT, CourtTarget.TEAM_MIDDLE_FRONT,
|
|
16
|
-
CourtTarget.TEAM_LEFT_FRONT, CourtTarget.TEAM_LEFT_BACK, CourtTarget.TEAM_MIDDLE_BACK]
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function getOpponentSide (): CourtTarget[] {
|
|
20
|
-
return [CourtTarget.OPPONENT_RIGHT_BACK, CourtTarget.OPPONENT_RIGHT_FRONT, CourtTarget.OPPONENT_MIDDLE_FRONT,
|
|
21
|
-
CourtTarget.OPPONENT_LEFT_FRONT, CourtTarget.OPPONENT_LEFT_BACK, CourtTarget.OPPONENT_MIDDLE_BACK]
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function getSidePosition (position: number): CourtPosition {
|
|
25
|
-
if (position < 1 || position > 12) throw new Error('POSITION_INDEX_OUT_OF_BOUNDS')
|
|
26
|
-
|
|
27
|
-
if (position > 6) return position - 6
|
|
28
|
-
else return position
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from '@jest/globals'
|
|
2
|
-
import { MatchSet, MatchSetState } from './match-set'
|
|
3
|
-
import { MatchTeam } from './match-team'
|
|
4
|
-
import { newRally } from './__stubs__'
|
|
5
|
-
import { libero } from '../player/__stubs__'
|
|
6
|
-
|
|
7
|
-
describe('MatchSet Test Module', () => {
|
|
8
|
-
let set: MatchSet
|
|
9
|
-
let tieBreakSet: MatchSet
|
|
10
|
-
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
set = new MatchSet({
|
|
13
|
-
id: '4a8d1149-0157-461c-afb4-8a2d9776da5a',
|
|
14
|
-
rallies: [],
|
|
15
|
-
stats: [],
|
|
16
|
-
awayScore: 0,
|
|
17
|
-
homeScore: 0,
|
|
18
|
-
order: 0,
|
|
19
|
-
isTieBreak: false,
|
|
20
|
-
homeLibero: libero,
|
|
21
|
-
awayLibero: libero
|
|
22
|
-
})
|
|
23
|
-
tieBreakSet = new MatchSet({
|
|
24
|
-
id: '5fed79c1-1146-45fb-acdd-acd4eb99bda3',
|
|
25
|
-
rallies: [],
|
|
26
|
-
stats: [],
|
|
27
|
-
awayScore: 0,
|
|
28
|
-
homeScore: 0,
|
|
29
|
-
order: 0,
|
|
30
|
-
isTieBreak: true,
|
|
31
|
-
homeLibero: libero,
|
|
32
|
-
awayLibero: libero
|
|
33
|
-
})
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
test('Should instantiate object properly', () => {
|
|
37
|
-
expect(set.id).toBe('4a8d1149-0157-461c-afb4-8a2d9776da5a')
|
|
38
|
-
expect(set.rallies.length).toBe(0)
|
|
39
|
-
expect(set.state).toBe(0)
|
|
40
|
-
expect(set.getHomeScore()).toBe(0)
|
|
41
|
-
expect(set.getAwayScore()).toBe(0)
|
|
42
|
-
})
|
|
43
|
-
// increaseScore Tests
|
|
44
|
-
test('Should increase score of home team', () => {
|
|
45
|
-
set.nextState()
|
|
46
|
-
expect(set.getHomeScore).toBe(0)
|
|
47
|
-
set.increaseScore(MatchTeam.HOME)
|
|
48
|
-
expect(set.getHomeScore).toBe(1)
|
|
49
|
-
})
|
|
50
|
-
test('Should increase score of away team', () => {
|
|
51
|
-
set.nextState()
|
|
52
|
-
expect(set.getAwayScore).toBe(0)
|
|
53
|
-
set.increaseScore(MatchTeam.AWAY)
|
|
54
|
-
expect(set.getAwayScore).toBe(1)
|
|
55
|
-
})
|
|
56
|
-
test('Should throw Error when trying to increase score of finished set', () => {
|
|
57
|
-
set.nextState()
|
|
58
|
-
for (let i = 0; i < 25; i++) set.increaseScore(MatchTeam.HOME)
|
|
59
|
-
|
|
60
|
-
function fin1 (): void { set.increaseScore(MatchTeam.HOME) }
|
|
61
|
-
|
|
62
|
-
function fin2 (): void { tieBreakSet.increaseScore(MatchTeam.HOME) }
|
|
63
|
-
|
|
64
|
-
expect(fin1).toThrow(/^CANNOT_INCREASE_SCORE_OF_SET$/)
|
|
65
|
-
expect(fin2).toThrow(/^CANNOT_INCREASE_SCORE_OF_SET$/)
|
|
66
|
-
})
|
|
67
|
-
test('Should throw Error when providing invalid team', () => {
|
|
68
|
-
set.nextState()
|
|
69
|
-
|
|
70
|
-
// @ts-expect-error
|
|
71
|
-
function fin (): void { set.increaseScore(MatchTeam.OTHER) }
|
|
72
|
-
|
|
73
|
-
expect(fin).toThrow(/^UNKNOWN_TEAM$/)
|
|
74
|
-
})
|
|
75
|
-
// addRally Tests
|
|
76
|
-
test('Should rally to rally array', () => {
|
|
77
|
-
expect(set.rallies.length).toBe(0)
|
|
78
|
-
set.addRally(newRally)
|
|
79
|
-
expect(set.rallies.length).toBe(1)
|
|
80
|
-
})
|
|
81
|
-
// isOver Tests
|
|
82
|
-
test('Should return true for team reaching point threshold', () => {
|
|
83
|
-
set.nextState()
|
|
84
|
-
expect(set.isOver()).toBe(false)
|
|
85
|
-
|
|
86
|
-
for (let i = 0; i < 25; i++) set.increaseScore(MatchTeam.HOME)
|
|
87
|
-
|
|
88
|
-
expect(set.isOver()).toBe(true)
|
|
89
|
-
})
|
|
90
|
-
test('Should return true for both teams reaching point threshold and point difference greater than 1',
|
|
91
|
-
() => {
|
|
92
|
-
set.nextState()
|
|
93
|
-
|
|
94
|
-
for (let i = 0; i < 25; i++) {
|
|
95
|
-
set.increaseScore(MatchTeam.HOME)
|
|
96
|
-
set.increaseScore(MatchTeam.AWAY)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
expect(set.isOver()).toBe(false)
|
|
100
|
-
set.increaseScore(MatchTeam.HOME)
|
|
101
|
-
expect(set.isOver()).toBe(false)
|
|
102
|
-
set.increaseScore(MatchTeam.HOME)
|
|
103
|
-
expect(set.isOver()).toBe(true)
|
|
104
|
-
})
|
|
105
|
-
// nextState Tests
|
|
106
|
-
test('Should advance to in play', () => {
|
|
107
|
-
expect(set.state).toBe(0)
|
|
108
|
-
set.nextState()
|
|
109
|
-
expect(set.state).toBe(1)
|
|
110
|
-
})
|
|
111
|
-
test('Should throw Error if in play and set not over', () => {
|
|
112
|
-
set.nextState()
|
|
113
|
-
|
|
114
|
-
function fin (): void { set.nextState() }
|
|
115
|
-
|
|
116
|
-
expect(fin).toThrow(/^CANNOT_ADVANCE_SET_STATE$/)
|
|
117
|
-
})
|
|
118
|
-
test('Should advance to FINISHED if set is over', () => {
|
|
119
|
-
set.nextState()
|
|
120
|
-
|
|
121
|
-
for (let i = 0; i < 25; i++) set.increaseScore(MatchTeam.HOME)
|
|
122
|
-
|
|
123
|
-
set.nextState()
|
|
124
|
-
expect(set.state).toBe(2)
|
|
125
|
-
})
|
|
126
|
-
test('Should throw Error when trying to transition from FINISHED state', () => {
|
|
127
|
-
set.nextState()
|
|
128
|
-
|
|
129
|
-
for (let i = 0; i < 25; i++) set.increaseScore(MatchTeam.HOME)
|
|
130
|
-
|
|
131
|
-
set.nextState()
|
|
132
|
-
|
|
133
|
-
function fin (): void { set.nextState() }
|
|
134
|
-
|
|
135
|
-
expect(fin).toThrow(/^CANT_GET_STATE_AFTER: FINISHED$/)
|
|
136
|
-
})
|
|
137
|
-
// getWinner Tests
|
|
138
|
-
test('Should throw Error when getting winner of unfinished set', () => {
|
|
139
|
-
function fin (): void { set.getWinner() }
|
|
140
|
-
|
|
141
|
-
expect(fin).toThrow(/^UNFINISHED_SET$/)
|
|
142
|
-
})
|
|
143
|
-
test('Should get correct set winner', () => {
|
|
144
|
-
set.nextState()
|
|
145
|
-
|
|
146
|
-
for (let i = 0; i < 25; i++) set.increaseScore(MatchTeam.HOME)
|
|
147
|
-
|
|
148
|
-
expect(set.getWinner()).toBe(MatchTeam.HOME)
|
|
149
|
-
|
|
150
|
-
tieBreakSet.nextState()
|
|
151
|
-
|
|
152
|
-
for (let i = 0; i < 15; i++) tieBreakSet.increaseScore(MatchTeam.AWAY)
|
|
153
|
-
|
|
154
|
-
expect(tieBreakSet.getWinner()).toBe(MatchTeam.AWAY)
|
|
155
|
-
})
|
|
156
|
-
// MatchSetState Tests
|
|
157
|
-
test('Should get next state', () => {
|
|
158
|
-
expect(MatchSetState.nextState(0)).toBe(1)
|
|
159
|
-
expect(MatchSetState.nextState(1)).toBe(2)
|
|
160
|
-
})
|
|
161
|
-
test('Should throw Error for state outside range', () => {
|
|
162
|
-
function fn1 (): void { MatchSetState.nextState(-1) }
|
|
163
|
-
|
|
164
|
-
function fn2 (): void { MatchSetState.nextState(3) }
|
|
165
|
-
|
|
166
|
-
expect(fn1).toThrow(/^STATE_INDEX_OUT_OF_BOUNDS$/)
|
|
167
|
-
expect(fn2).toThrow(/^STATE_INDEX_OUT_OF_BOUNDS$/)
|
|
168
|
-
})
|
|
169
|
-
test('Should throw Error for last state', () => {
|
|
170
|
-
function fn (): void { MatchSetState.nextState(2) }
|
|
171
|
-
|
|
172
|
-
expect(fn).toThrow(/^CANT_GET_STATE_AFTER: FINISHED$/)
|
|
173
|
-
})
|
|
174
|
-
})
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { Rally } from './rally'
|
|
2
|
-
import { validateUUID } from '../utils'
|
|
3
|
-
import { MatchTeam } from './match-team'
|
|
4
|
-
import { Player } from '../player'
|
|
5
|
-
|
|
6
|
-
export enum MatchSetState {
|
|
7
|
-
NEW = 0,
|
|
8
|
-
IN_PLAY = 1,
|
|
9
|
-
FINISHED = 2
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
13
|
-
export namespace MatchSetState {
|
|
14
|
-
export function nextState (state: number): MatchSetState {
|
|
15
|
-
if (state < 0 || state > 2) throw new Error('STATE_INDEX_OUT_OF_BOUNDS')
|
|
16
|
-
if (state === 2) throw new Error(`CANT_GET_STATE_AFTER: ${MatchSetState[state]}`)
|
|
17
|
-
|
|
18
|
-
return state + 1
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
enum ScoreThreshold {
|
|
23
|
-
SET = 25,
|
|
24
|
-
TIE_BREAK = 15
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface MatchSetOpts {
|
|
28
|
-
readonly id: string
|
|
29
|
-
readonly order: number
|
|
30
|
-
readonly isTieBreak: boolean
|
|
31
|
-
readonly homeLibero: Player | undefined
|
|
32
|
-
readonly awayLibero: Player | undefined
|
|
33
|
-
readonly homeScore: number
|
|
34
|
-
readonly awayScore: number
|
|
35
|
-
readonly stats: SetStatistics[]
|
|
36
|
-
readonly rallies: Rally[]
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface EventStat {
|
|
40
|
-
success: number
|
|
41
|
-
error: number
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface SetStatistics {
|
|
45
|
-
player: Player
|
|
46
|
-
ace: number
|
|
47
|
-
attempts: number
|
|
48
|
-
contacts: number
|
|
49
|
-
ralliesPlayed: number
|
|
50
|
-
serve: EventStat
|
|
51
|
-
reception: EventStat
|
|
52
|
-
set: EventStat
|
|
53
|
-
attack: EventStat
|
|
54
|
-
block: EventStat
|
|
55
|
-
kills: number
|
|
56
|
-
killBlocks: number
|
|
57
|
-
assists: number
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export class MatchSet {
|
|
61
|
-
readonly id: string
|
|
62
|
-
readonly order: number
|
|
63
|
-
readonly isTieBreak: boolean
|
|
64
|
-
readonly homeLibero: Player | undefined
|
|
65
|
-
readonly awayLibero: Player | undefined
|
|
66
|
-
private readonly scoreThreshold: ScoreThreshold
|
|
67
|
-
private homeScore: number
|
|
68
|
-
private awayScore: number
|
|
69
|
-
readonly stats: SetStatistics[]
|
|
70
|
-
readonly rallies: Rally[]
|
|
71
|
-
|
|
72
|
-
constructor ({ id, order, isTieBreak, homeLibero, awayLibero, stats, rallies, homeScore, awayScore }: MatchSetOpts) {
|
|
73
|
-
validateUUID(id)
|
|
74
|
-
|
|
75
|
-
this.id = id
|
|
76
|
-
this.order = order
|
|
77
|
-
this.homeScore = homeScore
|
|
78
|
-
this.awayScore = awayScore
|
|
79
|
-
this.homeLibero = homeLibero
|
|
80
|
-
this.awayLibero = awayLibero
|
|
81
|
-
this.stats = stats
|
|
82
|
-
this.rallies = rallies
|
|
83
|
-
this.isTieBreak = isTieBreak
|
|
84
|
-
this.scoreThreshold = isTieBreak ? ScoreThreshold.TIE_BREAK : ScoreThreshold.SET
|
|
85
|
-
this._state = MatchSetState.NEW
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
public getHomeScore (): number {
|
|
89
|
-
return this.homeScore
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
public getAwayScore (): number {
|
|
93
|
-
return this.awayScore
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
private _state: MatchSetState
|
|
97
|
-
|
|
98
|
-
get state (): MatchSetState {
|
|
99
|
-
return this._state
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
public increaseScore (team: MatchTeam): void {
|
|
103
|
-
if (this._state !== MatchSetState.IN_PLAY || this.isOver()) throw new Error('CANNOT_INCREASE_SCORE_OF_SET')
|
|
104
|
-
|
|
105
|
-
if (team === MatchTeam.HOME) this.homeScore++
|
|
106
|
-
else if (team === MatchTeam.AWAY) this.awayScore++
|
|
107
|
-
else throw new Error('UNKNOWN_TEAM')
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
public addRally (rally: Rally): void {
|
|
111
|
-
this.rallies.push(rally)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Has a team reached at least 25 points and is the score difference between both teams at least 2?
|
|
116
|
-
* @returns boolean
|
|
117
|
-
*/
|
|
118
|
-
public isOver (): boolean {
|
|
119
|
-
return Math.abs(this.homeScore - this.awayScore) > 1 &&
|
|
120
|
-
(this.homeScore >= this.scoreThreshold || this.awayScore >= this.scoreThreshold)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
public nextState (): void {
|
|
124
|
-
if (this._state === 1 && !this.isOver()) {
|
|
125
|
-
throw new Error('CANNOT_ADVANCE_SET_STATE')
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
this._state = MatchSetState.nextState(this._state)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Get the team that won the Set. Return undefined if set is not over.
|
|
133
|
-
* @returns CourtTeam
|
|
134
|
-
*/
|
|
135
|
-
public getWinner (): MatchTeam {
|
|
136
|
-
if (!this.isOver()) throw new Error('UNFINISHED_SET')
|
|
137
|
-
|
|
138
|
-
return this.homeScore > this.awayScore ? MatchTeam.HOME : MatchTeam.AWAY
|
|
139
|
-
}
|
|
140
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from '@jest/globals'
|
|
2
|
-
import { MatchTeam } from './match-team'
|
|
3
|
-
|
|
4
|
-
describe('MatchTeam Test Module', () => {
|
|
5
|
-
// otherTeam Tests
|
|
6
|
-
test('Should return correct team string', () => {
|
|
7
|
-
expect(MatchTeam.otherTeam(MatchTeam.AWAY)).toBe(MatchTeam.HOME)
|
|
8
|
-
expect(MatchTeam.otherTeam(MatchTeam.HOME)).toBe(MatchTeam.AWAY)
|
|
9
|
-
})
|
|
10
|
-
test('Should throw Error when providing invalid MatchTeam', () => {
|
|
11
|
-
// @ts-expect-error
|
|
12
|
-
function team (): void { MatchTeam.otherTeam(MatchTeam.OTHER) }
|
|
13
|
-
|
|
14
|
-
expect(team).toThrow(/^UNKNOWN_MATCH_TEAM$/)
|
|
15
|
-
})
|
|
16
|
-
})
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export enum MatchTeam {
|
|
2
|
-
HOME = 'homeTeam',
|
|
3
|
-
AWAY = 'awayTeam'
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
7
|
-
export namespace MatchTeam {
|
|
8
|
-
export function otherTeam (team: MatchTeam): MatchTeam {
|
|
9
|
-
if (team === MatchTeam.HOME) return MatchTeam.AWAY
|
|
10
|
-
else if (team === MatchTeam.AWAY) return MatchTeam.HOME
|
|
11
|
-
else throw new Error('UNKNOWN_MATCH_TEAM')
|
|
12
|
-
}
|
|
13
|
-
}
|