diff options
| author | salmonik <salmonik@tuta.io> | 2026-10-28 23:13:24 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-10-28 23:13:24 +0100 |
| commit | fc59ef77cda14d97d854dfcaa848307cfa512b69 (patch) | |
| tree | b0fc97390b96078e0a0538e76d7c76f7c04135f1 /tests/client_core.rs | |
| parent | v0.4.0: add first-time TLS setup and server help (diff) | |
| download | zagan-bet-fc59ef77cda14d97d854dfcaa848307cfa512b69.tar.gz zagan-bet-fc59ef77cda14d97d854dfcaa848307cfa512b69.zip | |
v1.0.0: replace slots with 5x3 reels and five paylines
Diffstat (limited to '')
| -rw-r--r-- | tests/client_core.rs | 106 |
1 files changed, 86 insertions, 20 deletions
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 @@ | |||
| 5 | //! player would see, not about ANSI sequences. | 5 | //! player would see, not about ANSI sequences. |
| 6 | 6 | ||
| 7 | use zagan_bet::client::core::{ClientCore, Effect, InteractiveCommand, Key}; | 7 | use zagan_bet::client::core::{ClientCore, Effect, InteractiveCommand, Key}; |
| 8 | use zagan_bet::client::games::response::parse_spin_response; | ||
| 8 | use zagan_bet::client::ui::command_names; | 9 | use zagan_bet::client::ui::command_names; |
| 9 | 10 | ||
| 11 | const WIN3: &str = "CCCCLLCLODGSDGS"; | ||
| 12 | const LOSS: &str = "CLOOGDSLCDCOGLS"; | ||
| 13 | const ALL_C: &str = "CCCCCCCCCCCCCCC"; | ||
| 14 | |||
| 10 | #[derive(Default)] | 15 | #[derive(Default)] |
| 11 | struct Screen { | 16 | struct Screen { |
| 12 | lines: Vec<String>, | 17 | lines: Vec<String>, |
| @@ -123,16 +128,17 @@ impl Harness { | |||
| 123 | } | 128 | } |
| 124 | 129 | ||
| 125 | #[test] | 130 | #[test] |
| 126 | fn play_shows_a_seven_line_board_and_fetches_the_balance() { | 131 | fn play_shows_a_nine_line_board_and_fetches_the_balance() { |
| 127 | let mut h = Harness::new(); | 132 | let mut h = Harness::new(); |
| 128 | h.line("play slots 50"); | 133 | h.line("play slots 50"); |
| 129 | 134 | ||
| 130 | assert_eq!(h.board().len(), 7); | 135 | assert_eq!(h.board().len(), 9); |
| 131 | assert!(h.board()[1].contains("Bet: 50 PLN")); | 136 | assert!(h.board()[1].contains("Bet: 50 PLN")); |
| 137 | assert!(h.board()[1].contains("Lines: 5")); | ||
| 132 | assert!(h.sent.contains(&"INFO".to_string())); | 138 | assert!(h.sent.contains(&"INFO".to_string())); |
| 133 | 139 | ||
| 134 | h.reply("INFO alice 1 1000"); | 140 | h.reply("INFO alice 1 1000"); |
| 135 | assert_eq!(h.board().len(), 7); | 141 | assert_eq!(h.board().len(), 9); |
| 136 | assert!(h.board()[1].contains("Balance: 1000 PLN")); | 142 | assert!(h.board()[1].contains("Balance: 1000 PLN")); |
| 137 | } | 143 | } |
| 138 | 144 | ||
| @@ -143,18 +149,22 @@ fn spin_replaces_the_board_and_keeps_the_controls_line() { | |||
| 143 | let lines_before_spin = h.screen.lines.len(); | 149 | let lines_before_spin = h.screen.lines.len(); |
| 144 | 150 | ||
| 145 | h.key(Key::Char(' ')); | 151 | h.key(Key::Char(' ')); |
| 146 | assert_eq!(h.board().len(), 7); | 152 | assert_eq!(h.board().len(), 9); |
| 147 | assert!(h.board()[4].contains("Spinning...")); | 153 | assert!(h.board()[6].contains("Spinning...")); |
| 148 | assert!(h.board()[6].contains("[Q] Quit")); | 154 | assert!(h.board()[8].contains("[Q] Quit")); |
| 149 | assert!(h.sent.iter().any(|line| line == "PLAY_START slots 50")); | 155 | assert!(h.sent.iter().any(|line| line == "PLAY_START slots 50")); |
| 150 | assert_eq!(h.screen.lines.len(), lines_before_spin); | 156 | assert_eq!(h.screen.lines.len(), lines_before_spin); |
| 151 | 157 | ||
| 152 | h.reply("GAME_RESULT session-1 60 50 1010 OSS two"); | 158 | h.reply("GAME_RESULT session-1 100 50 1050 CCCCLLCLODGSDGS win 1"); |
| 153 | assert_eq!(h.board().len(), 7); | 159 | assert_eq!(h.board().len(), 9); |
| 154 | assert!(h.board()[2].contains("[ O ] [ S ] [ S ]")); | 160 | assert!(h |
| 155 | assert!(h.board()[4].contains("Two of a kind! Winnings: 60 PLN")); | 161 | .board() |
| 156 | assert!(h.board()[1].contains("Balance: 1010 PLN")); | 162 | .get(2) |
| 157 | assert!(h.board()[6].contains("[Q] Quit")); | 163 | .is_some_and(|line| line.contains("[ C ] [ C ] [ C ] [ D ] [ D ]"))); |
| 164 | assert!(h.board()[6].contains("Won 100 PLN")); | ||
| 165 | assert!(h.board()[7].contains("Winning lines: 1")); | ||
| 166 | assert!(h.board()[1].contains("Balance: 1050 PLN")); | ||
| 167 | assert!(h.board()[8].contains("[Q] Quit")); | ||
| 158 | assert_eq!(h.screen.lines.len(), lines_before_spin); | 168 | assert_eq!(h.screen.lines.len(), lines_before_spin); |
| 159 | } | 169 | } |
| 160 | 170 | ||
| @@ -163,14 +173,17 @@ fn changing_the_bet_after_a_spin_does_not_leave_stale_lines() { | |||
| 163 | let mut h = Harness::new(); | 173 | let mut h = Harness::new(); |
| 164 | h.enter_slots("50"); | 174 | h.enter_slots("50"); |
| 165 | h.key(Key::Char(' ')); | 175 | h.key(Key::Char(' ')); |
| 166 | h.reply("GAME_RESULT session-1 60 50 1010 OSS two"); | 176 | h.reply("GAME_RESULT session-1 100 50 1050 CCCCLLCLODGSDGS win 1"); |
| 167 | let lines_before_bet = h.screen.lines.len(); | 177 | let lines_before_bet = h.screen.lines.len(); |
| 168 | 178 | ||
| 169 | h.key(Key::Char('+')); | 179 | h.key(Key::Char('+')); |
| 170 | 180 | ||
| 171 | assert_eq!(h.board().len(), 7); | 181 | assert_eq!(h.board().len(), 9); |
| 172 | assert!(h.board()[1].contains("Bet: 60 PLN")); | 182 | assert!(h.board()[1].contains("Bet: 60 PLN")); |
| 173 | assert!(h.board()[2].contains("[ O ] [ S ] [ S ]")); | 183 | assert!(h |
| 184 | .board() | ||
| 185 | .get(2) | ||
| 186 | .is_some_and(|line| line.contains("[ C ] [ C ] [ C ] [ D ] [ D ]"))); | ||
| 174 | assert_eq!(h.screen.lines.len(), lines_before_bet); | 187 | assert_eq!(h.screen.lines.len(), lines_before_bet); |
| 175 | assert_eq!( | 188 | assert_eq!( |
| 176 | h.screen | 189 | h.screen |
| @@ -183,6 +196,32 @@ fn changing_the_bet_after_a_spin_does_not_leave_stale_lines() { | |||
| 183 | } | 196 | } |
| 184 | 197 | ||
| 185 | #[test] | 198 | #[test] |
| 199 | fn a_losing_spin_shows_no_win_and_no_winning_lines() { | ||
| 200 | let mut h = Harness::new(); | ||
| 201 | h.enter_slots("10"); | ||
| 202 | h.key(Key::Char(' ')); | ||
| 203 | |||
| 204 | h.reply(&format!("GAME_RESULT session-1 0 10 990 {LOSS} none -")); | ||
| 205 | |||
| 206 | assert_eq!(h.board().len(), 9); | ||
| 207 | assert!(h.board()[6].contains("No win.")); | ||
| 208 | assert_eq!(h.board()[7], ""); | ||
| 209 | } | ||
| 210 | |||
| 211 | #[test] | ||
| 212 | fn a_mega_win_shows_all_winning_lines() { | ||
| 213 | let mut h = Harness::new(); | ||
| 214 | h.enter_slots("10"); | ||
| 215 | h.key(Key::Char(' ')); | ||
| 216 | |||
| 217 | h.reply(&format!("GAME_RESULT session-1 750 10 1740 {ALL_C} mega 1,2,3,4,5")); | ||
| 218 | |||
| 219 | assert_eq!(h.board().len(), 9); | ||
| 220 | assert!(h.board()[6].contains("MEGA WIN! 750 PLN")); | ||
| 221 | assert!(h.board()[7].contains("Winning lines: 1,2,3,4,5")); | ||
| 222 | } | ||
| 223 | |||
| 224 | #[test] | ||
| 186 | fn quitting_clears_the_board_and_returns_the_prompt() { | 225 | fn quitting_clears_the_board_and_returns_the_prompt() { |
| 187 | let mut h = Harness::new(); | 226 | let mut h = Harness::new(); |
| 188 | h.enter_slots("50"); | 227 | h.enter_slots("50"); |
| @@ -202,8 +241,8 @@ fn a_server_error_replaces_the_status_line() { | |||
| 202 | 241 | ||
| 203 | h.reply("ERROR Insufficient balance"); | 242 | h.reply("ERROR Insufficient balance"); |
| 204 | 243 | ||
| 205 | assert_eq!(h.board().len(), 7); | 244 | assert_eq!(h.board().len(), 9); |
| 206 | assert!(h.board()[4].contains("ERROR: Insufficient balance")); | 245 | assert!(h.board()[6].contains("ERROR: Insufficient balance")); |
| 207 | assert!(h.board()[2].contains("[ ? ]")); | 246 | assert!(h.board()[2].contains("[ ? ]")); |
| 208 | assert!(!h.board().iter().any(|line| line.contains("Spinning"))); | 247 | assert!(!h.board().iter().any(|line| line.contains("Spinning"))); |
| 209 | } | 248 | } |
| @@ -216,8 +255,8 @@ fn an_empty_reply_is_an_error_not_a_silent_spin() { | |||
| 216 | 255 | ||
| 217 | h.reply(""); | 256 | h.reply(""); |
| 218 | 257 | ||
| 219 | assert_eq!(h.board().len(), 7); | 258 | assert_eq!(h.board().len(), 9); |
| 220 | assert!(h.board()[4].contains("No response from server")); | 259 | assert!(h.board()[6].contains("No response from server")); |
| 221 | } | 260 | } |
| 222 | 261 | ||
| 223 | #[test] | 262 | #[test] |
| @@ -301,7 +340,7 @@ fn play_without_a_bet_uses_the_default() { | |||
| 301 | let mut h = Harness::new(); | 340 | let mut h = Harness::new(); |
| 302 | h.line("play slots"); | 341 | h.line("play slots"); |
| 303 | 342 | ||
| 304 | assert_eq!(h.board().len(), 7); | 343 | assert_eq!(h.board().len(), 9); |
| 305 | assert!(h.board()[1].contains("Bet: 10 PLN")); | 344 | assert!(h.board()[1].contains("Bet: 10 PLN")); |
| 306 | } | 345 | } |
| 307 | 346 | ||
| @@ -475,3 +514,30 @@ fn disconnect_clears_connection_state() { | |||
| 475 | .iter() | 514 | .iter() |
| 476 | .any(|line| line.contains("Not connected"))); | 515 | .any(|line| line.contains("Not connected"))); |
| 477 | } | 516 | } |
| 517 | |||
| 518 | #[test] | ||
| 519 | fn parses_a_five_by_three_result_with_winning_lines() { | ||
| 520 | let response = format!("GAME_RESULT session-1 100 50 1050 {WIN3} win 1"); | ||
| 521 | let result = parse_spin_response(&response).expect("valid 5x3 result"); | ||
| 522 | |||
| 523 | assert_eq!(result.reels.chars().count(), 15); | ||
| 524 | assert_eq!(result.win_type, "win"); | ||
| 525 | assert_eq!(result.win_lines, vec![1]); | ||
| 526 | } | ||
| 527 | |||
| 528 | #[test] | ||
| 529 | fn accepts_a_legacy_three_symbol_result() { | ||
| 530 | let result = parse_spin_response("GAME_RESULT session-1 60 10 1050 OSS two") | ||
| 531 | .expect("legacy result should still parse"); | ||
| 532 | |||
| 533 | assert_eq!(result.reels, "OSS"); | ||
| 534 | assert_eq!(result.win_type, "two"); | ||
| 535 | assert!(result.win_lines.is_empty()); | ||
| 536 | } | ||
| 537 | |||
| 538 | #[test] | ||
| 539 | fn rejects_a_grid_with_the_wrong_size() { | ||
| 540 | let response = "GAME_RESULT session-1 100 50 1050 CCCCCCCCCCCCCC win 1"; | ||
| 541 | |||
| 542 | assert!(parse_spin_response(response).is_err()); | ||
| 543 | } | ||
