volleyballsimtypes 0.0.480 → 0.0.481

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,6 +41,11 @@ class Standing {
41
41
  // effective ratio here that treats "won with nothing lost" as +Infinity, ranking it highest.
42
42
  const effectiveRatio = (won, lost) => lost > 0 ? won / lost : (won > 0 ? Infinity : 0);
43
43
  return (standingA, standingB) => {
44
+ // VNL/FIVB order: matches WON is the first criterion, then match points, then set ratio, point ratio, h2h.
45
+ if (standingB.matchesWon > standingA.matchesWon)
46
+ return 1;
47
+ if (standingA.matchesWon > standingB.matchesWon)
48
+ return -1;
44
49
  if (standingB.points > standingA.points)
45
50
  return 1;
46
51
  if (standingA.points > standingB.points)
@@ -115,23 +115,34 @@ function makeStanding(teamId, opts = {}) {
115
115
  });
116
116
  // ─── sortFn ──────────────────────────────────────────────────────────────────
117
117
  (0, globals_1.describe)('sortFn()', () => {
118
- (0, globals_1.it)('sorts by points descending', () => {
118
+ (0, globals_1.it)('ranks by matches won ahead of points (VNL first criterion)', () => {
119
119
  const idA = (0, uuid_1.v4)();
120
120
  const idB = (0, uuid_1.v4)();
121
- // A has 3 points (1 win 3-0), B has 0 points
121
+ // A: won32=2 2 wins, 4 points. B: won30=1 + lost23=2 1 win, 5 points.
122
+ // Wins is the first criterion, so A ranks above B even though B has more points.
123
+ const a = makeStanding(idA, { won32: 2 });
124
+ const b = makeStanding(idB, { won30: 1, lost23: 2 });
125
+ const sorted = [b, a].sort(standing_1.Standing.sortFn([]));
126
+ (0, globals_1.expect)(sorted[0].teamId).toBe(idA);
127
+ (0, globals_1.expect)(sorted[1].teamId).toBe(idB);
128
+ });
129
+ (0, globals_1.it)('breaks ties by points when wins are equal', () => {
130
+ const idA = (0, uuid_1.v4)();
131
+ const idB = (0, uuid_1.v4)();
132
+ // Both 1 win. A: won30=1 → 3 points. B: won32=1 → 2 points. Points decides once wins tie.
122
133
  const a = makeStanding(idA, { won30: 1 });
123
- const b = makeStanding(idB);
134
+ const b = makeStanding(idB, { won32: 1 });
124
135
  const sorted = [b, a].sort(standing_1.Standing.sortFn([]));
125
136
  (0, globals_1.expect)(sorted[0].teamId).toBe(idA);
126
137
  (0, globals_1.expect)(sorted[1].teamId).toBe(idB);
127
138
  });
128
- (0, globals_1.it)('breaks ties by setsRatio when points are equal', () => {
139
+ (0, globals_1.it)('breaks ties by setsRatio when wins and points are equal', () => {
129
140
  const idA = (0, uuid_1.v4)();
130
141
  const idB = (0, uuid_1.v4)();
131
- // Both 4 points, but A has better setsRatio:
132
- // A: won32=2points=4, setsWon=6, setsLost=4, setsRatio=1.5
133
- // B: won31=1, lost23=1 → points=(1*3)+(1)=4, setsWon=5, setsLost=4, setsRatio=1.25
134
- const a = makeStanding(idA, { won32: 2 });
142
+ // Both 1 win and 4 points, but A has the better setsRatio:
143
+ // A: won30=1, lost23=1 → setsWon=5, setsLost=3, setsRatio1.67
144
+ // B: won31=1, lost23=1 → setsWon=5, setsLost=4, setsRatio=1.25
145
+ const a = makeStanding(idA, { won30: 1, lost23: 1 });
135
146
  const b = makeStanding(idB, { won31: 1, lost23: 1 });
136
147
  const sorted = [b, a].sort(standing_1.Standing.sortFn([]));
137
148
  (0, globals_1.expect)(sorted[0].teamId).toBe(idA);
@@ -38,6 +38,11 @@ export class Standing {
38
38
  // effective ratio here that treats "won with nothing lost" as +Infinity, ranking it highest.
39
39
  const effectiveRatio = (won, lost) => lost > 0 ? won / lost : (won > 0 ? Infinity : 0);
40
40
  return (standingA, standingB) => {
41
+ // VNL/FIVB order: matches WON is the first criterion, then match points, then set ratio, point ratio, h2h.
42
+ if (standingB.matchesWon > standingA.matchesWon)
43
+ return 1;
44
+ if (standingA.matchesWon > standingB.matchesWon)
45
+ return -1;
41
46
  if (standingB.points > standingA.points)
42
47
  return 1;
43
48
  if (standingA.points > standingB.points)
@@ -113,23 +113,34 @@ describe('Standing', () => {
113
113
  });
114
114
  // ─── sortFn ──────────────────────────────────────────────────────────────────
115
115
  describe('sortFn()', () => {
116
- it('sorts by points descending', () => {
116
+ it('ranks by matches won ahead of points (VNL first criterion)', () => {
117
117
  const idA = uuidv4();
118
118
  const idB = uuidv4();
119
- // A has 3 points (1 win 3-0), B has 0 points
119
+ // A: won32=2 2 wins, 4 points. B: won30=1 + lost23=2 1 win, 5 points.
120
+ // Wins is the first criterion, so A ranks above B even though B has more points.
121
+ const a = makeStanding(idA, { won32: 2 });
122
+ const b = makeStanding(idB, { won30: 1, lost23: 2 });
123
+ const sorted = [b, a].sort(Standing.sortFn([]));
124
+ expect(sorted[0].teamId).toBe(idA);
125
+ expect(sorted[1].teamId).toBe(idB);
126
+ });
127
+ it('breaks ties by points when wins are equal', () => {
128
+ const idA = uuidv4();
129
+ const idB = uuidv4();
130
+ // Both 1 win. A: won30=1 → 3 points. B: won32=1 → 2 points. Points decides once wins tie.
120
131
  const a = makeStanding(idA, { won30: 1 });
121
- const b = makeStanding(idB);
132
+ const b = makeStanding(idB, { won32: 1 });
122
133
  const sorted = [b, a].sort(Standing.sortFn([]));
123
134
  expect(sorted[0].teamId).toBe(idA);
124
135
  expect(sorted[1].teamId).toBe(idB);
125
136
  });
126
- it('breaks ties by setsRatio when points are equal', () => {
137
+ it('breaks ties by setsRatio when wins and points are equal', () => {
127
138
  const idA = uuidv4();
128
139
  const idB = uuidv4();
129
- // Both 4 points, but A has better setsRatio:
130
- // A: won32=2points=4, setsWon=6, setsLost=4, setsRatio=1.5
131
- // B: won31=1, lost23=1 → points=(1*3)+(1)=4, setsWon=5, setsLost=4, setsRatio=1.25
132
- const a = makeStanding(idA, { won32: 2 });
140
+ // Both 1 win and 4 points, but A has the better setsRatio:
141
+ // A: won30=1, lost23=1 → setsWon=5, setsLost=3, setsRatio1.67
142
+ // B: won31=1, lost23=1 → setsWon=5, setsLost=4, setsRatio=1.25
143
+ const a = makeStanding(idA, { won30: 1, lost23: 1 });
133
144
  const b = makeStanding(idB, { won31: 1, lost23: 1 });
134
145
  const sorted = [b, a].sort(Standing.sortFn([]));
135
146
  expect(sorted[0].teamId).toBe(idA);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "volleyballsimtypes",
3
- "version": "0.0.480",
3
+ "version": "0.0.481",
4
4
  "description": "vbsim types",
5
5
  "main": "./dist/cjs/src/index.js",
6
6
  "module": "./dist/esm/src/index.js",