From fc59ef77cda14d97d854dfcaa848307cfa512b69 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 28 Oct 2026 23:13:24 +0100 Subject: v1.0.0: replace slots with 5x3 reels and five paylines --- tests/client_core.rs | 106 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 86 insertions(+), 20 deletions(-) (limited to 'tests/client_core.rs') diff --git a/tests/client_core.rs b/tests/client_core.rs index c298ab7..80ec587 100644 --- a/tests/client_core.rs +++ b/tests/client_core.rs @@ -5,8 +5,13 @@ //! player would see, not about ANSI sequences. use zagan_bet::client::core::{ClientCore, Effect, InteractiveCommand, Key}; +use zagan_bet::client::games::response::parse_spin_response; use zagan_bet::client::ui::command_names; +const WIN3: &str = "CCCCLLCLODGSDGS"; +const LOSS: &str = "CLOOGDSLCDCOGLS"; +const ALL_C: &str = "CCCCCCCCCCCCCCC"; + #[derive(Default)] struct Screen { lines: Vec, @@ -123,16 +128,17 @@ impl Harness { } #[test] -fn play_shows_a_seven_line_board_and_fetches_the_balance() { +fn play_shows_a_nine_line_board_and_fetches_the_balance() { let mut h = Harness::new(); h.line("play slots 50"); - assert_eq!(h.board().len(), 7); + assert_eq!(h.board().len(), 9); assert!(h.board()[1].contains("Bet: 50 PLN")); + assert!(h.board()[1].contains("Lines: 5")); assert!(h.sent.contains(&"INFO".to_string())); h.reply("INFO alice 1 1000"); - assert_eq!(h.board().len(), 7); + assert_eq!(h.board().len(), 9); assert!(h.board()[1].contains("Balance: 1000 PLN")); } @@ -143,18 +149,22 @@ fn spin_replaces_the_board_and_keeps_the_controls_line() { let lines_before_spin = h.screen.lines.len(); h.key(Key::Char(' ')); - assert_eq!(h.board().len(), 7); - assert!(h.board()[4].contains("Spinning...")); - assert!(h.board()[6].contains("[Q] Quit")); + assert_eq!(h.board().len(), 9); + assert!(h.board()[6].contains("Spinning...")); + assert!(h.board()[8].contains("[Q] Quit")); assert!(h.sent.iter().any(|line| line == "PLAY_START slots 50")); assert_eq!(h.screen.lines.len(), lines_before_spin); - h.reply("GAME_RESULT session-1 60 50 1010 OSS two"); - assert_eq!(h.board().len(), 7); - assert!(h.board()[2].contains("[ O ] [ S ] [ S ]")); - assert!(h.board()[4].contains("Two of a kind! Winnings: 60 PLN")); - assert!(h.board()[1].contains("Balance: 1010 PLN")); - assert!(h.board()[6].contains("[Q] Quit")); + h.reply("GAME_RESULT session-1 100 50 1050 CCCCLLCLODGSDGS win 1"); + assert_eq!(h.board().len(), 9); + assert!(h + .board() + .get(2) + .is_some_and(|line| line.contains("[ C ] [ C ] [ C ] [ D ] [ D ]"))); + assert!(h.board()[6].contains("Won 100 PLN")); + assert!(h.board()[7].contains("Winning lines: 1")); + assert!(h.board()[1].contains("Balance: 1050 PLN")); + assert!(h.board()[8].contains("[Q] Quit")); assert_eq!(h.screen.lines.len(), lines_before_spin); } @@ -163,14 +173,17 @@ fn changing_the_bet_after_a_spin_does_not_leave_stale_lines() { let mut h = Harness::new(); h.enter_slots("50"); h.key(Key::Char(' ')); - h.reply("GAME_RESULT session-1 60 50 1010 OSS two"); + h.reply("GAME_RESULT session-1 100 50 1050 CCCCLLCLODGSDGS win 1"); let lines_before_bet = h.screen.lines.len(); h.key(Key::Char('+')); - assert_eq!(h.board().len(), 7); + assert_eq!(h.board().len(), 9); assert!(h.board()[1].contains("Bet: 60 PLN")); - assert!(h.board()[2].contains("[ O ] [ S ] [ S ]")); + assert!(h + .board() + .get(2) + .is_some_and(|line| line.contains("[ C ] [ C ] [ C ] [ D ] [ D ]"))); assert_eq!(h.screen.lines.len(), lines_before_bet); assert_eq!( h.screen @@ -182,6 +195,32 @@ fn changing_the_bet_after_a_spin_does_not_leave_stale_lines() { ); } +#[test] +fn a_losing_spin_shows_no_win_and_no_winning_lines() { + let mut h = Harness::new(); + h.enter_slots("10"); + h.key(Key::Char(' ')); + + h.reply(&format!("GAME_RESULT session-1 0 10 990 {LOSS} none -")); + + assert_eq!(h.board().len(), 9); + assert!(h.board()[6].contains("No win.")); + assert_eq!(h.board()[7], ""); +} + +#[test] +fn a_mega_win_shows_all_winning_lines() { + let mut h = Harness::new(); + h.enter_slots("10"); + h.key(Key::Char(' ')); + + h.reply(&format!("GAME_RESULT session-1 750 10 1740 {ALL_C} mega 1,2,3,4,5")); + + assert_eq!(h.board().len(), 9); + assert!(h.board()[6].contains("MEGA WIN! 750 PLN")); + assert!(h.board()[7].contains("Winning lines: 1,2,3,4,5")); +} + #[test] fn quitting_clears_the_board_and_returns_the_prompt() { let mut h = Harness::new(); @@ -202,8 +241,8 @@ fn a_server_error_replaces_the_status_line() { h.reply("ERROR Insufficient balance"); - assert_eq!(h.board().len(), 7); - assert!(h.board()[4].contains("ERROR: Insufficient balance")); + assert_eq!(h.board().len(), 9); + assert!(h.board()[6].contains("ERROR: Insufficient balance")); assert!(h.board()[2].contains("[ ? ]")); assert!(!h.board().iter().any(|line| line.contains("Spinning"))); } @@ -216,8 +255,8 @@ fn an_empty_reply_is_an_error_not_a_silent_spin() { h.reply(""); - assert_eq!(h.board().len(), 7); - assert!(h.board()[4].contains("No response from server")); + assert_eq!(h.board().len(), 9); + assert!(h.board()[6].contains("No response from server")); } #[test] @@ -301,7 +340,7 @@ fn play_without_a_bet_uses_the_default() { let mut h = Harness::new(); h.line("play slots"); - assert_eq!(h.board().len(), 7); + assert_eq!(h.board().len(), 9); assert!(h.board()[1].contains("Bet: 10 PLN")); } @@ -475,3 +514,30 @@ fn disconnect_clears_connection_state() { .iter() .any(|line| line.contains("Not connected"))); } + +#[test] +fn parses_a_five_by_three_result_with_winning_lines() { + let response = format!("GAME_RESULT session-1 100 50 1050 {WIN3} win 1"); + let result = parse_spin_response(&response).expect("valid 5x3 result"); + + assert_eq!(result.reels.chars().count(), 15); + assert_eq!(result.win_type, "win"); + assert_eq!(result.win_lines, vec![1]); +} + +#[test] +fn accepts_a_legacy_three_symbol_result() { + let result = parse_spin_response("GAME_RESULT session-1 60 10 1050 OSS two") + .expect("legacy result should still parse"); + + assert_eq!(result.reels, "OSS"); + assert_eq!(result.win_type, "two"); + assert!(result.win_lines.is_empty()); +} + +#[test] +fn rejects_a_grid_with_the_wrong_size() { + let response = "GAME_RESULT session-1 100 50 1050 CCCCCCCCCCCCCC win 1"; + + assert!(parse_spin_response(response).is_err()); +} -- cgit v1.2.3