diff options
Diffstat (limited to '')
| -rw-r--r-- | tests/client_core.rs | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/client_core.rs b/tests/client_core.rs index 4749d99..7fb7e29 100644 --- a/tests/client_core.rs +++ b/tests/client_core.rs | |||
| @@ -47,6 +47,15 @@ impl Screen { | |||
| 47 | self.region_start = None; | 47 | self.region_start = None; |
| 48 | self.region_len = 0; | 48 | self.region_len = 0; |
| 49 | } | 49 | } |
| 50 | Effect::AnimateRoulette { final_lines, .. } => { | ||
| 51 | if let Some(start) = self.region_start { | ||
| 52 | self.lines.truncate(start); | ||
| 53 | } else { | ||
| 54 | self.region_start = Some(self.lines.len()); | ||
| 55 | } | ||
| 56 | self.lines.extend(final_lines.iter().cloned()); | ||
| 57 | self.region_len = final_lines.len(); | ||
| 58 | } | ||
| 50 | Effect::SetPrompt { text, cursor_col } => { | 59 | Effect::SetPrompt { text, cursor_col } => { |
| 51 | self.prompt = text.clone(); | 60 | self.prompt = text.clone(); |
| 52 | self.prompt_cursor = *cursor_col; | 61 | self.prompt_cursor = *cursor_col; |
| @@ -125,6 +134,11 @@ impl Harness { | |||
| 125 | self.line(&format!("play slots {bet}")); | 134 | self.line(&format!("play slots {bet}")); |
| 126 | self.reply("INFO alice 1 1000"); | 135 | self.reply("INFO alice 1 1000"); |
| 127 | } | 136 | } |
| 137 | |||
| 138 | fn enter_roulette(&mut self) { | ||
| 139 | self.line("play roulette"); | ||
| 140 | self.reply("INFO alice 1 1000"); | ||
| 141 | } | ||
| 128 | } | 142 | } |
| 129 | 143 | ||
| 130 | #[test] | 144 | #[test] |
| @@ -559,3 +573,77 @@ fn rejects_a_grid_with_the_wrong_size() { | |||
| 559 | 573 | ||
| 560 | assert!(parse_spin_response(response).is_err()); | 574 | assert!(parse_spin_response(response).is_err()); |
| 561 | } | 575 | } |
| 576 | |||
| 577 | #[test] | ||
| 578 | fn roulette_split_bets_spin_and_show_the_result() { | ||
| 579 | let mut h = Harness::new(); | ||
| 580 | h.enter_roulette(); | ||
| 581 | |||
| 582 | assert_eq!(h.board().len(), 8); | ||
| 583 | assert_eq!(h.board()[0], "=== ROULETTE ==="); | ||
| 584 | assert!(h.board()[1].contains("Balance: 1000 PLN")); | ||
| 585 | assert!(h.board()[1].contains("Chip: 10 PLN")); | ||
| 586 | assert!(h.board()[2].contains("Bets: (none)")); | ||
| 587 | |||
| 588 | h.key(Key::Char('r')); | ||
| 589 | h.key(Key::Char('e')); | ||
| 590 | h.key(Key::Char('1')); | ||
| 591 | h.key(Key::Char('7')); | ||
| 592 | h.key(Key::Enter); | ||
| 593 | |||
| 594 | assert!(h.board()[2].contains("RED 10")); | ||
| 595 | assert!(h.board()[2].contains("EVEN 10")); | ||
| 596 | assert!(h.board()[2].contains("#17 10")); | ||
| 597 | assert!(h.board()[2].contains("Total: 30 PLN")); | ||
| 598 | |||
| 599 | h.key(Key::Char(' ')); | ||
| 600 | let request = h | ||
| 601 | .sent | ||
| 602 | .iter() | ||
| 603 | .find(|line| line.starts_with("PLAY_START roulette")) | ||
| 604 | .expect("roulette request"); | ||
| 605 | assert_eq!( | ||
| 606 | request, | ||
| 607 | "PLAY_START roulette 30 {\"red\":10,\"black\":0,\"even\":10,\"odd\":0,\"numbers\":[{\"number\":17,\"amount\":10}]}" | ||
| 608 | ); | ||
| 609 | |||
| 610 | let bets = | ||
| 611 | r#"{"red":10,"black":0,"even":10,"odd":0,"numbers":[{"number":17,"amount":10}]}"#; | ||
| 612 | h.reply(&format!( | ||
| 613 | "ROULETTE_RESULT session-1 360 30 1330 17 black {bets}" | ||
| 614 | )); | ||
| 615 | |||
| 616 | assert_eq!(h.board().len(), 8); | ||
| 617 | assert!(h.board()[1].contains("Balance: 1330 PLN")); | ||
| 618 | assert!(h.board()[4].contains("Winning: 17 BLACK ODD")); | ||
| 619 | assert!(h.board()[5].contains("Won 360 PLN")); | ||
| 620 | } | ||
| 621 | |||
| 622 | #[test] | ||
| 623 | fn roulette_rejects_an_empty_spin_and_accepts_the_equals_chip_key() { | ||
| 624 | let mut h = Harness::new(); | ||
| 625 | h.enter_roulette(); | ||
| 626 | |||
| 627 | h.key(Key::Char(' ')); | ||
| 628 | assert!(h.board()[4].contains("ERROR: Place at least one bet")); | ||
| 629 | assert!(!h.sent.iter().any(|line| line.starts_with("PLAY_START roulette"))); | ||
| 630 | |||
| 631 | h.key(Key::Char('=')); | ||
| 632 | assert!(h.board()[1].contains("Chip: 20 PLN")); | ||
| 633 | h.key(Key::Char('r')); | ||
| 634 | assert!(h.board()[2].contains("RED 20")); | ||
| 635 | assert!(h.board()[2].contains("Total: 20 PLN")); | ||
| 636 | } | ||
| 637 | |||
| 638 | #[test] | ||
| 639 | fn roulette_rejects_an_out_of_range_number() { | ||
| 640 | let mut h = Harness::new(); | ||
| 641 | h.enter_roulette(); | ||
| 642 | |||
| 643 | h.key(Key::Char('9')); | ||
| 644 | h.key(Key::Char('9')); | ||
| 645 | h.key(Key::Enter); | ||
| 646 | |||
| 647 | assert!(h.board()[4].contains("ERROR: Number must be 0-36")); | ||
| 648 | assert!(h.board()[2].contains("Bets: (none)")); | ||
| 649 | } | ||
