add tests for 84
This commit is contained in:
@@ -9,3 +9,6 @@ edition = "2021"
|
|||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
strum = "0.24.1"
|
strum = "0.24.1"
|
||||||
strum_macros = "0.24.1"
|
strum_macros = "0.24.1"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
debug = true
|
||||||
|
|||||||
+53
-3
@@ -122,7 +122,6 @@ impl Monopoly {
|
|||||||
let t1 = iter.next().unwrap();
|
let t1 = iter.next().unwrap();
|
||||||
let t2 = iter.next().unwrap();
|
let t2 = iter.next().unwrap();
|
||||||
let is_double = t1 == t2;
|
let is_double = t1 == t2;
|
||||||
// dbg!(t1, t2);
|
|
||||||
(t1 + t2, is_double)
|
(t1 + t2, is_double)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,7 +178,6 @@ impl Monopoly {
|
|||||||
|
|
||||||
fn handle_chance(&mut self, square: Squares) -> Squares {
|
fn handle_chance(&mut self, square: Squares) -> Squares {
|
||||||
let card = self.draw_from_chance_pile_and_put_at_bottom();
|
let card = self.draw_from_chance_pile_and_put_at_bottom();
|
||||||
// dbg!(card);
|
|
||||||
match card {
|
match card {
|
||||||
Chance::AdvanceToGo => self.advance_to_go(),
|
Chance::AdvanceToGo => self.advance_to_go(),
|
||||||
Chance::GoToJail => self.go_to_jail(),
|
Chance::GoToJail => self.go_to_jail(),
|
||||||
@@ -240,7 +238,7 @@ impl Monopoly {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn go_back_3_squares(&mut self) -> Squares {
|
fn go_back_3_squares(&mut self) -> Squares {
|
||||||
self.board.nth(NUMBER_SQUARES - 3).unwrap()
|
self.board.nth(NUMBER_SQUARES - 4).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_too_many_doubles(&mut self, is_double: bool) -> bool {
|
fn check_too_many_doubles(&mut self, is_double: bool) -> bool {
|
||||||
@@ -252,6 +250,11 @@ impl Monopoly {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
fn advance_by_number(&mut self, number: usize) -> Squares {
|
||||||
|
self.board.nth(number).unwrap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Statistics {
|
pub struct Statistics {
|
||||||
@@ -288,3 +291,50 @@ impl Statistics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub mod test {
|
||||||
|
use super::{Monopoly, Squares};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn jail() {
|
||||||
|
let mut monopoly = Monopoly::new();
|
||||||
|
assert_eq!(monopoly.go_to_jail(), Squares::Jail);
|
||||||
|
assert_eq!(monopoly.go_to_jail(), Squares::Jail);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn utility() {
|
||||||
|
let mut monopoly = Monopoly::new();
|
||||||
|
assert_eq!(monopoly.go_to_utility(), Squares::U1);
|
||||||
|
assert_eq!(monopoly.go_to_utility(), Squares::U2);
|
||||||
|
assert_eq!(monopoly.go_to_utility(), Squares::U1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn railway() {
|
||||||
|
let mut monopoly = Monopoly::new();
|
||||||
|
assert_eq!(monopoly.go_to_railway(), Squares::R1);
|
||||||
|
assert_eq!(monopoly.go_to_railway(), Squares::R2);
|
||||||
|
assert_eq!(monopoly.go_to_railway(), Squares::R3);
|
||||||
|
assert_eq!(monopoly.go_to_railway(), Squares::R4);
|
||||||
|
assert_eq!(monopoly.go_to_railway(), Squares::R1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn go() {
|
||||||
|
let mut monopoly = Monopoly::new();
|
||||||
|
assert_eq!(monopoly.advance_to_go(), Squares::Go);
|
||||||
|
assert_eq!(monopoly.advance_to_go(), Squares::Go);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn back_3() {
|
||||||
|
let mut monopoly = Monopoly::new();
|
||||||
|
assert_eq!(monopoly.advance_by_number(3) as isize, 3);
|
||||||
|
assert_eq!(monopoly.go_back_3_squares(), Squares::Go);
|
||||||
|
|
||||||
|
assert_eq!(monopoly.advance_by_number(27) as isize, 27);
|
||||||
|
assert_eq!(monopoly.go_back_3_squares() as isize, 24);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user