fix: 修复悔棋奇数步崩溃及空历史错误语义 (NoHistory)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-31 13:38:04 +08:00
parent 8c3289e631
commit cd9c3a79ab
3 changed files with 14 additions and 4 deletions
+8 -3
View File
@@ -99,7 +99,7 @@ impl Board {
/// 悔棋 — 撤销最近一步
pub fn undo(&self) -> Result<Board, MoveError> {
if self.history.is_empty() {
return Err(MoveError::GameOver);
return Err(MoveError::NoHistory);
}
let mut new_board = self.clone();
let last_move = new_board.history.pop().unwrap();
@@ -253,9 +253,14 @@ mod tests {
}
#[test]
fn test_undo_empty_history() {
fn test_undo_empty_history_returns_no_history_error() {
let board = Board::new(15);
assert_eq!(board.undo(), Err(MoveError::GameOver));
let result = board.undo();
assert!(result.is_err());
match result {
Err(MoveError::NoHistory) => {},
other => panic!("expected NoHistory, got {:?}", other),
}
}
#[test]