# Step 7: Final Testing Checklist
## Refactored Tic-Tac-Toe Game - Hardware Validation

**Date:** January 30, 2026  
**Status:** Compilation successful ✓

---

## Pre-Test Verification

### Build Artifacts
- [x] Compiles without errors
- [x] Compiles without warnings
- [x] basic1.uf2 generated successfully
- [x] All new modules included in build

### Architecture Components
- [x] InputManager class (lib/input_manager.cpp)
- [x] Game base class (lib/game.h)
- [x] TicTacToeGame class (games/tic_tac_toe.cpp)
- [x] Input events (lib/input_event.h)
- [x] Main loop refactored (basic1.cpp)

---

## Hardware Testing Plan

### Test 1: Basic System Startup
**Expected Behavior:**
- USB serial connection establishes
- Debug messages appear:
  - "=== [BOARD_NAME] Demo ==="
  - "Core 1 started - handling display refreshes"
  - "Touch initialized successfully"
  - Initial game board renders

**Validation:**
- [ ] Serial output shows startup messages
- [ ] Both cores start successfully
- [ ] Display shows Tic-Tac-Toe board
- [ ] No system hangs or crashes

---

### Test 2: Touch Input Detection
**Test Steps:**
1. Tap empty cell in top-left corner
2. Tap empty cell in center
3. Tap empty cell in bottom-right corner
4. Tap already occupied cell
5. Tap outside board area

**Expected Behavior:**
- Debug output: "Processing touch: flag=1"
- Debug output: "Touch DOWN at (x,y)"
- X or O appears in tapped cell
- Occupied cells reject new pieces
- Touches outside board are ignored
- Turn indicator updates on left side

**Validation:**
- [ ] Touch interrupts fire correctly
- [ ] Coordinates map to correct cells
- [ ] Pieces appear in touched cells
- [ ] Turn switches between X and O
- [ ] Invalid moves rejected
- [ ] Debug messages show correct coordinates

---

### Test 3: Button Navigation (e-ink boards)
**Test Steps:**
1. Press KEY0 to move selection
2. Press KEY0 multiple times to cycle cells
3. Press KEY1 to place piece in selected cell
4. Verify selection skips occupied cells

**Expected Behavior:**
- KEY0: Selection highlight moves to next cell
- KEY1: Piece placed at highlighted cell
- Selection automatically skips occupied cells
- Debug output: "Selection moved to [row,col]"

**Validation:**
- [ ] KEY0 moves selection correctly
- [ ] KEY1 places piece at selection
- [ ] Selection visual feedback works
- [ ] Button debouncing functions
- [ ] Debug messages show correct events

---

### Test 4: Win Condition Detection
**Test Scenarios:**

#### Row Win (X)
- Tap cells: [0,0], [1,0], [0,1], [1,1], [0,2]
- Expected: "X WINS!" message

#### Column Win (O)
- Tap cells: [0,0], [0,1], [1,0], [0,2], [2,1], [0,3]
- Expected: "O WINS!" message (after X's move)

#### Diagonal Win (X)
- Tap cells: [0,0], [0,1], [1,1], [0,2], [2,2]
- Expected: "X WINS!" message

#### Tie Game
- Fill all cells with no winner
- Expected: "TIE GAME!" message

**Validation:**
- [ ] Row wins detected correctly
- [ ] Column wins detected correctly
- [ ] Diagonal wins detected correctly
- [ ] Tie games detected correctly
- [ ] Game over message displays
- [ ] No further moves accepted after win

---

### Test 5: Game Restart
**Test Steps:**
1. Complete a game (win or tie)
2. Touch screen or press KEY0
3. Verify board clears
4. Verify X starts first
5. Play another game

**Expected Behavior:**
- Board clears to empty state
- X always starts after restart
- Turn indicator resets
- Previous game statistics preserved
- New game begins immediately

**Validation:**
- [ ] Touch restarts game
- [ ] KEY0 restarts game
- [ ] Board completely clears
- [ ] X starts correctly
- [ ] Game flows normally after restart

---

### Test 6: Statistics Tracking
**Test Steps:**
1. Play game where X wins
2. Check statistics: "X:1 O:0 Tie:0"
3. Restart and let O win
4. Check statistics: "X:1 O:1 Tie:0"
5. Play to tie
6. Check statistics: "X:1 O:1 Tie:1"
7. Verify move counter increments

**Expected Behavior:**
- Win counts persist across restarts
- Tie count tracks correctly
- Move counter shows total moves
- Statistics display at bottom

**Validation:**
- [ ] X wins increment correctly
- [ ] O wins increment correctly
- [ ] Ties increment correctly
- [ ] Move counter accurate
- [ ] Stats persist across restarts
- [ ] Display shows current stats

---

### Test 7: Display Refresh (Dual-Core)
**Test Steps:**
1. Make move and observe refresh
2. Make rapid successive moves
3. During e-ink refresh, attempt another move
4. Verify Core 0 stays responsive

**Expected Behavior:**
- Display refreshes after each move
- Core 1 handles refresh asynchronously
- Core 0 processes inputs during refresh
- Pending refresh queues if Core 1 busy
- Debug message: "Refresh pending - Core 1 still busy" (if applicable)

**Validation:**
- [ ] Display updates after moves
- [ ] No screen artifacts
- [ ] System responsive during refresh
- [ ] E-ink refresh completes fully
- [ ] Dual-core architecture working
- [ ] No refresh race conditions

---

### Test 8: Edge Cases & Error Handling
**Test Scenarios:**

#### Rapid Touch Events
- Tap multiple cells rapidly
- Expected: All valid moves registered

#### Touch During Transition
- Touch during display refresh
- Expected: Input queued, processed after refresh

#### Multiple Button Presses
- Press both KEY0 and KEY1 simultaneously
- Expected: One action processed (KEY0 priority)

#### Touch Release Events
- Touch and hold, then release
- Expected: Debug shows "Touch UP"

**Validation:**
- [ ] Rapid touches handled correctly
- [ ] No missed inputs
- [ ] No duplicate moves
- [ ] Touch up events processed
- [ ] System remains stable

---

### Test 9: Memory & Performance
**Observations:**
- Monitor for memory leaks (play 10+ games)
- Check for display artifacts over time
- Verify system doesn't slow down
- Confirm no crashes after extended use

**Validation:**
- [ ] No memory leaks observed
- [ ] Consistent performance over time
- [ ] No progressive slowdown
- [ ] Display quality maintained
- [ ] System stable after 10+ games

---

### Test 10: Code Architecture Validation
**Verification:**
- InputManager handles all input processing
- TicTacToeGame encapsulates game logic
- basic1.cpp only handles hardware/main loop
- Polymorphic Game pointer works correctly
- All extern variables resolve correctly

**Validation:**
- [ ] InputManager processes touch correctly
- [ ] InputManager processes buttons correctly
- [ ] Game class polymorphism works
- [ ] Clean separation of concerns
- [ ] No tight coupling between modules

---

## Success Criteria

### Must Pass (Critical)
1. System boots and initializes
2. Touch input registers moves
3. Win conditions detect correctly
4. Game restarts properly
5. Display refreshes without artifacts

### Should Pass (Important)
1. Button navigation works (if board has buttons)
2. Statistics track accurately
3. Debug output shows correct events
4. Dual-core refresh is non-blocking
5. Edge cases handled gracefully

### Nice to Have (Enhancement)
1. Gesture recognition works
2. No performance degradation over time
3. Clean debug output formatting
4. Smooth user experience

---

## Issue Tracking

### Found Issues
| Issue | Severity | Description | Status |
|-------|----------|-------------|--------|
|       |          |             |        |

### Notes
- 
-
-

---

## Test Results Summary

**Date Tested:** _________________  
**Tester:** _________________  
**Hardware:** _________________  

**Overall Status:** ⬜ PASS / ⬜ FAIL / ⬜ PARTIAL

**Critical Issues:** _________________

**Recommendations:** _________________

---

## Next Steps

If all tests pass:
- ✅ Architecture successfully refactored
- ✅ Ready to add new games (Snake, Pong, etc.)
- ✅ Can implement GameLauncher for game selection

If issues found:
1. Document specific failing test
2. Check relevant module (InputManager, TicTacToeGame, or main loop)
3. Verify hardware connections (touch INT pin, button pins)
4. Review debug serial output for clues
5. Test with minimal configuration first
