This repository was archived by the owner on Jul 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
🧪 Add unit tests for calculateEnergyFactor in RaceEngine #21
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { describe, it, expect } from 'vitest'; | ||
| import { RaceEngine, RaceHorse } from './raceEngine'; | ||
|
|
||
| describe('RaceEngine', () => { | ||
| const mockHorses = [ | ||
| { | ||
| id: '1', | ||
| name: 'Test Horse', | ||
| genetics: { baseSpeed: 50, stamina: 50, agility: 50, temperament: 50, intelligence: 50 } | ||
| } | ||
| ]; | ||
| const mockConfig = { | ||
| distance: 1000, | ||
| conditions: { weather: 'Clear', trackCondition: 'Fast' } | ||
| }; | ||
| const mockCallbacks = { | ||
| onUpdate: () => {}, | ||
| onFinish: () => {} | ||
| }; | ||
|
|
||
| const engine = new RaceEngine(mockHorses, mockConfig, mockCallbacks); | ||
|
|
||
| describe('calculateEnergyFactor', () => { | ||
| it('returns 0.25 when energy is 0 or less', () => { | ||
| const horse = { energy: 0, stamina: 100 } as RaceHorse; | ||
| expect(engine.calculateEnergyFactor(horse)).toBe(0.25); | ||
|
|
||
| const exhaustedHorse = { energy: -10, stamina: 100 } as RaceHorse; | ||
| expect(engine.calculateEnergyFactor(exhaustedHorse)).toBe(0.25); | ||
| }); | ||
|
|
||
| it('returns 1.0 when energy is 100 and stamina is 0', () => { | ||
| const horse = { energy: 100, stamina: 0 } as RaceHorse; | ||
| // baseFactor = Math.pow(100/100, 0.45) = 1 | ||
| // staminaBonus = 0 / 200 = 0 | ||
| // result = 1 * (1 + 0) = 1 | ||
| expect(engine.calculateEnergyFactor(horse)).toBe(1.0); | ||
| }); | ||
|
|
||
| it('returns 1.5 when energy is 100 and stamina is 100', () => { | ||
| const horse = { energy: 100, stamina: 100 } as RaceHorse; | ||
| // baseFactor = 1 | ||
| // staminaBonus = 100 / 200 = 0.5 | ||
| // result = 1 * (1 + 0.5) = 1.5 | ||
| expect(engine.calculateEnergyFactor(horse)).toBe(1.5); | ||
| }); | ||
|
|
||
| it('calculates factor correctly for mid-range values', () => { | ||
| const horse = { energy: 50, stamina: 50 } as RaceHorse; | ||
| const baseFactor = Math.pow(50 / 100, 0.45); | ||
| const staminaBonus = 50 / 200; | ||
| const expected = baseFactor * (1 + staminaBonus); | ||
| expect(engine.calculateEnergyFactor(horse)).toBeCloseTo(expected, 5); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: ereezyy/Sol_Horse
Length of output: 309
🏁 Script executed:
cat -n .github/workflows/ci-cd.yml | head -120Repository: ereezyy/Sol_Horse
Length of output: 3593
Use
npm ciinstead ofnpm installin CI/CD jobs.Since this repo commits
package-lock.json, usingnpm installwill ignore the locked versions and potentially resolve different dependencies than what was tested locally, risking undetected lockfile drift in test, security, staging, and production workflows. Usenpm cito respect the lockfile.This applies to lines 28, 61, 85, and 116.
🤖 Prompt for AI Agents