From 19c6c6701a6556845b8016e7bcff166a76d971b3 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Tue, 27 May 2025 12:04:24 -0700 Subject: [PATCH] [position] Fix broken tests build The make_move tests were trying to access the last capture piece directly from a slice of captures pieces (implementation prior to CapturesList). Implement CapturesList::last() to return an Option<&Piece> and use it in the tests. --- position/src/position/captures.rs | 5 +++++ position/src/position/make_move.rs | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/position/src/position/captures.rs b/position/src/position/captures.rs index d6ce3e2..ddd9dac 100644 --- a/position/src/position/captures.rs +++ b/position/src/position/captures.rs @@ -8,6 +8,11 @@ use chessfriend_core::{Color, Piece}; pub(crate) struct CapturesList([Vec; Color::NUM]); impl CapturesList { + #[cfg(test)] + pub fn last(&self, color: Color) -> Option<&Piece> { + self.0[color as usize].last() + } + pub fn push(&mut self, color: Color, piece: Piece) { self.0[color as usize].push(piece); } diff --git a/position/src/position/make_move.rs b/position/src/position/make_move.rs index 6be4814..13c0d6a 100644 --- a/position/src/position/make_move.rs +++ b/position/src/position/make_move.rs @@ -407,7 +407,7 @@ mod tests { assert_eq!(pos.get_piece(Square::C2), None); assert_eq!(pos.get_piece(Square::F5), Some(piece!(White Bishop))); - assert_eq!(pos.captures[Color::White as usize][0], piece!(Black Rook)); + assert_eq!(pos.captures.last(Color::White), Some(&piece!(Black Rook))); assert_eq!(pos.board.active_color, Color::Black); assert_eq!(pos.board.half_move_clock, 0); @@ -444,7 +444,7 @@ mod tests { None, "capture target pawn not removed" ); - assert_eq!(pos.captures[Color::Black as usize][0], piece!(White Pawn)); + assert_eq!(pos.captures.last(Color::Black), Some(&piece!(White Pawn))); Ok(()) }