volleyballsimtypes 0.0.99 → 0.0.100

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.
@@ -41,11 +41,9 @@ exports.finishedSet = (() => {
41
41
  homeLibero: __stubs__2.libero,
42
42
  awayLibero: __stubs__2.libero
43
43
  });
44
- set.nextState();
45
44
  for (let i = 0; i < 25; i++) {
46
45
  set.increaseScore(match_team_1.MatchTeam.HOME);
47
46
  }
48
- set.nextState();
49
47
  return set;
50
48
  })();
51
49
  exports.inProgressSet = (() => {
@@ -60,7 +58,6 @@ exports.inProgressSet = (() => {
60
58
  homeLibero: __stubs__2.libero,
61
59
  awayLibero: __stubs__2.libero
62
60
  });
63
- set.nextState();
64
61
  for (let i = 0; i < 20; i++) {
65
62
  set.increaseScore(match_team_1.MatchTeam.AWAY);
66
63
  }
@@ -1,14 +1,6 @@
1
1
  import { Rally } from './rally';
2
2
  import { MatchTeam } from './match-team';
3
3
  import { Player } from '../player';
4
- export declare enum MatchSetState {
5
- NEW = 0,
6
- IN_PLAY = 1,
7
- FINISHED = 2
8
- }
9
- export declare namespace MatchSetState {
10
- function nextState(state: number): MatchSetState;
11
- }
12
4
  interface MatchSetOpts {
13
5
  readonly id: string;
14
6
  readonly order: number;
@@ -50,9 +42,7 @@ export declare class MatchSet {
50
42
  private readonly scoreThreshold;
51
43
  private homeScore;
52
44
  private awayScore;
53
- private _state;
54
45
  constructor({ id, order, isTieBreak, homeLibero, awayLibero, stats, rallies, homeScore, awayScore }: MatchSetOpts);
55
- get state(): MatchSetState;
56
46
  getHomeScore(): number;
57
47
  getAwayScore(): number;
58
48
  increaseScore(team: MatchTeam): void;
@@ -62,7 +52,6 @@ export declare class MatchSet {
62
52
  * @returns boolean
63
53
  */
64
54
  isOver(): boolean;
65
- nextState(): void;
66
55
  /**
67
56
  * Get the team that won the Set. Return undefined if set is not over.
68
57
  * @returns CourtTeam
@@ -1,25 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MatchSet = exports.MatchSetState = void 0;
3
+ exports.MatchSet = void 0;
4
4
  const utils_1 = require("../utils");
5
5
  const match_team_1 = require("./match-team");
6
- var MatchSetState;
7
- (function (MatchSetState) {
8
- MatchSetState[MatchSetState["NEW"] = 0] = "NEW";
9
- MatchSetState[MatchSetState["IN_PLAY"] = 1] = "IN_PLAY";
10
- MatchSetState[MatchSetState["FINISHED"] = 2] = "FINISHED";
11
- })(MatchSetState = exports.MatchSetState || (exports.MatchSetState = {}));
12
- // eslint-disable-next-line @typescript-eslint/no-namespace
13
- (function (MatchSetState) {
14
- function nextState(state) {
15
- if (state < 0 || state > 2)
16
- throw new Error('STATE_INDEX_OUT_OF_BOUNDS');
17
- if (state === 2)
18
- throw new Error(`CANT_GET_STATE_AFTER: ${MatchSetState[state]}`);
19
- return state + 1;
20
- }
21
- MatchSetState.nextState = nextState;
22
- })(MatchSetState = exports.MatchSetState || (exports.MatchSetState = {}));
23
6
  var ScoreThreshold;
24
7
  (function (ScoreThreshold) {
25
8
  ScoreThreshold[ScoreThreshold["SET"] = 25] = "SET";
@@ -38,10 +21,6 @@ class MatchSet {
38
21
  this.rallies = rallies;
39
22
  this.isTieBreak = isTieBreak;
40
23
  this.scoreThreshold = isTieBreak ? ScoreThreshold.TIE_BREAK : ScoreThreshold.SET;
41
- this._state = MatchSetState.NEW;
42
- }
43
- get state() {
44
- return this._state;
45
24
  }
46
25
  getHomeScore() {
47
26
  return this.homeScore;
@@ -50,8 +29,6 @@ class MatchSet {
50
29
  return this.awayScore;
51
30
  }
52
31
  increaseScore(team) {
53
- if (this._state !== MatchSetState.IN_PLAY || this.isOver())
54
- throw new Error('CANNOT_INCREASE_SCORE_OF_SET');
55
32
  if (team === match_team_1.MatchTeam.HOME)
56
33
  this.homeScore++;
57
34
  else if (team === match_team_1.MatchTeam.AWAY)
@@ -70,12 +47,6 @@ class MatchSet {
70
47
  return Math.abs(this.homeScore - this.awayScore) > 1 &&
71
48
  (this.homeScore >= this.scoreThreshold || this.awayScore >= this.scoreThreshold);
72
49
  }
73
- nextState() {
74
- if (this._state === 1 && !this.isOver()) {
75
- throw new Error('CANNOT_ADVANCE_SET_STATE');
76
- }
77
- this._state = MatchSetState.nextState(this._state);
78
- }
79
50
  /**
80
51
  * Get the team that won the Set. Return undefined if set is not over.
81
52
  * @returns CourtTeam
@@ -35,25 +35,21 @@ const __stubs__2 = require("../player/__stubs__");
35
35
  (0, globals_1.test)('Should instantiate object properly', () => {
36
36
  (0, globals_1.expect)(set.id).toBe('4a8d1149-0157-461c-afb4-8a2d9776da5a');
37
37
  (0, globals_1.expect)(set.rallies.length).toBe(0);
38
- (0, globals_1.expect)(set.state).toBe(0);
39
38
  (0, globals_1.expect)(set.getHomeScore()).toBe(0);
40
39
  (0, globals_1.expect)(set.getAwayScore()).toBe(0);
41
40
  });
42
41
  // increaseScore Tests
43
42
  (0, globals_1.test)('Should increase score of home team', () => {
44
- set.nextState();
45
43
  (0, globals_1.expect)(set.getHomeScore).toBe(0);
46
44
  set.increaseScore(match_team_1.MatchTeam.HOME);
47
45
  (0, globals_1.expect)(set.getHomeScore).toBe(1);
48
46
  });
49
47
  (0, globals_1.test)('Should increase score of away team', () => {
50
- set.nextState();
51
48
  (0, globals_1.expect)(set.getAwayScore).toBe(0);
52
49
  set.increaseScore(match_team_1.MatchTeam.AWAY);
53
50
  (0, globals_1.expect)(set.getAwayScore).toBe(1);
54
51
  });
55
52
  (0, globals_1.test)('Should throw Error when trying to increase score of finished set', () => {
56
- set.nextState();
57
53
  for (let i = 0; i < 25; i++)
58
54
  set.increaseScore(match_team_1.MatchTeam.HOME);
59
55
  function fin1() { set.increaseScore(match_team_1.MatchTeam.HOME); }
@@ -62,7 +58,6 @@ const __stubs__2 = require("../player/__stubs__");
62
58
  (0, globals_1.expect)(fin2).toThrow(/^CANNOT_INCREASE_SCORE_OF_SET$/);
63
59
  });
64
60
  (0, globals_1.test)('Should throw Error when providing invalid team', () => {
65
- set.nextState();
66
61
  // @ts-expect-error
67
62
  function fin() { set.increaseScore(match_team_1.MatchTeam.OTHER); }
68
63
  (0, globals_1.expect)(fin).toThrow(/^UNKNOWN_TEAM$/);
@@ -75,14 +70,12 @@ const __stubs__2 = require("../player/__stubs__");
75
70
  });
76
71
  // isOver Tests
77
72
  (0, globals_1.test)('Should return true for team reaching point threshold', () => {
78
- set.nextState();
79
73
  (0, globals_1.expect)(set.isOver()).toBe(false);
80
74
  for (let i = 0; i < 25; i++)
81
75
  set.increaseScore(match_team_1.MatchTeam.HOME);
82
76
  (0, globals_1.expect)(set.isOver()).toBe(true);
83
77
  });
84
78
  (0, globals_1.test)('Should return true for both teams reaching point threshold and point difference greater than 1', () => {
85
- set.nextState();
86
79
  for (let i = 0; i < 25; i++) {
87
80
  set.increaseScore(match_team_1.MatchTeam.HOME);
88
81
  set.increaseScore(match_team_1.MatchTeam.AWAY);
@@ -93,60 +86,17 @@ const __stubs__2 = require("../player/__stubs__");
93
86
  set.increaseScore(match_team_1.MatchTeam.HOME);
94
87
  (0, globals_1.expect)(set.isOver()).toBe(true);
95
88
  });
96
- // nextState Tests
97
- (0, globals_1.test)('Should advance to in play', () => {
98
- (0, globals_1.expect)(set.state).toBe(0);
99
- set.nextState();
100
- (0, globals_1.expect)(set.state).toBe(1);
101
- });
102
- (0, globals_1.test)('Should throw Error if in play and set not over', () => {
103
- set.nextState();
104
- function fin() { set.nextState(); }
105
- (0, globals_1.expect)(fin).toThrow(/^CANNOT_ADVANCE_SET_STATE$/);
106
- });
107
- (0, globals_1.test)('Should advance to FINISHED if set is over', () => {
108
- set.nextState();
109
- for (let i = 0; i < 25; i++)
110
- set.increaseScore(match_team_1.MatchTeam.HOME);
111
- set.nextState();
112
- (0, globals_1.expect)(set.state).toBe(2);
113
- });
114
- (0, globals_1.test)('Should throw Error when trying to transition from FINISHED state', () => {
115
- set.nextState();
116
- for (let i = 0; i < 25; i++)
117
- set.increaseScore(match_team_1.MatchTeam.HOME);
118
- set.nextState();
119
- function fin() { set.nextState(); }
120
- (0, globals_1.expect)(fin).toThrow(/^CANT_GET_STATE_AFTER: FINISHED$/);
121
- });
122
89
  // getWinner Tests
123
90
  (0, globals_1.test)('Should throw Error when getting winner of unfinished set', () => {
124
91
  function fin() { set.getWinner(); }
125
92
  (0, globals_1.expect)(fin).toThrow(/^UNFINISHED_SET$/);
126
93
  });
127
94
  (0, globals_1.test)('Should get correct set winner', () => {
128
- set.nextState();
129
95
  for (let i = 0; i < 25; i++)
130
96
  set.increaseScore(match_team_1.MatchTeam.HOME);
131
97
  (0, globals_1.expect)(set.getWinner()).toBe(match_team_1.MatchTeam.HOME);
132
- tieBreakSet.nextState();
133
98
  for (let i = 0; i < 15; i++)
134
99
  tieBreakSet.increaseScore(match_team_1.MatchTeam.AWAY);
135
100
  (0, globals_1.expect)(tieBreakSet.getWinner()).toBe(match_team_1.MatchTeam.AWAY);
136
101
  });
137
- // MatchSetState Tests
138
- (0, globals_1.test)('Should get next state', () => {
139
- (0, globals_1.expect)(match_set_1.MatchSetState.nextState(0)).toBe(1);
140
- (0, globals_1.expect)(match_set_1.MatchSetState.nextState(1)).toBe(2);
141
- });
142
- (0, globals_1.test)('Should throw Error for state outside range', () => {
143
- function fn1() { match_set_1.MatchSetState.nextState(-1); }
144
- function fn2() { match_set_1.MatchSetState.nextState(3); }
145
- (0, globals_1.expect)(fn1).toThrow(/^STATE_INDEX_OUT_OF_BOUNDS$/);
146
- (0, globals_1.expect)(fn2).toThrow(/^STATE_INDEX_OUT_OF_BOUNDS$/);
147
- });
148
- (0, globals_1.test)('Should throw Error for last state', () => {
149
- function fn() { match_set_1.MatchSetState.nextState(2); }
150
- (0, globals_1.expect)(fn).toThrow(/^CANT_GET_STATE_AFTER: FINISHED$/);
151
- });
152
102
  });
@@ -1,7 +1,6 @@
1
1
  import { Team } from '../team';
2
2
  import { CourtPosition } from './court-position';
3
- import { RallyEvent } from '../event/rally-event';
4
- import { Score } from '../event/score';
3
+ import { RallyEvent, Score } from '../event';
5
4
  interface RallyOpts {
6
5
  readonly id: string;
7
6
  readonly order: number;
@@ -14,15 +13,6 @@ export interface PlayerPosition {
14
13
  position: CourtPosition;
15
14
  playerId: string;
16
15
  }
17
- export declare enum RallyState {
18
- NEW = 0,
19
- MANAGEMENT = 1,
20
- IN_PLAY = 2,
21
- FINISHED = 3
22
- }
23
- export declare namespace RallyState {
24
- function nextState(state: number): RallyState;
25
- }
26
16
  export declare class Rally {
27
17
  readonly id: string;
28
18
  readonly servingTeam: Team;
@@ -30,12 +20,8 @@ export declare class Rally {
30
20
  readonly homePlayerPosition: PlayerPosition[];
31
21
  readonly awayPlayerPosition: PlayerPosition[];
32
22
  readonly order: number;
33
- private _state;
34
23
  constructor({ id, order, servingTeam, homePlayerPosition, awayPlayerPosition, events }: RallyOpts);
35
- get state(): RallyState;
36
24
  get score(): Score | undefined;
37
- isOver(): boolean;
38
25
  addEvent(event: RallyEvent): void;
39
- nextState(): void;
40
26
  }
41
27
  export {};
@@ -1,26 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Rally = exports.RallyState = void 0;
3
+ exports.Rally = void 0;
4
4
  const utils_1 = require("../utils");
5
- const rally_event_1 = require("../event/rally-event");
6
- var RallyState;
7
- (function (RallyState) {
8
- RallyState[RallyState["NEW"] = 0] = "NEW";
9
- RallyState[RallyState["MANAGEMENT"] = 1] = "MANAGEMENT";
10
- RallyState[RallyState["IN_PLAY"] = 2] = "IN_PLAY";
11
- RallyState[RallyState["FINISHED"] = 3] = "FINISHED";
12
- })(RallyState = exports.RallyState || (exports.RallyState = {}));
13
- // eslint-disable-next-line @typescript-eslint/no-namespace
14
- (function (RallyState) {
15
- function nextState(state) {
16
- if (state < 0 || state > 3)
17
- throw new Error('STATE_INDEX_OUT_OF_BOUNDS');
18
- if (state === 3)
19
- throw new Error(`CANT_GET_STATE_AFTER: ${RallyState[state]}`);
20
- return state + 1;
21
- }
22
- RallyState.nextState = nextState;
23
- })(RallyState = exports.RallyState || (exports.RallyState = {}));
5
+ const event_1 = require("../event");
24
6
  class Rally {
25
7
  constructor({ id, order, servingTeam, homePlayerPosition, awayPlayerPosition, events }) {
26
8
  (0, utils_1.validateUUID)(id);
@@ -30,22 +12,12 @@ class Rally {
30
12
  this.homePlayerPosition = homePlayerPosition;
31
13
  this.awayPlayerPosition = awayPlayerPosition;
32
14
  this.events = events;
33
- this._state = RallyState.NEW;
34
- }
35
- get state() {
36
- return this._state;
37
15
  }
38
16
  get score() {
39
- return this.events.find(e => e.eventType === rally_event_1.EventTypeEnum.SCORE);
40
- }
41
- isOver() {
42
- return this._state === RallyState.FINISHED;
17
+ return this.events.find(e => e.eventType === event_1.EventTypeEnum.SCORE);
43
18
  }
44
19
  addEvent(event) {
45
20
  this.events.push(event);
46
21
  }
47
- nextState() {
48
- this._state = RallyState.nextState(this._state);
49
- }
50
22
  }
51
23
  exports.Rally = Rally;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const globals_1 = require("@jest/globals");
4
4
  const rally_1 = require("./rally");
5
5
  const __stubs__1 = require("../event/__stubs__");
6
- const rally_event_1 = require("../event/rally-event");
6
+ const event_1 = require("../event");
7
7
  const __stubs__2 = require("../team/__stubs__");
8
8
  (0, globals_1.describe)('Rally Test Module', () => {
9
9
  let rally;
@@ -21,44 +21,12 @@ const __stubs__2 = require("../team/__stubs__");
21
21
  (0, globals_1.expect)(rally.id).toBe('0ac3ba3a-d710-42dc-a1e7-7066b8df5fd9');
22
22
  (0, globals_1.expect)(rally.servingTeam.id).toBe('426b5b9b-5be7-4963-92eb-71b7a3b29ffd');
23
23
  (0, globals_1.expect)(rally.events.length).toBe(0);
24
- (0, globals_1.expect)(rally.state).toBe(0);
25
- });
26
- // nextState Tests
27
- (0, globals_1.test)('Should cycle through states correctly', () => {
28
- (0, globals_1.expect)(rally.state).toBe(0);
29
- rally.nextState();
30
- (0, globals_1.expect)(rally.state).toBe(1);
31
- rally.nextState();
32
- (0, globals_1.expect)(rally.state).toBe(2);
33
- rally.nextState();
34
- (0, globals_1.expect)(rally.state).toBe(3);
35
- });
36
- (0, globals_1.test)('Should throw Error when trying to get next state after FINISHED', () => {
37
- function state() {
38
- rally.nextState();
39
- rally.nextState();
40
- rally.nextState();
41
- rally.nextState();
42
- }
43
- (0, globals_1.expect)(state).toThrow(/^CANT_GET_STATE_AFTER: FINISHED$/);
44
24
  });
45
25
  // addEvent Tests
46
26
  (0, globals_1.test)('Should add event to event array', () => {
47
27
  (0, globals_1.expect)(rally.events.length).toBe(0);
48
28
  rally.addEvent(__stubs__1.serve);
49
- (0, globals_1.expect)(rally.events.at(-1)?.eventType).toBe(rally_event_1.EventTypeEnum.SERVE);
50
- });
51
- // isOver Tests
52
- (0, globals_1.test)('Should return false if rally state is not FINISHED', () => {
53
- (0, globals_1.expect)(rally.state).toBe(0);
54
- (0, globals_1.expect)(rally.isOver()).toBe(false);
55
- });
56
- (0, globals_1.test)('Should return true if rally state is FINISHED', () => {
57
- rally.nextState();
58
- rally.nextState();
59
- rally.nextState();
60
- (0, globals_1.expect)(rally.state).toBe(3);
61
- (0, globals_1.expect)(rally.isOver()).toBe(true);
29
+ (0, globals_1.expect)(rally.events.at(-1)?.eventType).toBe(event_1.EventTypeEnum.SERVE);
62
30
  });
63
31
  // getScore Tests
64
32
  (0, globals_1.test)('Should return undefined if events array does not contain a Score', () => {
@@ -68,21 +36,6 @@ const __stubs__2 = require("../team/__stubs__");
68
36
  (0, globals_1.test)('Should return Score if events array contains a Score', () => {
69
37
  rally.addEvent(__stubs__1.score);
70
38
  (0, globals_1.expect)(rally.score).not.toBeUndefined();
71
- (0, globals_1.expect)(rally.score?.eventType).toBe(rally_event_1.EventTypeEnum.SCORE);
72
- });
73
- // RallyState Tests
74
- (0, globals_1.test)('Should get next state', () => {
75
- (0, globals_1.expect)(rally_1.RallyState.nextState(0)).toBe(1);
76
- (0, globals_1.expect)(rally_1.RallyState.nextState(1)).toBe(2);
77
- });
78
- (0, globals_1.test)('Should throw Error for state outside range', () => {
79
- function fn1() { rally_1.RallyState.nextState(-1); }
80
- function fn2() { rally_1.RallyState.nextState(4); }
81
- (0, globals_1.expect)(fn1).toThrow(/^STATE_INDEX_OUT_OF_BOUNDS$/);
82
- (0, globals_1.expect)(fn2).toThrow(/^STATE_INDEX_OUT_OF_BOUNDS$/);
83
- });
84
- (0, globals_1.test)('Should throw Error for last state', () => {
85
- function fn() { rally_1.RallyState.nextState(3); }
86
- (0, globals_1.expect)(fn).toThrow(/^CANT_GET_STATE_AFTER: FINISHED$/);
39
+ (0, globals_1.expect)(rally.score?.eventType).toBe(event_1.EventTypeEnum.SCORE);
87
40
  });
88
41
  });
@@ -38,11 +38,9 @@ export const finishedSet = (() => {
38
38
  homeLibero: libero,
39
39
  awayLibero: libero
40
40
  });
41
- set.nextState();
42
41
  for (let i = 0; i < 25; i++) {
43
42
  set.increaseScore(MatchTeam.HOME);
44
43
  }
45
- set.nextState();
46
44
  return set;
47
45
  })();
48
46
  export const inProgressSet = (() => {
@@ -57,7 +55,6 @@ export const inProgressSet = (() => {
57
55
  homeLibero: libero,
58
56
  awayLibero: libero
59
57
  });
60
- set.nextState();
61
58
  for (let i = 0; i < 20; i++) {
62
59
  set.increaseScore(MatchTeam.AWAY);
63
60
  }
@@ -1,14 +1,6 @@
1
1
  import { Rally } from './rally';
2
2
  import { MatchTeam } from './match-team';
3
3
  import { Player } from '../player';
4
- export declare enum MatchSetState {
5
- NEW = 0,
6
- IN_PLAY = 1,
7
- FINISHED = 2
8
- }
9
- export declare namespace MatchSetState {
10
- function nextState(state: number): MatchSetState;
11
- }
12
4
  interface MatchSetOpts {
13
5
  readonly id: string;
14
6
  readonly order: number;
@@ -50,9 +42,7 @@ export declare class MatchSet {
50
42
  private readonly scoreThreshold;
51
43
  private homeScore;
52
44
  private awayScore;
53
- private _state;
54
45
  constructor({ id, order, isTieBreak, homeLibero, awayLibero, stats, rallies, homeScore, awayScore }: MatchSetOpts);
55
- get state(): MatchSetState;
56
46
  getHomeScore(): number;
57
47
  getAwayScore(): number;
58
48
  increaseScore(team: MatchTeam): void;
@@ -62,7 +52,6 @@ export declare class MatchSet {
62
52
  * @returns boolean
63
53
  */
64
54
  isOver(): boolean;
65
- nextState(): void;
66
55
  /**
67
56
  * Get the team that won the Set. Return undefined if set is not over.
68
57
  * @returns CourtTeam
@@ -1,22 +1,5 @@
1
1
  import { validateUUID } from '../utils';
2
2
  import { MatchTeam } from './match-team';
3
- export var MatchSetState;
4
- (function (MatchSetState) {
5
- MatchSetState[MatchSetState["NEW"] = 0] = "NEW";
6
- MatchSetState[MatchSetState["IN_PLAY"] = 1] = "IN_PLAY";
7
- MatchSetState[MatchSetState["FINISHED"] = 2] = "FINISHED";
8
- })(MatchSetState || (MatchSetState = {}));
9
- // eslint-disable-next-line @typescript-eslint/no-namespace
10
- (function (MatchSetState) {
11
- function nextState(state) {
12
- if (state < 0 || state > 2)
13
- throw new Error('STATE_INDEX_OUT_OF_BOUNDS');
14
- if (state === 2)
15
- throw new Error(`CANT_GET_STATE_AFTER: ${MatchSetState[state]}`);
16
- return state + 1;
17
- }
18
- MatchSetState.nextState = nextState;
19
- })(MatchSetState || (MatchSetState = {}));
20
3
  var ScoreThreshold;
21
4
  (function (ScoreThreshold) {
22
5
  ScoreThreshold[ScoreThreshold["SET"] = 25] = "SET";
@@ -35,10 +18,6 @@ export class MatchSet {
35
18
  this.rallies = rallies;
36
19
  this.isTieBreak = isTieBreak;
37
20
  this.scoreThreshold = isTieBreak ? ScoreThreshold.TIE_BREAK : ScoreThreshold.SET;
38
- this._state = MatchSetState.NEW;
39
- }
40
- get state() {
41
- return this._state;
42
21
  }
43
22
  getHomeScore() {
44
23
  return this.homeScore;
@@ -47,8 +26,6 @@ export class MatchSet {
47
26
  return this.awayScore;
48
27
  }
49
28
  increaseScore(team) {
50
- if (this._state !== MatchSetState.IN_PLAY || this.isOver())
51
- throw new Error('CANNOT_INCREASE_SCORE_OF_SET');
52
29
  if (team === MatchTeam.HOME)
53
30
  this.homeScore++;
54
31
  else if (team === MatchTeam.AWAY)
@@ -67,12 +44,6 @@ export class MatchSet {
67
44
  return Math.abs(this.homeScore - this.awayScore) > 1 &&
68
45
  (this.homeScore >= this.scoreThreshold || this.awayScore >= this.scoreThreshold);
69
46
  }
70
- nextState() {
71
- if (this._state === 1 && !this.isOver()) {
72
- throw new Error('CANNOT_ADVANCE_SET_STATE');
73
- }
74
- this._state = MatchSetState.nextState(this._state);
75
- }
76
47
  /**
77
48
  * Get the team that won the Set. Return undefined if set is not over.
78
49
  * @returns CourtTeam
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, test } from '@jest/globals';
2
- import { MatchSet, MatchSetState } from './match-set';
2
+ import { MatchSet } from './match-set';
3
3
  import { MatchTeam } from './match-team';
4
4
  import { newRally } from './__stubs__';
5
5
  import { libero } from '../player/__stubs__';
@@ -33,25 +33,21 @@ describe('MatchSet Test Module', () => {
33
33
  test('Should instantiate object properly', () => {
34
34
  expect(set.id).toBe('4a8d1149-0157-461c-afb4-8a2d9776da5a');
35
35
  expect(set.rallies.length).toBe(0);
36
- expect(set.state).toBe(0);
37
36
  expect(set.getHomeScore()).toBe(0);
38
37
  expect(set.getAwayScore()).toBe(0);
39
38
  });
40
39
  // increaseScore Tests
41
40
  test('Should increase score of home team', () => {
42
- set.nextState();
43
41
  expect(set.getHomeScore).toBe(0);
44
42
  set.increaseScore(MatchTeam.HOME);
45
43
  expect(set.getHomeScore).toBe(1);
46
44
  });
47
45
  test('Should increase score of away team', () => {
48
- set.nextState();
49
46
  expect(set.getAwayScore).toBe(0);
50
47
  set.increaseScore(MatchTeam.AWAY);
51
48
  expect(set.getAwayScore).toBe(1);
52
49
  });
53
50
  test('Should throw Error when trying to increase score of finished set', () => {
54
- set.nextState();
55
51
  for (let i = 0; i < 25; i++)
56
52
  set.increaseScore(MatchTeam.HOME);
57
53
  function fin1() { set.increaseScore(MatchTeam.HOME); }
@@ -60,7 +56,6 @@ describe('MatchSet Test Module', () => {
60
56
  expect(fin2).toThrow(/^CANNOT_INCREASE_SCORE_OF_SET$/);
61
57
  });
62
58
  test('Should throw Error when providing invalid team', () => {
63
- set.nextState();
64
59
  // @ts-expect-error
65
60
  function fin() { set.increaseScore(MatchTeam.OTHER); }
66
61
  expect(fin).toThrow(/^UNKNOWN_TEAM$/);
@@ -73,14 +68,12 @@ describe('MatchSet Test Module', () => {
73
68
  });
74
69
  // isOver Tests
75
70
  test('Should return true for team reaching point threshold', () => {
76
- set.nextState();
77
71
  expect(set.isOver()).toBe(false);
78
72
  for (let i = 0; i < 25; i++)
79
73
  set.increaseScore(MatchTeam.HOME);
80
74
  expect(set.isOver()).toBe(true);
81
75
  });
82
76
  test('Should return true for both teams reaching point threshold and point difference greater than 1', () => {
83
- set.nextState();
84
77
  for (let i = 0; i < 25; i++) {
85
78
  set.increaseScore(MatchTeam.HOME);
86
79
  set.increaseScore(MatchTeam.AWAY);
@@ -91,60 +84,17 @@ describe('MatchSet Test Module', () => {
91
84
  set.increaseScore(MatchTeam.HOME);
92
85
  expect(set.isOver()).toBe(true);
93
86
  });
94
- // nextState Tests
95
- test('Should advance to in play', () => {
96
- expect(set.state).toBe(0);
97
- set.nextState();
98
- expect(set.state).toBe(1);
99
- });
100
- test('Should throw Error if in play and set not over', () => {
101
- set.nextState();
102
- function fin() { set.nextState(); }
103
- expect(fin).toThrow(/^CANNOT_ADVANCE_SET_STATE$/);
104
- });
105
- test('Should advance to FINISHED if set is over', () => {
106
- set.nextState();
107
- for (let i = 0; i < 25; i++)
108
- set.increaseScore(MatchTeam.HOME);
109
- set.nextState();
110
- expect(set.state).toBe(2);
111
- });
112
- test('Should throw Error when trying to transition from FINISHED state', () => {
113
- set.nextState();
114
- for (let i = 0; i < 25; i++)
115
- set.increaseScore(MatchTeam.HOME);
116
- set.nextState();
117
- function fin() { set.nextState(); }
118
- expect(fin).toThrow(/^CANT_GET_STATE_AFTER: FINISHED$/);
119
- });
120
87
  // getWinner Tests
121
88
  test('Should throw Error when getting winner of unfinished set', () => {
122
89
  function fin() { set.getWinner(); }
123
90
  expect(fin).toThrow(/^UNFINISHED_SET$/);
124
91
  });
125
92
  test('Should get correct set winner', () => {
126
- set.nextState();
127
93
  for (let i = 0; i < 25; i++)
128
94
  set.increaseScore(MatchTeam.HOME);
129
95
  expect(set.getWinner()).toBe(MatchTeam.HOME);
130
- tieBreakSet.nextState();
131
96
  for (let i = 0; i < 15; i++)
132
97
  tieBreakSet.increaseScore(MatchTeam.AWAY);
133
98
  expect(tieBreakSet.getWinner()).toBe(MatchTeam.AWAY);
134
99
  });
135
- // MatchSetState Tests
136
- test('Should get next state', () => {
137
- expect(MatchSetState.nextState(0)).toBe(1);
138
- expect(MatchSetState.nextState(1)).toBe(2);
139
- });
140
- test('Should throw Error for state outside range', () => {
141
- function fn1() { MatchSetState.nextState(-1); }
142
- function fn2() { MatchSetState.nextState(3); }
143
- expect(fn1).toThrow(/^STATE_INDEX_OUT_OF_BOUNDS$/);
144
- expect(fn2).toThrow(/^STATE_INDEX_OUT_OF_BOUNDS$/);
145
- });
146
- test('Should throw Error for last state', () => {
147
- function fn() { MatchSetState.nextState(2); }
148
- expect(fn).toThrow(/^CANT_GET_STATE_AFTER: FINISHED$/);
149
- });
150
100
  });
@@ -1,7 +1,6 @@
1
1
  import { Team } from '../team';
2
2
  import { CourtPosition } from './court-position';
3
- import { RallyEvent } from '../event/rally-event';
4
- import { Score } from '../event/score';
3
+ import { RallyEvent, Score } from '../event';
5
4
  interface RallyOpts {
6
5
  readonly id: string;
7
6
  readonly order: number;
@@ -14,15 +13,6 @@ export interface PlayerPosition {
14
13
  position: CourtPosition;
15
14
  playerId: string;
16
15
  }
17
- export declare enum RallyState {
18
- NEW = 0,
19
- MANAGEMENT = 1,
20
- IN_PLAY = 2,
21
- FINISHED = 3
22
- }
23
- export declare namespace RallyState {
24
- function nextState(state: number): RallyState;
25
- }
26
16
  export declare class Rally {
27
17
  readonly id: string;
28
18
  readonly servingTeam: Team;
@@ -30,12 +20,8 @@ export declare class Rally {
30
20
  readonly homePlayerPosition: PlayerPosition[];
31
21
  readonly awayPlayerPosition: PlayerPosition[];
32
22
  readonly order: number;
33
- private _state;
34
23
  constructor({ id, order, servingTeam, homePlayerPosition, awayPlayerPosition, events }: RallyOpts);
35
- get state(): RallyState;
36
24
  get score(): Score | undefined;
37
- isOver(): boolean;
38
25
  addEvent(event: RallyEvent): void;
39
- nextState(): void;
40
26
  }
41
27
  export {};
@@ -1,23 +1,5 @@
1
1
  import { validateUUID } from '../utils';
2
- import { EventTypeEnum } from '../event/rally-event';
3
- export var RallyState;
4
- (function (RallyState) {
5
- RallyState[RallyState["NEW"] = 0] = "NEW";
6
- RallyState[RallyState["MANAGEMENT"] = 1] = "MANAGEMENT";
7
- RallyState[RallyState["IN_PLAY"] = 2] = "IN_PLAY";
8
- RallyState[RallyState["FINISHED"] = 3] = "FINISHED";
9
- })(RallyState || (RallyState = {}));
10
- // eslint-disable-next-line @typescript-eslint/no-namespace
11
- (function (RallyState) {
12
- function nextState(state) {
13
- if (state < 0 || state > 3)
14
- throw new Error('STATE_INDEX_OUT_OF_BOUNDS');
15
- if (state === 3)
16
- throw new Error(`CANT_GET_STATE_AFTER: ${RallyState[state]}`);
17
- return state + 1;
18
- }
19
- RallyState.nextState = nextState;
20
- })(RallyState || (RallyState = {}));
2
+ import { EventTypeEnum } from '../event';
21
3
  export class Rally {
22
4
  constructor({ id, order, servingTeam, homePlayerPosition, awayPlayerPosition, events }) {
23
5
  validateUUID(id);
@@ -27,21 +9,11 @@ export class Rally {
27
9
  this.homePlayerPosition = homePlayerPosition;
28
10
  this.awayPlayerPosition = awayPlayerPosition;
29
11
  this.events = events;
30
- this._state = RallyState.NEW;
31
- }
32
- get state() {
33
- return this._state;
34
12
  }
35
13
  get score() {
36
14
  return this.events.find(e => e.eventType === EventTypeEnum.SCORE);
37
15
  }
38
- isOver() {
39
- return this._state === RallyState.FINISHED;
40
- }
41
16
  addEvent(event) {
42
17
  this.events.push(event);
43
18
  }
44
- nextState() {
45
- this._state = RallyState.nextState(this._state);
46
- }
47
19
  }
@@ -1,7 +1,7 @@
1
1
  import { describe, expect, test } from '@jest/globals';
2
- import { Rally, RallyState } from './rally';
2
+ import { Rally } from './rally';
3
3
  import { score, serve } from '../event/__stubs__';
4
- import { EventTypeEnum } from '../event/rally-event';
4
+ import { EventTypeEnum } from '../event';
5
5
  import { team } from '../team/__stubs__';
6
6
  describe('Rally Test Module', () => {
7
7
  let rally;
@@ -19,26 +19,6 @@ describe('Rally Test Module', () => {
19
19
  expect(rally.id).toBe('0ac3ba3a-d710-42dc-a1e7-7066b8df5fd9');
20
20
  expect(rally.servingTeam.id).toBe('426b5b9b-5be7-4963-92eb-71b7a3b29ffd');
21
21
  expect(rally.events.length).toBe(0);
22
- expect(rally.state).toBe(0);
23
- });
24
- // nextState Tests
25
- test('Should cycle through states correctly', () => {
26
- expect(rally.state).toBe(0);
27
- rally.nextState();
28
- expect(rally.state).toBe(1);
29
- rally.nextState();
30
- expect(rally.state).toBe(2);
31
- rally.nextState();
32
- expect(rally.state).toBe(3);
33
- });
34
- test('Should throw Error when trying to get next state after FINISHED', () => {
35
- function state() {
36
- rally.nextState();
37
- rally.nextState();
38
- rally.nextState();
39
- rally.nextState();
40
- }
41
- expect(state).toThrow(/^CANT_GET_STATE_AFTER: FINISHED$/);
42
22
  });
43
23
  // addEvent Tests
44
24
  test('Should add event to event array', () => {
@@ -46,18 +26,6 @@ describe('Rally Test Module', () => {
46
26
  rally.addEvent(serve);
47
27
  expect(rally.events.at(-1)?.eventType).toBe(EventTypeEnum.SERVE);
48
28
  });
49
- // isOver Tests
50
- test('Should return false if rally state is not FINISHED', () => {
51
- expect(rally.state).toBe(0);
52
- expect(rally.isOver()).toBe(false);
53
- });
54
- test('Should return true if rally state is FINISHED', () => {
55
- rally.nextState();
56
- rally.nextState();
57
- rally.nextState();
58
- expect(rally.state).toBe(3);
59
- expect(rally.isOver()).toBe(true);
60
- });
61
29
  // getScore Tests
62
30
  test('Should return undefined if events array does not contain a Score', () => {
63
31
  rally.addEvent(serve);
@@ -68,19 +36,4 @@ describe('Rally Test Module', () => {
68
36
  expect(rally.score).not.toBeUndefined();
69
37
  expect(rally.score?.eventType).toBe(EventTypeEnum.SCORE);
70
38
  });
71
- // RallyState Tests
72
- test('Should get next state', () => {
73
- expect(RallyState.nextState(0)).toBe(1);
74
- expect(RallyState.nextState(1)).toBe(2);
75
- });
76
- test('Should throw Error for state outside range', () => {
77
- function fn1() { RallyState.nextState(-1); }
78
- function fn2() { RallyState.nextState(4); }
79
- expect(fn1).toThrow(/^STATE_INDEX_OUT_OF_BOUNDS$/);
80
- expect(fn2).toThrow(/^STATE_INDEX_OUT_OF_BOUNDS$/);
81
- });
82
- test('Should throw Error for last state', () => {
83
- function fn() { RallyState.nextState(3); }
84
- expect(fn).toThrow(/^CANT_GET_STATE_AFTER: FINISHED$/);
85
- });
86
39
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "volleyballsimtypes",
3
- "version": "0.0.99",
3
+ "version": "0.0.100",
4
4
  "description": "vbsim types",
5
5
  "main": "./dist/cjs/src/index.js",
6
6
  "module": "./dist/esm/src/index.js",