diff options
Diffstat (limited to 'tests/client_core.rs')
| -rw-r--r-- | tests/client_core.rs | 63 |
1 files changed, 23 insertions, 40 deletions
diff --git a/tests/client_core.rs b/tests/client_core.rs index e8b5646..176791e 100644 --- a/tests/client_core.rs +++ b/tests/client_core.rs | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | //! logical `Effect`s that `ClientCore` emits, so assertions are about what a | 4 | //! logical `Effect`s that `ClientCore` emits, so assertions are about what a |
| 5 | //! player would see, not about ANSI sequences. | 5 | //! player would see, not about ANSI sequences. |
| 6 | 6 | ||
| 7 | use std::time::Duration; | ||
| 7 | use zagan_bet::blackjack::BlackjackState; | 8 | use zagan_bet::blackjack::BlackjackState; |
| 8 | use zagan_bet::client::core::{ClientCore, Effect, InteractiveCommand, Key}; | 9 | use zagan_bet::client::core::{ClientCore, Effect, InteractiveCommand, Key}; |
| 9 | use zagan_bet::client::games::response::{ | 10 | use zagan_bet::client::games::response::{ |
| @@ -11,7 +12,6 @@ use zagan_bet::client::games::response::{ | |||
| 11 | }; | 12 | }; |
| 12 | use zagan_bet::client::ui::command_names; | 13 | use zagan_bet::client::ui::command_names; |
| 13 | use zagan_bet::crash::CrashState; | 14 | use zagan_bet::crash::CrashState; |
| 14 | use std::time::Duration; | ||
| 15 | 15 | ||
| 16 | const WIN3: &str = "CCCCLLCLODGSDGS"; | 16 | const WIN3: &str = "CCCCLLCLODGSDGS"; |
| 17 | const LOSS: &str = "CLOOGDSLCDCOGLS"; | 17 | const LOSS: &str = "CLOOGDSLCDCOGLS"; |
| @@ -67,10 +67,7 @@ impl Screen { | |||
| 67 | } | 67 | } |
| 68 | Effect::SendLine(line) => sent.push(line.clone()), | 68 | Effect::SendLine(line) => sent.push(line.clone()), |
| 69 | Effect::Interactive(command) => interactive.push(command.clone()), | 69 | Effect::Interactive(command) => interactive.push(command.clone()), |
| 70 | Effect::Quit | 70 | Effect::Quit | Effect::Disconnect | Effect::ListHosts | Effect::ForgetHost(_) => {} |
| 71 | | Effect::Disconnect | ||
| 72 | | Effect::ListHosts | ||
| 73 | | Effect::ForgetHost(_) => {} | ||
| 74 | } | 71 | } |
| 75 | } | 72 | } |
| 76 | } | 73 | } |
| @@ -276,7 +273,8 @@ fn a_mega_win_shows_all_winning_lines() { | |||
| 276 | 273 | ||
| 277 | assert_eq!(h.board().len(), 10); | 274 | assert_eq!(h.board().len(), 10); |
| 278 | assert!(h.board()[7].contains("MEGA WIN! 700 PLN")); | 275 | assert!(h.board()[7].contains("MEGA WIN! 700 PLN")); |
| 279 | assert!(h.board()[8].contains("Winning lines: 1 (top), 2 (middle), 3 (bottom), 4 (V), 5 (inverted V)")); | 276 | assert!(h.board()[8] |
| 277 | .contains("Winning lines: 1 (top), 2 (middle), 3 (bottom), 4 (V), 5 (inverted V)")); | ||
| 280 | assert_eq!(h.board()[2].matches("{ C }").count(), 5); | 278 | assert_eq!(h.board()[2].matches("{ C }").count(), 5); |
| 281 | } | 279 | } |
| 282 | 280 | ||
| @@ -423,10 +421,7 @@ fn help_lists_every_command() { | |||
| 423 | 421 | ||
| 424 | let transcript = h.screen.lines.join("\n"); | 422 | let transcript = h.screen.lines.join("\n"); |
| 425 | for command in command_names() { | 423 | for command in command_names() { |
| 426 | assert!( | 424 | assert!(transcript.contains(command), "help is missing '{command}'"); |
| 427 | transcript.contains(command), | ||
| 428 | "help is missing '{command}'" | ||
| 429 | ); | ||
| 430 | } | 425 | } |
| 431 | } | 426 | } |
| 432 | 427 | ||
| @@ -548,11 +543,7 @@ fn send_prints_the_echo() { | |||
| 548 | h.line("send hello"); | 543 | h.line("send hello"); |
| 549 | h.reply("hello"); | 544 | h.reply("hello"); |
| 550 | 545 | ||
| 551 | assert!(h | 546 | assert!(h.screen.lines.iter().any(|line| line == "Echo: hello")); |
| 552 | .screen | ||
| 553 | .lines | ||
| 554 | .iter() | ||
| 555 | .any(|line| line == "Echo: hello")); | ||
| 556 | } | 547 | } |
| 557 | 548 | ||
| 558 | #[test] | 549 | #[test] |
| @@ -560,11 +551,7 @@ fn disconnect_clears_connection_state() { | |||
| 560 | let mut h = Harness::new(); | 551 | let mut h = Harness::new(); |
| 561 | h.line("disconnect"); | 552 | h.line("disconnect"); |
| 562 | 553 | ||
| 563 | assert!(h | 554 | assert!(h.screen.lines.iter().any(|line| line == "Disconnected")); |
| 564 | .screen | ||
| 565 | .lines | ||
| 566 | .iter() | ||
| 567 | .any(|line| line == "Disconnected")); | ||
| 568 | 555 | ||
| 569 | h.line("play slots"); | 556 | h.line("play slots"); |
| 570 | assert!(h | 557 | assert!(h |
| @@ -636,8 +623,7 @@ fn roulette_split_bets_spin_and_show_the_result() { | |||
| 636 | "PLAY_START roulette 30 {\"red\":10,\"black\":0,\"even\":10,\"odd\":0,\"numbers\":[{\"number\":17,\"amount\":10}]}" | 623 | "PLAY_START roulette 30 {\"red\":10,\"black\":0,\"even\":10,\"odd\":0,\"numbers\":[{\"number\":17,\"amount\":10}]}" |
| 637 | ); | 624 | ); |
| 638 | 625 | ||
| 639 | let bets = | 626 | let bets = r#"{"red":10,"black":0,"even":10,"odd":0,"numbers":[{"number":17,"amount":10}]}"#; |
| 640 | r#"{"red":10,"black":0,"even":10,"odd":0,"numbers":[{"number":17,"amount":10}]}"#; | ||
| 641 | h.reply(&format!( | 627 | h.reply(&format!( |
| 642 | "ROULETTE_RESULT session-1 360 30 1330 17 black {bets}" | 628 | "ROULETTE_RESULT session-1 360 30 1330 17 black {bets}" |
| 643 | )); | 629 | )); |
| @@ -655,7 +641,10 @@ fn roulette_rejects_an_empty_spin_and_accepts_the_equals_chip_key() { | |||
| 655 | 641 | ||
| 656 | h.key(Key::Char(' ')); | 642 | h.key(Key::Char(' ')); |
| 657 | assert!(h.board()[4].contains("ERROR: Place at least one bet")); | 643 | assert!(h.board()[4].contains("ERROR: Place at least one bet")); |
| 658 | assert!(!h.sent.iter().any(|line| line.starts_with("PLAY_START roulette"))); | 644 | assert!(!h |
| 645 | .sent | ||
| 646 | .iter() | ||
| 647 | .any(|line| line.starts_with("PLAY_START roulette"))); | ||
| 659 | 648 | ||
| 660 | h.key(Key::Char('=')); | 649 | h.key(Key::Char('=')); |
| 661 | assert!(h.board()[1].contains("Chip: 20 PLN")); | 650 | assert!(h.board()[1].contains("Chip: 20 PLN")); |
| @@ -716,10 +705,7 @@ fn blackjack_deals_hits_and_settles() { | |||
| 716 | assert!(h.board()[4].contains("Press [SPACE] to deal.")); | 705 | assert!(h.board()[4].contains("Press [SPACE] to deal.")); |
| 717 | 706 | ||
| 718 | h.key(Key::Char(' ')); | 707 | h.key(Key::Char(' ')); |
| 719 | assert!(h | 708 | assert!(h.sent.iter().any(|line| line == "PLAY_START blackjack 10")); |
| 720 | .sent | ||
| 721 | .iter() | ||
| 722 | .any(|line| line == "PLAY_START blackjack 10")); | ||
| 723 | 709 | ||
| 724 | let player = bj_state( | 710 | let player = bj_state( |
| 725 | "bj1", | 711 | "bj1", |
| @@ -847,10 +833,7 @@ fn blackjack_ready_board_can_change_the_next_bet() { | |||
| 847 | assert!(h.board()[1].contains("Bet: 20 PLN")); | 833 | assert!(h.board()[1].contains("Bet: 20 PLN")); |
| 848 | 834 | ||
| 849 | h.key(Key::Char(' ')); | 835 | h.key(Key::Char(' ')); |
| 850 | assert!(h | 836 | assert!(h.sent.iter().any(|line| line == "PLAY_START blackjack 20")); |
| 851 | .sent | ||
| 852 | .iter() | ||
| 853 | .any(|line| line == "PLAY_START blackjack 20")); | ||
| 854 | } | 837 | } |
| 855 | 838 | ||
| 856 | #[test] | 839 | #[test] |
| @@ -875,7 +858,13 @@ fn parses_a_blackjack_state() { | |||
| 875 | assert!(parse_blackjack_response("ERROR Insufficient balance").is_err()); | 858 | assert!(parse_blackjack_response("ERROR Insufficient balance").is_err()); |
| 876 | } | 859 | } |
| 877 | 860 | ||
| 878 | fn crash_state(phase: &str, multiplier: f64, crash_point: Option<f64>, payout: u64, balance: i64) -> CrashState { | 861 | fn crash_state( |
| 862 | phase: &str, | ||
| 863 | multiplier: f64, | ||
| 864 | crash_point: Option<f64>, | ||
| 865 | payout: u64, | ||
| 866 | balance: i64, | ||
| 867 | ) -> CrashState { | ||
| 879 | CrashState { | 868 | CrashState { |
| 880 | session_id: "cr1".to_string(), | 869 | session_id: "cr1".to_string(), |
| 881 | phase: phase.to_string(), | 870 | phase: phase.to_string(), |
| @@ -920,10 +909,7 @@ fn crash_starts_a_round_and_draws_the_multiplier_locally() { | |||
| 920 | assert!(h.board()[3].contains("Potential: 20 PLN")); | 909 | assert!(h.board()[3].contains("Potential: 20 PLN")); |
| 921 | 910 | ||
| 922 | h.key(Key::Char('c')); | 911 | h.key(Key::Char('c')); |
| 923 | assert_eq!( | 912 | assert_eq!(h.sent.last().map(String::as_str), Some("CRASH_CASHOUT cr1")); |
| 924 | h.sent.last().map(String::as_str), | ||
| 925 | Some("CRASH_CASHOUT cr1") | ||
| 926 | ); | ||
| 927 | 913 | ||
| 928 | let cashed = crash_state("cashed", 2.0, Some(3.0), 20, 1010); | 914 | let cashed = crash_state("cashed", 2.0, Some(3.0), 20, 1010); |
| 929 | h.reply(&crash_line("CRASH_STATE", &cashed)); | 915 | h.reply(&crash_line("CRASH_STATE", &cashed)); |
| @@ -967,10 +953,7 @@ fn crash_q_forfeits_an_active_round() { | |||
| 967 | h.reply(&crash_line("CRASH_START", &running)); | 953 | h.reply(&crash_line("CRASH_START", &running)); |
| 968 | 954 | ||
| 969 | h.key(Key::Char('q')); | 955 | h.key(Key::Char('q')); |
| 970 | assert_eq!( | 956 | assert_eq!(h.sent.last().map(String::as_str), Some("CRASH_FORFEIT cr1")); |
| 971 | h.sent.last().map(String::as_str), | ||
| 972 | Some("CRASH_FORFEIT cr1") | ||
| 973 | ); | ||
| 974 | 957 | ||
| 975 | let forfeited = crash_state("forfeit", 1.2, Some(2.0), 0, 990); | 958 | let forfeited = crash_state("forfeit", 1.2, Some(2.0), 0, 990); |
| 976 | h.reply(&crash_line("CRASH_STATE", &forfeited)); | 959 | h.reply(&crash_line("CRASH_STATE", &forfeited)); |
