From 279e9e9d3591709ece18b9426f22d03ecfcfd11c Mon Sep 17 00:00:00 2001 From: YoEnte Date: Sun, 19 Jan 2025 00:51:10 +0100 Subject: [PATCH 1/5] fix: eat salad card usable without salads --- src/plugin/action/card.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/plugin/action/card.rs b/src/plugin/action/card.rs index 2cd24bb..0000573 100644 --- a/src/plugin/action/card.rs +++ b/src/plugin/action/card.rs @@ -79,7 +79,15 @@ impl Card { // saturating add is here unnecessary because the board is finite and never larger than usize::MAX self.move_to_field(current, state, other.position + 1, remaining_cards)?; } - Card::EatSalad => current.eat_salad(state)?, + Card::EatSalad => { + if current.salads == 0 { + return Err(HUIError::new_err( + "You can only play this card if you have lettuce left", + )); + } + + current.eat_salad(state)? + } Card::SwapCarrots => { if current.position >= PluginConstants::LAST_LETTUCE_POSITION || other.position >= PluginConstants::LAST_LETTUCE_POSITION From 36aa84ba86748199dbb75b48c56a53dfcb97b5dc Mon Sep 17 00:00:00 2001 From: YoEnte Date: Sun, 19 Jan 2025 00:52:58 +0100 Subject: [PATCH 2/5] add: test for fix --- src/plugin/test/card_test.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/plugin/test/card_test.rs b/src/plugin/test/card_test.rs index e13e6bb..69291ba 100644 --- a/src/plugin/test/card_test.rs +++ b/src/plugin/test/card_test.rs @@ -131,12 +131,10 @@ mod tests { #[test] fn test_play_card_not_on_hare_field() { let mut state = create_test_game_state(); - let card = Card::FallBack; + let _card = Card::FallBack; let mut current_player = state.clone_current_player(); current_player.position = 1; state.update_player(current_player); - let result = card.perform(&mut state, vec![Card::EatSalad, Card::SwapCarrots]); - assert!(result.is_err()); } #[test] @@ -147,4 +145,16 @@ mod tests { let result = invalid_card.perform(&mut state, vec![Card::EatSalad, Card::SwapCarrots]); assert!(result.is_err()); } + + #[test] + fn test_no_salad_but_salad_card() { + let mut state = create_test_game_state(); + let card = Card::EatSalad; + let mut current_player = state.clone_current_player(); + current_player.salads = 0; + current_player.cards = vec![card]; + state.update_player(current_player); + let result = card.perform(&mut state, vec![]); + assert!(result.is_err()); + } } From e9e45343c77cef35c9b9a9abbee09e6e870efffc Mon Sep 17 00:00:00 2001 From: YoEnte Date: Sun, 19 Jan 2025 01:14:52 +0100 Subject: [PATCH 3/5] add: a modified logic for testing --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 311c305..e6bee8f 100644 --- a/.gitignore +++ b/.gitignore @@ -71,4 +71,7 @@ docs/_build/ .vscode/ # Pyenv -.python-version \ No newline at end of file +.python-version + +# logic test +logic_test.py \ No newline at end of file From 124c602fecedc47c7c4f3d06780ffdbcbf64d133 Mon Sep 17 00:00:00 2001 From: YoEnte Date: Mon, 20 Jan 2025 10:41:30 +0100 Subject: [PATCH 4/5] fix: broken test --- src/plugin/test/card_test.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugin/test/card_test.rs b/src/plugin/test/card_test.rs index 69291ba..fbd6d06 100644 --- a/src/plugin/test/card_test.rs +++ b/src/plugin/test/card_test.rs @@ -131,10 +131,12 @@ mod tests { #[test] fn test_play_card_not_on_hare_field() { let mut state = create_test_game_state(); - let _card = Card::FallBack; + let card = Card::FallBack; let mut current_player = state.clone_current_player(); current_player.position = 1; state.update_player(current_player); + let result = card.perform(&mut state, vec![Card::EatSalad, Card::SwapCarrots]); + assert!(result.is_err()); } #[test] From 3f900a13fb3b783f91d071528934fc29d5021df1 Mon Sep 17 00:00:00 2001 From: YoEnte Date: Mon, 20 Jan 2025 10:48:31 +0100 Subject: [PATCH 5/5] remove: the modifed the test logic --- .gitignore | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index e6bee8f..311c305 100644 --- a/.gitignore +++ b/.gitignore @@ -71,7 +71,4 @@ docs/_build/ .vscode/ # Pyenv -.python-version - -# logic test -logic_test.py \ No newline at end of file +.python-version \ No newline at end of file