-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8cf5e0
commit 0ffc088
Showing
8 changed files
with
259 additions
and
97 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
117 changes: 117 additions & 0 deletions
117
src/game/__tests__/dominion-lib-log-calculatePausedTime.spec.ts
This file contains 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,117 @@ | ||
import { calculatePausedTime } from '@/game/dominion-lib-log'; | ||
import { ILogEntry } from '@/game/interfaces/log-entry'; | ||
import { GameLogAction } from '@/game/enumerations/game-log-action'; | ||
import { createMockLog } from '@/__fixtures__/dominion-lib-fixtures'; | ||
|
||
describe('calculatePausedTime', () => { | ||
it('should return 0 if logEntries is empty', () => { | ||
const logEntries: ILogEntry[] = []; | ||
const endTime = new Date(); | ||
expect(calculatePausedTime(logEntries, 0, endTime)).toBe(0); | ||
}); | ||
|
||
it('should return 0 if no pause or save/load actions are present', () => { | ||
const logEntries: ILogEntry[] = [ | ||
createMockLog({ | ||
timestamp: new Date('2023-01-01T00:00:00Z'), | ||
action: GameLogAction.START_GAME, | ||
turn: 1, | ||
}), | ||
createMockLog({ | ||
timestamp: new Date('2023-01-01T01:00:00Z'), | ||
action: GameLogAction.NEXT_TURN, | ||
turn: 2, | ||
}), | ||
]; | ||
const endTime = new Date('2023-01-01T02:00:00Z'); | ||
expect(calculatePausedTime(logEntries, 0, endTime)).toBe(0); | ||
}); | ||
|
||
it('should calculate paused time correctly for pause/unpause actions', () => { | ||
const logEntries: ILogEntry[] = [ | ||
createMockLog({ | ||
timestamp: new Date('2023-01-01T00:00:00Z'), | ||
action: GameLogAction.START_GAME, | ||
turn: 1, | ||
}), | ||
createMockLog({ | ||
timestamp: new Date('2023-01-01T01:00:00Z'), | ||
action: GameLogAction.PAUSE, | ||
turn: 1, | ||
}), | ||
createMockLog({ | ||
timestamp: new Date('2023-01-01T01:30:00Z'), | ||
action: GameLogAction.UNPAUSE, | ||
turn: 1, | ||
}), | ||
]; | ||
const endTime = new Date('2023-01-01T02:00:00Z'); | ||
expect(calculatePausedTime(logEntries, 0, endTime)).toBe(30 * 60 * 1000); // 30 minutes in milliseconds | ||
}); | ||
|
||
it('should calculate paused time correctly for save/load actions', () => { | ||
const logEntries: ILogEntry[] = [ | ||
createMockLog({ | ||
timestamp: new Date('2023-01-01T00:00:00Z'), | ||
action: GameLogAction.START_GAME, | ||
turn: 1, | ||
}), | ||
createMockLog({ | ||
timestamp: new Date('2023-01-01T01:00:00Z'), | ||
action: GameLogAction.SAVE_GAME, | ||
turn: 1, | ||
}), | ||
createMockLog({ | ||
timestamp: new Date('2023-01-01T01:30:00Z'), | ||
action: GameLogAction.LOAD_GAME, | ||
turn: 1, | ||
}), | ||
]; | ||
const endTime = new Date('2023-01-01T02:00:00Z'); | ||
expect(calculatePausedTime(logEntries, 0, endTime)).toBe(30 * 60 * 1000); // 30 minutes in milliseconds | ||
}); | ||
|
||
it('should handle case where end time is during a pause', () => { | ||
const logEntries: ILogEntry[] = [ | ||
createMockLog({ | ||
timestamp: new Date('2023-01-01T00:00:00Z'), | ||
action: GameLogAction.START_GAME, | ||
turn: 1, | ||
}), | ||
createMockLog({ | ||
timestamp: new Date('2023-01-01T01:00:00Z'), | ||
action: GameLogAction.PAUSE, | ||
turn: 1, | ||
}), | ||
]; | ||
const endTime = new Date('2023-01-01T01:30:00Z'); | ||
expect(calculatePausedTime(logEntries, 0, endTime)).toBe(30 * 60 * 1000); // 30 minutes in milliseconds | ||
}); | ||
|
||
it('should handle case where end time is after a pause/unpause cycle', () => { | ||
const logEntries: ILogEntry[] = [ | ||
createMockLog({ | ||
timestamp: new Date('2023-01-01T00:00:00Z'), | ||
action: GameLogAction.START_GAME, | ||
turn: 1, | ||
}), | ||
createMockLog({ | ||
timestamp: new Date('2023-01-01T01:00:00Z'), | ||
action: GameLogAction.PAUSE, | ||
turn: 1, | ||
}), | ||
createMockLog({ | ||
timestamp: new Date('2023-01-01T01:30:00Z'), | ||
action: GameLogAction.UNPAUSE, | ||
turn: 1, | ||
}), | ||
createMockLog({ | ||
timestamp: new Date('2023-01-01T02:00:00Z'), | ||
action: GameLogAction.PAUSE, | ||
turn: 1, | ||
}), | ||
]; | ||
const endTime = new Date('2023-01-01T02:30:00Z'); | ||
expect(calculatePausedTime(logEntries, 0, endTime)).toBe(60 * 60 * 1000); // 1 hour in milliseconds | ||
}); | ||
}); |
1 change: 0 additions & 1 deletion
1
src/game/__tests__/dominion-lib-undo-removeTargetAndLinkedActions.spec.ts
This file contains 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.