summaryrefslogtreecommitdiffstats
path: root/tests/slots.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-10-28 23:19:52 +0100
committersalmonik <salmonik@tuta.io>2026-10-28 23:19:52 +0100
commit2915d826f744612e0d975282f5bddf13270b9f3f (patch)
treea2864bfaef91070ac3b4e13b8b731e539a757cc8 /tests/slots.rs
parentv1.0.0: replace slots with 5x3 reels and five paylines (diff)
downloadzagan-bet-2915d826f744612e0d975282f5bddf13270b9f3f.tar.gz
zagan-bet-2915d826f744612e0d975282f5bddf13270b9f3f.zip
v1.1.0: highlight winning symbols on the slots board
Diffstat (limited to '')
-rw-r--r--tests/slots.rs43
1 files changed, 29 insertions, 14 deletions
diff --git a/tests/slots.rs b/tests/slots.rs
index 5fb751a..857e607 100644
--- a/tests/slots.rs
+++ b/tests/slots.rs
@@ -1,6 +1,6 @@
1//! Regression tests for the server-side 5x3 slots game. 1//! Regression tests for the server-side 5x3 slots game.
2 2
3use zagan_bet::server::games::slots::{SlotsGame, PAYLINES, REELS, ROWS}; 3use zagan_bet::server::games::slots::{LineWin, SlotsGame, PAYLINES, REELS, ROWS};
4use zagan_bet::server::games::traits::{Game, GamePhase}; 4use zagan_bet::server::games::traits::{Game, GamePhase};
5 5
6/// Convert row-major test rows into the column-major wire format. 6/// Convert row-major test rows into the column-major wire format.
@@ -15,13 +15,17 @@ fn grid(rows: [&str; 3]) -> String {
15 result 15 result
16} 16}
17 17
18fn payout(rows: [&str; 3], bet: u64) -> (u64, Vec<usize>) { 18fn payout(rows: [&str; 3], bet: u64) -> (u64, Vec<LineWin>) {
19 let reels = grid(rows); 19 let reels = grid(rows);
20 let game = SlotsGame::with_grid(&reels); 20 let game = SlotsGame::with_grid(&reels);
21 let cells: Vec<char> = reels.chars().collect(); 21 let cells: Vec<char> = reels.chars().collect();
22 game.calculate_payout(&cells, bet) 22 game.calculate_payout(&cells, bet)
23} 23}
24 24
25fn lines(wins: &[LineWin]) -> Vec<usize> {
26 wins.iter().map(|win| win.line).collect()
27}
28
25#[test] 29#[test]
26fn the_wire_grid_is_five_reels_by_three_rows() { 30fn the_wire_grid_is_five_reels_by_three_rows() {
27 assert_eq!(REELS, 5); 31 assert_eq!(REELS, 5);
@@ -37,50 +41,60 @@ fn the_wire_grid_is_five_reels_by_three_rows() {
37 41
38#[test] 42#[test]
39fn three_of_a_kind_on_the_top_line_pays() { 43fn three_of_a_kind_on_the_top_line_pays() {
40 let (winnings, lines) = payout(["CCCDD", "CLLGG", "CLOSS"], 10); 44 let (winnings, wins) = payout(["CCCDD", "CLLGG", "CLOSS"], 10);
41 45
42 assert_eq!(winnings, 20, "CCC on line 1 pays 2x total bet"); 46 assert_eq!(winnings, 20, "CCC on line 1 pays 2x total bet");
43 assert_eq!(lines, vec![1]); 47 assert_eq!(lines(&wins), vec![1]);
48 assert_eq!(wins[0].cells, vec![0, 3, 6]);
44} 49}
45 50
46#[test] 51#[test]
47fn four_of_a_kind_pays_more_than_three() { 52fn four_of_a_kind_pays_more_than_three() {
48 let (winnings, lines) = payout(["CCCCD", "LOGDS", "OGDSL"], 10); 53 let (winnings, wins) = payout(["CCCCD", "LOGDS", "OGDSL"], 10);
49 54
50 assert_eq!(winnings, 50, "CCCC pays 5x total bet"); 55 assert_eq!(winnings, 50, "CCCC pays 5x total bet");
51 assert_eq!(lines, vec![1]); 56 assert_eq!(lines(&wins), vec![1]);
57 assert_eq!(wins[0].cells, vec![0, 3, 6, 9]);
52} 58}
53 59
54#[test] 60#[test]
55fn five_of_a_kind_pays_all_lines() { 61fn five_of_a_kind_pays_all_lines() {
56 let (winnings, lines) = payout(["SSSSS", "SSSSS", "SSSSS"], 10); 62 let (winnings, wins) = payout(["SSSSS", "SSSSS", "SSSSS"], 10);
57 63
58 assert_eq!(winnings, 7500, "five SSSSS lines at 150x each"); 64 assert_eq!(winnings, 7500, "five SSSSS lines at 150x each");
59 assert_eq!(lines, vec![1, 2, 3, 4, 5]); 65 assert_eq!(lines(&wins), vec![1, 2, 3, 4, 5]);
66 assert_eq!(wins[0].cells, vec![0, 3, 6, 9, 12]);
67 assert_eq!(wins[3].cells, vec![0, 4, 8, 10, 12]);
68 assert_eq!(wins[4].cells, vec![2, 4, 6, 10, 14]);
60} 69}
61 70
62#[test] 71#[test]
63fn the_v_payline_is_evaluated() { 72fn the_v_payline_is_evaluated() {
64 let (winnings, lines) = payout(["COGDC", "LCLCG", "OGCSD"], 10); 73 let (winnings, wins) = payout(["COGDC", "LCLCG", "OGCSD"], 10);
65 74
66 assert_eq!(winnings, 150, "V line with five C symbols pays 15x"); 75 assert_eq!(winnings, 150, "V line with five C symbols pays 15x");
67 assert_eq!(lines, vec![4]); 76 assert_eq!(lines(&wins), vec![4]);
77 assert_eq!(wins[0].cells, vec![0, 4, 8, 10, 12]);
68} 78}
69 79
70#[test] 80#[test]
71fn no_matching_line_pays_nothing() { 81fn no_matching_line_pays_nothing() {
72 let (winnings, lines) = payout(["CLOGD", "LOSGC", "DGDSC"], 100); 82 let (winnings, wins) = payout(["CLOGD", "LOSGC", "DGDSC"], 100);
73 83
74 assert_eq!(winnings, 0); 84 assert_eq!(winnings, 0);
75 assert!(lines.is_empty()); 85 assert!(wins.is_empty());
76} 86}
77 87
78#[test] 88#[test]
79fn winning_lines_are_added_together() { 89fn winning_lines_are_added_together() {
80 let (winnings, lines) = payout(["SSSSS", "LLLLL", "OOOOO"], 10); 90 let (winnings, wins) = payout(["SSSSS", "LLLLL", "OOOOO"], 10);
81 91
82 assert_eq!(winnings, (150 + 20 + 25) * 10); 92 assert_eq!(winnings, (150 + 20 + 25) * 10);
83 assert_eq!(lines, vec![1, 2, 3]); 93 assert_eq!(lines(&wins), vec![1, 2, 3]);
94
95 let mut cells: Vec<usize> = wins.iter().flat_map(|win| win.cells.clone()).collect();
96 cells.sort_unstable();
97 assert_eq!(cells, (0..15).collect::<Vec<_>>());
84} 98}
85 99
86#[test] 100#[test]
@@ -111,6 +125,7 @@ fn a_spin_produces_a_finished_state_and_a_result_with_win_lines() {
111 assert_eq!(result.winnings, 20); 125 assert_eq!(result.winnings, 20);
112 assert_eq!(result.result_data.get("win_type").unwrap(), "win"); 126 assert_eq!(result.result_data.get("win_type").unwrap(), "win");
113 assert_eq!(result.result_data.get("win_lines").unwrap(), "1"); 127 assert_eq!(result.result_data.get("win_lines").unwrap(), "1");
128 assert_eq!(result.result_data.get("win_cells").unwrap(), "0,3,6");
114} 129}
115 130
116#[test] 131#[test]