Skip to content

Commit d426948

Browse files
Clean up test code types and formatting
Co-authored-by: kevinjosethomas <46242684+kevinjosethomas@users.noreply.github.com>
1 parent ab8f79c commit d426948

1 file changed

Lines changed: 48 additions & 20 deletions

File tree

__tests__/hooks/useOpeningDrillController-evaluation.test.ts

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,24 @@ describe('useOpeningDrillController evaluation chart generation', () => {
1212
startingNode: GameNode,
1313
playerColor: 'white' | 'black',
1414
) => {
15-
const moveAnalyses: any[] = []
16-
const evaluationChart: any[] = []
17-
18-
const extractNodeAnalysis = (node: GameNode, path: GameNode[] = []): void => {
15+
const moveAnalyses: Array<{
16+
move: string
17+
san: string
18+
fen: string
19+
isPlayerMove: boolean
20+
evaluation: number
21+
moveNumber: number
22+
}> = []
23+
const evaluationChart: Array<{
24+
moveNumber: number
25+
evaluation: number
26+
isPlayerMove: boolean
27+
}> = []
28+
29+
const extractNodeAnalysis = (
30+
node: GameNode,
31+
path: GameNode[] = [],
32+
): void => {
1933
const currentPath = [...path, node]
2034

2135
if (node.move && node.san) {
@@ -59,39 +73,46 @@ describe('useOpeningDrillController evaluation chart generation', () => {
5973
// Create a game tree representing: 1. e4 e5 2. Nf3 Nc6 (opening) 3. Bb5 a6 (drill moves)
6074
const chess = new Chess()
6175
const gameTree = new GameTree(chess.fen())
62-
76+
6377
// Add opening moves (these should NOT be included in evaluation chart)
6478
chess.move('e4')
65-
const e4Node = gameTree.addMainMove(gameTree.getRoot(), chess.fen(), 'e2e4', 'e4')!
66-
79+
const e4Node = gameTree.addMainMove(
80+
gameTree.getRoot(),
81+
chess.fen(),
82+
'e2e4',
83+
'e4',
84+
)!
85+
6786
chess.move('e5')
6887
const e5Node = gameTree.addMainMove(e4Node, chess.fen(), 'e7e5', 'e5')!
69-
88+
7089
chess.move('Nf3')
7190
const nf3Node = gameTree.addMainMove(e5Node, chess.fen(), 'g1f3', 'Nf3')!
72-
91+
7392
chess.move('Nc6')
7493
const nc6Node = gameTree.addMainMove(nf3Node, chess.fen(), 'b8c6', 'Nc6')! // This is the opening end
75-
94+
7695
// Add drill moves (these SHOULD be included in evaluation chart)
7796
chess.move('Bb5')
7897
const bb5Node = gameTree.addMainMove(nc6Node, chess.fen(), 'f1b5', 'Bb5')!
79-
98+
8099
chess.move('a6')
81100
const a6Node = gameTree.addMainMove(bb5Node, chess.fen(), 'a7a6', 'a6')!
82101

83102
// Test starting from game root (old behavior - should include all moves)
84-
const { moveAnalyses: rootAnalyses, evaluationChart: rootChart } =
103+
const { moveAnalyses: rootAnalyses, evaluationChart: rootChart } =
85104
extractNodeAnalysisFromPosition(gameTree.getRoot(), 'white')
86105

87106
// Test starting from opening end (new behavior - should only include drill moves)
88-
const { moveAnalyses: openingEndAnalyses, evaluationChart: openingEndChart } =
89-
extractNodeAnalysisFromPosition(nc6Node, 'white')
107+
const {
108+
moveAnalyses: openingEndAnalyses,
109+
evaluationChart: openingEndChart,
110+
} = extractNodeAnalysisFromPosition(nc6Node, 'white')
90111

91112
// Verify that starting from root includes all moves (including opening)
92113
expect(rootAnalyses).toHaveLength(6) // e4, e5, Nf3, Nc6, Bb5, a6
93114
expect(rootChart).toHaveLength(6)
94-
115+
95116
// Verify that starting from opening end only includes post-opening moves
96117
// Note: This includes the last opening move (Nc6) which provides context for the evaluation chart
97118
expect(openingEndAnalyses).toHaveLength(3) // Nc6 (last opening move), Bb5, a6
@@ -112,18 +133,25 @@ describe('useOpeningDrillController evaluation chart generation', () => {
112133
it('should handle the case where opening end node is null', () => {
113134
const chess = new Chess()
114135
const gameTree = new GameTree(chess.fen())
115-
136+
116137
// Add some moves
117138
chess.move('e4')
118-
const e4Node = gameTree.addMainMove(gameTree.getRoot(), chess.fen(), 'e2e4', 'e4')!
139+
const e4Node = gameTree.addMainMove(
140+
gameTree.getRoot(),
141+
chess.fen(),
142+
'e2e4',
143+
'e4',
144+
)!
119145

120146
// Test with null opening end node (should fallback to root)
121147
const startingNode = null || gameTree.getRoot() // Simulates the fallback logic
122-
const { moveAnalyses, evaluationChart } =
123-
extractNodeAnalysisFromPosition(startingNode, 'white')
148+
const { moveAnalyses, evaluationChart } = extractNodeAnalysisFromPosition(
149+
startingNode,
150+
'white',
151+
)
124152

125153
expect(moveAnalyses).toHaveLength(1)
126154
expect(evaluationChart).toHaveLength(1)
127155
expect(moveAnalyses[0].san).toBe('e4')
128156
})
129-
})
157+
})

0 commit comments

Comments
 (0)