|
| 1 | +import { |
| 2 | + avoidSimilarFirstNames, |
| 3 | + mustNotHaveRoles, |
| 4 | + onlyMultipleGroupRounds, |
| 5 | + preferLaterGroups, |
| 6 | + shouldHelpAfterCompeting, |
| 7 | +} from './constraints'; |
| 8 | +import { buildActivity, buildPerson, buildWcif } from '../../store/reducers/_tests_/helpers'; |
| 9 | +import type { Activity } from '@wca/helpers'; |
| 10 | +import { describe, expect, it } from 'vitest'; |
| 11 | + |
| 12 | +const buildGroup = (id: number, groupNumber: number): Activity => |
| 13 | + buildActivity({ |
| 14 | + id, |
| 15 | + name: `Group ${groupNumber}`, |
| 16 | + activityCode: `333-r1-g${groupNumber}`, |
| 17 | + startTime: `2024-01-01T10:0${groupNumber}:00Z`, |
| 18 | + endTime: `2024-01-01T10:1${groupNumber}:00Z`, |
| 19 | + }); |
| 20 | + |
| 21 | +const scoreProps = (activity: Activity, activities: Activity[]) => ({ |
| 22 | + wcif: buildWcif([ |
| 23 | + buildActivity({ |
| 24 | + id: 1, |
| 25 | + activityCode: '333-r1', |
| 26 | + childActivities: activities, |
| 27 | + }), |
| 28 | + ]), |
| 29 | + activities, |
| 30 | + cluster: [], |
| 31 | + assignmentCode: 'competitor', |
| 32 | + person: buildPerson({ |
| 33 | + assignments: [{ activityId: 12, assignmentCode: 'staff-judge', stationNumber: null }], |
| 34 | + }), |
| 35 | + activity, |
| 36 | +}); |
| 37 | + |
| 38 | +describe('recipe constraints', () => { |
| 39 | + it('prefers the group before a staff assignment so staff help after competing', () => { |
| 40 | + const activities = [buildGroup(11, 1), buildGroup(12, 2), buildGroup(13, 3)]; |
| 41 | + |
| 42 | + expect(shouldHelpAfterCompeting.score(scoreProps(activities[0], activities))).toBe(1); |
| 43 | + expect(shouldHelpAfterCompeting.score(scoreProps(activities[2], activities))).toBe(0); |
| 44 | + }); |
| 45 | + |
| 46 | + it('wraps staff competitor assignments from group one staff to the last competing group', () => { |
| 47 | + const activities = [buildGroup(11, 1), buildGroup(12, 2), buildGroup(13, 3)]; |
| 48 | + const props = { |
| 49 | + ...scoreProps(activities[2], activities), |
| 50 | + person: buildPerson({ |
| 51 | + assignments: [{ activityId: 11, assignmentCode: 'staff-judge', stationNumber: null }], |
| 52 | + }), |
| 53 | + }; |
| 54 | + |
| 55 | + expect(shouldHelpAfterCompeting.score(props)).toBe(1); |
| 56 | + }); |
| 57 | + |
| 58 | + it('scores later groups higher', () => { |
| 59 | + const activities = [buildGroup(11, 1), buildGroup(12, 2), buildGroup(13, 3)]; |
| 60 | + |
| 61 | + const earlyScore = preferLaterGroups.score(scoreProps(activities[0], activities)); |
| 62 | + const lateScore = preferLaterGroups.score(scoreProps(activities[2], activities)); |
| 63 | + |
| 64 | + expect(lateScore).toBeGreaterThan(earlyScore ?? 0); |
| 65 | + }); |
| 66 | + |
| 67 | + it('rejects people with blocked roles', () => { |
| 68 | + const activity = buildGroup(11, 1); |
| 69 | + const props = { |
| 70 | + ...scoreProps(activity, [activity]), |
| 71 | + person: buildPerson({ roles: ['organizer'] }), |
| 72 | + options: { roles: ['delegate', 'trainee-delegate', 'organizer'] }, |
| 73 | + }; |
| 74 | + |
| 75 | + expect(mustNotHaveRoles.score(props)).toBeNull(); |
| 76 | + }); |
| 77 | + |
| 78 | + it('rejects judge assignments when only one group exists', () => { |
| 79 | + const activity = buildGroup(11, 1); |
| 80 | + |
| 81 | + expect(onlyMultipleGroupRounds.score(scoreProps(activity, [activity]))).toBeNull(); |
| 82 | + }); |
| 83 | + |
| 84 | + it('penalizes same-sounding first names in the same activity', () => { |
| 85 | + const activity = buildGroup(11, 1); |
| 86 | + const props = { |
| 87 | + ...scoreProps(activity, [activity]), |
| 88 | + wcif: buildWcif([], [ |
| 89 | + buildPerson({ |
| 90 | + name: 'John Smith', |
| 91 | + assignments: [{ activityId: 11, assignmentCode: 'competitor', stationNumber: null }], |
| 92 | + }), |
| 93 | + ]), |
| 94 | + person: buildPerson({ name: 'Jon Jones' }), |
| 95 | + }; |
| 96 | + |
| 97 | + expect(avoidSimilarFirstNames.score(props)).toBeLessThan(0); |
| 98 | + }); |
| 99 | +}); |
0 commit comments