summaryrefslogtreecommitdiffstats
path: root/tests/client_core.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-10-29 22:55:49 +0100
committersalmonik <salmonik@tuta.io>2026-10-29 22:55:49 +0100
commit49df948de25d28601469e9ca993f33530989ebd0 (patch)
tree291aae0f57d0d7d12a27eb28038e43f942d6b991 /tests/client_core.rs
parentv2.4.0: key stored credentials by certificate fingerprint (diff)
downloadzagan-bet-49df948de25d28601469e9ca993f33530989ebd0.tar.gz
zagan-bet-49df948de25d28601469e9ca993f33530989ebd0.zip
v3.0.0: cursor-driven roulette felt with splits and corners; drop schema migrations; require 80x24
Diffstat (limited to 'tests/client_core.rs')
-rw-r--r--tests/client_core.rs86
1 files changed, 52 insertions, 34 deletions
diff --git a/tests/client_core.rs b/tests/client_core.rs
index 176791e..dea6808 100644
--- a/tests/client_core.rs
+++ b/tests/client_core.rs
@@ -591,26 +591,34 @@ fn rejects_a_grid_with_the_wrong_size() {
591} 591}
592 592
593#[test] 593#[test]
594fn roulette_split_bets_spin_and_show_the_result() { 594fn roulette_cursor_places_bets_and_spins() {
595 let mut h = Harness::new(); 595 let mut h = Harness::new();
596 h.enter_roulette(); 596 h.enter_roulette();
597 597
598 assert_eq!(h.board().len(), 8); 598 assert_eq!(h.board().len(), 12);
599 assert_eq!(h.board()[0], "=== ROULETTE ==="); 599 assert_eq!(h.board()[0], "=== ROULETTE ===");
600 assert!(h.board()[1].contains("Balance: 1000 PLN")); 600 assert!(h.board()[1].contains("Balance: 1000 PLN"));
601 assert!(h.board()[1].contains("Chip: 10 PLN")); 601 assert!(h.board()[1].contains("Chip: 10 PLN"));
602 assert!(h.board()[2].contains("Bets: (none)")); 602 assert!(h.board()[9].contains("Bets: (none)"));
603 // The cursor starts on number 1, the bottom-left corner.
604 assert!(h.board()[5].contains("[ 1 ]"));
605
606 // Up twice: straight 2, then the split between 2 and 3.
607 h.key(Key::Up);
608 h.key(Key::Up);
609 assert!(h.board()[4].contains("[ 2 ]"));
610 assert!(h.board()[3].contains("[ 3 ]"));
603 611
604 h.key(Key::Char('r'));
605 h.key(Key::Char('e'));
606 h.key(Key::Char('1'));
607 h.key(Key::Char('7'));
608 h.key(Key::Enter); 612 h.key(Key::Enter);
613 assert!(h.board()[9].contains("2/3 10"));
614 assert!(h.board()[9].contains("Total: 10 PLN"));
609 615
610 assert!(h.board()[2].contains("RED 10")); 616 // Back down to number 1 and place a straight.
611 assert!(h.board()[2].contains("EVEN 10")); 617 h.key(Key::Down);
612 assert!(h.board()[2].contains("#17 10")); 618 h.key(Key::Down);
613 assert!(h.board()[2].contains("Total: 30 PLN")); 619 h.key(Key::Enter);
620 assert!(h.board()[9].contains("1 10"));
621 assert!(h.board()[9].contains("Total: 20 PLN"));
614 622
615 h.key(Key::Char(' ')); 623 h.key(Key::Char(' '));
616 let request = h 624 let request = h
@@ -620,18 +628,41 @@ fn roulette_split_bets_spin_and_show_the_result() {
620 .expect("roulette request"); 628 .expect("roulette request");
621 assert_eq!( 629 assert_eq!(
622 request, 630 request,
623 "PLAY_START roulette 30 {\"red\":10,\"black\":0,\"even\":10,\"odd\":0,\"numbers\":[{\"number\":17,\"amount\":10}]}" 631 "PLAY_START roulette 20 {\"chips\":[{\"target\":{\"bet\":\"split\",\"a\":2,\"b\":3},\"amount\":10},{\"target\":{\"bet\":\"straight\",\"number\":1},\"amount\":10}]}"
624 ); 632 );
625 633
626 let bets = r#"{"red":10,"black":0,"even":10,"odd":0,"numbers":[{"number":17,"amount":10}]}"#; 634 let bets = r#"{"chips":[{"target":{"bet":"split","a":2,"b":3},"amount":10},{"target":{"bet":"straight","number":1},"amount":10}]}"#;
627 h.reply(&format!( 635 h.reply(&format!(
628 "ROULETTE_RESULT session-1 360 30 1330 17 black {bets}" 636 "ROULETTE_RESULT session-1 180 20 1160 3 red {bets}"
629 )); 637 ));
630 638
631 assert_eq!(h.board().len(), 8); 639 assert_eq!(h.board().len(), 12);
632 assert!(h.board()[1].contains("Balance: 1330 PLN")); 640 assert!(h.board()[1].contains("Balance: 1160 PLN"));
633 assert!(h.board()[4].contains("Winning: 17 BLACK ODD")); 641 assert!(h.board()[10].contains("Won 180 PLN at 3 RED ODD"));
634 assert!(h.board()[5].contains("Won 360 PLN")); 642 assert!(h.board()[10].contains("+160"));
643}
644
645#[test]
646fn roulette_cursor_reaches_the_outside_rows() {
647 let mut h = Harness::new();
648 h.enter_roulette();
649
650 h.key(Key::Down);
651 assert!(h.board()[6].starts_with("[") && h.board()[6].contains("1st 12"));
652 h.key(Key::Down);
653 assert!(h.board()[7].starts_with("[") && h.board()[7].contains("2:1"));
654 h.key(Key::Down);
655 assert!(h.board()[8].starts_with("[") && h.board()[8].contains("1-18"));
656
657 h.key(Key::Enter);
658 assert!(h.board()[9].contains("1-18 10"));
659
660 // Back up to the felt: the bottom edge of the first dozen is the 1/4 split.
661 h.key(Key::Up);
662 h.key(Key::Up);
663 h.key(Key::Up);
664 assert!(h.board()[5].contains("[ 1 ]"));
665 assert!(h.board()[5].contains("[ 4 ]"));
635} 666}
636 667
637#[test] 668#[test]
@@ -640,7 +671,7 @@ fn roulette_rejects_an_empty_spin_and_accepts_the_equals_chip_key() {
640 h.enter_roulette(); 671 h.enter_roulette();
641 672
642 h.key(Key::Char(' ')); 673 h.key(Key::Char(' '));
643 assert!(h.board()[4].contains("ERROR: Place at least one bet")); 674 assert!(h.board()[10].contains("ERROR: Place at least one bet"));
644 assert!(!h 675 assert!(!h
645 .sent 676 .sent
646 .iter() 677 .iter()
@@ -648,22 +679,9 @@ fn roulette_rejects_an_empty_spin_and_accepts_the_equals_chip_key() {
648 679
649 h.key(Key::Char('=')); 680 h.key(Key::Char('='));
650 assert!(h.board()[1].contains("Chip: 20 PLN")); 681 assert!(h.board()[1].contains("Chip: 20 PLN"));
651 h.key(Key::Char('r'));
652 assert!(h.board()[2].contains("RED 20"));
653 assert!(h.board()[2].contains("Total: 20 PLN"));
654}
655
656#[test]
657fn roulette_rejects_an_out_of_range_number() {
658 let mut h = Harness::new();
659 h.enter_roulette();
660
661 h.key(Key::Char('9'));
662 h.key(Key::Char('9'));
663 h.key(Key::Enter); 682 h.key(Key::Enter);
664 683 assert!(h.board()[9].contains("1 20"));
665 assert!(h.board()[4].contains("ERROR: Number must be 0-36")); 684 assert!(h.board()[9].contains("Total: 20 PLN"));
666 assert!(h.board()[2].contains("Bets: (none)"));
667} 685}
668 686
669fn bj_state( 687fn bj_state(