summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-10-29 18:43:09 +0100
committersalmonik <salmonik@tuta.io>2026-10-29 18:43:09 +0100
commit08269639606c0481037cbde7ebaf2e0455460883 (patch)
tree57c1f967e8836a1a7da84b1887d932e0067d538f /tests
parentv2.2.0: add blackjack with reserved bets and hit/stand/double (diff)
downloadzagan-bet-08269639606c0481037cbde7ebaf2e0455460883.tar.gz
zagan-bet-08269639606c0481037cbde7ebaf2e0455460883.zip
v2.2.1: forfeit blackjack bets when leaving or disconnecting
Diffstat (limited to '')
-rw-r--r--tests/blackjack.rs11
-rw-r--r--tests/client_core.rs19
-rw-r--r--tests/server_core.rs20
3 files changed, 33 insertions, 17 deletions
diff --git a/tests/blackjack.rs b/tests/blackjack.rs
index 79721d3..f90ca8d 100644
--- a/tests/blackjack.rs
+++ b/tests/blackjack.rs
@@ -80,6 +80,17 @@ fn doubling_adds_the_base_bet_and_draws_one_card() {
80} 80}
81 81
82#[test] 82#[test]
83fn forfeiting_loses_the_bet() {
84 let mut hand = hand(&["10S", "9D", "6H", "8C"], 10);
85 hand.forfeit();
86
87 assert!(hand.is_done());
88 assert_eq!(hand.result, "forfeit");
89 assert_eq!(hand.winnings, 0);
90 assert_eq!(hand.bet, 10);
91}
92
93#[test]
83fn the_dealer_busts_and_the_player_wins() { 94fn the_dealer_busts_and_the_player_wins() {
84 let mut hand = hand(&["10S", "7H", "8H", "9C", "10H"], 10); 95 let mut hand = hand(&["10S", "7H", "8H", "9C", "10H"], 10);
85 assert_eq!(hand.player_total(), 18); 96 assert_eq!(hand.player_total(), 18);
diff --git a/tests/client_core.rs b/tests/client_core.rs
index cfcf608..ec444bd 100644
--- a/tests/client_core.rs
+++ b/tests/client_core.rs
@@ -722,6 +722,7 @@ fn blackjack_deals_hits_and_settles() {
722 assert!(h.board()[3].contains("You: [10♠] [6♥] 16")); 722 assert!(h.board()[3].contains("You: [10♠] [6♥] 16"));
723 assert!(h.board()[4].contains("Hit, stand or double.")); 723 assert!(h.board()[4].contains("Hit, stand or double."));
724 assert!(h.board()[5].contains("[D]ouble")); 724 assert!(h.board()[5].contains("[D]ouble"));
725 assert!(h.board()[5].contains("[Q] Forfeit"));
725 726
726 h.key(Key::Char('h')); 727 h.key(Key::Char('h'));
727 assert_eq!( 728 assert_eq!(
@@ -757,7 +758,7 @@ fn blackjack_deals_hits_and_settles() {
757} 758}
758 759
759#[test] 760#[test]
760fn blackjack_cancel_sends_a_cancel_action() { 761fn blackjack_forfeit_is_sent_when_leaving_an_active_hand() {
761 let mut h = Harness::new(); 762 let mut h = Harness::new();
762 h.enter_blackjack(); 763 h.enter_blackjack();
763 h.key(Key::Char(' ')); 764 h.key(Key::Char(' '));
@@ -784,10 +785,10 @@ fn blackjack_cancel_sends_a_cancel_action() {
784 h.key(Key::Char('q')); 785 h.key(Key::Char('q'));
785 assert_eq!( 786 assert_eq!(
786 h.sent.last().map(String::as_str), 787 h.sent.last().map(String::as_str),
787 Some("BLACKJACK_ACTION bj1 cancel") 788 Some("BLACKJACK_ACTION bj1 forfeit")
788 ); 789 );
789 790
790 let cancelled = bj_state( 791 let forfeited = bj_state(
791 "bj1", 792 "bj1",
792 "done", 793 "done",
793 &["10S", "6H"], 794 &["10S", "6H"],
@@ -796,18 +797,22 @@ fn blackjack_cancel_sends_a_cancel_action() {
796 9, 797 9,
797 10, 798 10,
798 10, 799 10,
799 1000, 800 990,
800 &[], 801 &[],
801 "cancelled", 802 "forfeit",
802 0, 803 0,
803 ); 804 );
804 h.reply(&format!( 805 h.reply(&format!(
805 "BLACKJACK_STATE {}", 806 "BLACKJACK_STATE {}",
806 serde_json::to_string(&cancelled).unwrap() 807 serde_json::to_string(&forfeited).unwrap()
807 )); 808 ));
808 809
809 assert!(h.board().is_empty()); 810 assert!(h.board().is_empty());
810 assert!(h.screen.lines.iter().any(|line| line == "Game exited.")); 811 assert!(h
812 .screen
813 .lines
814 .iter()
815 .any(|line| line.contains("forfeited (10 PLN lost)")));
811} 816}
812 817
813#[test] 818#[test]
diff --git a/tests/server_core.rs b/tests/server_core.rs
index 3ad277a..08a2bf2 100644
--- a/tests/server_core.rs
+++ b/tests/server_core.rs
@@ -457,7 +457,7 @@ fn blackjack_natural_settles_immediately() {
457} 457}
458 458
459#[test] 459#[test]
460fn blackjack_cancel_refunds_the_reserved_bet() { 460fn blackjack_forfeit_keeps_the_reserved_bet() {
461 let (mut core, _path) = 461 let (mut core, _path) =
462 setup_blackjack("blackjack-cancel", &["10S", "9D", "6H", "8C"]); 462 setup_blackjack("blackjack-cancel", &["10S", "9D", "6H", "8C"]);
463 let mut state = ConnectionState::default(); 463 let mut state = ConnectionState::default();
@@ -467,20 +467,20 @@ fn blackjack_cancel_refunds_the_reserved_bet() {
467 let current = blackjack_state(&core.handle_message(&mut state, "PLAY_START blackjack 10")); 467 let current = blackjack_state(&core.handle_message(&mut state, "PLAY_START blackjack 10"));
468 assert_eq!(current.balance, 990); 468 assert_eq!(current.balance, 990);
469 469
470 let cancelled = blackjack_state(&core.handle_message( 470 let forfeited = blackjack_state(&core.handle_message(
471 &mut state, 471 &mut state,
472 &format!("BLACKJACK_ACTION {} cancel", current.session_id), 472 &format!("BLACKJACK_ACTION {} forfeit", current.session_id),
473 )); 473 ));
474 474
475 assert_eq!(cancelled.result, "cancelled"); 475 assert_eq!(forfeited.result, "forfeit");
476 assert_eq!(cancelled.balance, 1000); 476 assert_eq!(forfeited.balance, 990);
477 assert_eq!(core.balance("alice"), Some(1000)); 477 assert_eq!(core.balance("alice"), Some(990));
478 assert_eq!(core.play_count("alice"), 0); 478 assert_eq!(core.play_count("alice"), 1);
479 assert_eq!(core.session_count(), 0); 479 assert_eq!(core.session_count(), 0);
480} 480}
481 481
482#[test] 482#[test]
483fn blackjack_disconnect_refunds_the_reserved_bet() { 483fn blackjack_disconnect_forfeits_the_reserved_bet() {
484 let (mut core, _path) = 484 let (mut core, _path) =
485 setup_blackjack("blackjack-disconnect", &["10S", "9D", "6H", "8C"]); 485 setup_blackjack("blackjack-disconnect", &["10S", "9D", "6H", "8C"]);
486 let mut state = ConnectionState::default(); 486 let mut state = ConnectionState::default();
@@ -492,7 +492,7 @@ fn blackjack_disconnect_refunds_the_reserved_bet() {
492 492
493 core.disconnect(&state); 493 core.disconnect(&state);
494 494
495 assert_eq!(core.balance("alice"), Some(1000)); 495 assert_eq!(core.balance("alice"), Some(990));
496 assert_eq!(core.play_count("alice"), 0); 496 assert_eq!(core.play_count("alice"), 1);
497 assert_eq!(core.session_count(), 0); 497 assert_eq!(core.session_count(), 0);
498} 498}