diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-01 16:17:19 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-01 16:17:19 +0100 |
| commit | f07221b4e1d8aa464a44fe566884ccc0565406e9 (patch) | |
| tree | 48020a68cee1c95521d594dc6803c1f7ec01c801 /tests/roulette.rs | |
| parent | add nginx + php-fpm deployment example (diff) | |
| download | zagan-bet-f07221b4e1d8aa464a44fe566884ccc0565406e9.tar.gz zagan-bet-f07221b4e1d8aa464a44fe566884ccc0565406e9.zip | |
v3.2.0: straight and split bets anywhere on the felt; add history command
Diffstat (limited to '')
| -rw-r--r-- | tests/roulette.rs | 97 |
1 files changed, 72 insertions, 25 deletions
diff --git a/tests/roulette.rs b/tests/roulette.rs index 8f9155c..0c5e195 100644 --- a/tests/roulette.rs +++ b/tests/roulette.rs | |||
| @@ -234,28 +234,51 @@ fn target_at(x: usize, y: usize) -> BetTarget { | |||
| 234 | } | 234 | } |
| 235 | 235 | ||
| 236 | #[test] | 236 | #[test] |
| 237 | fn lattice_points_become_straights_splits_and_corners() { | 237 | fn cell_centres_are_straights() { |
| 238 | assert_eq!( | 238 | assert_eq!(target_at(1, 5), BetTarget::Straight { number: 1 }); |
| 239 | target_at(0, 3), | 239 | assert_eq!(target_at(1, 1), BetTarget::Straight { number: 3 }); |
| 240 | BetTarget::Straight { number: 1 }, | 240 | assert_eq!(target_at(23, 1), BetTarget::Straight { number: 36 }); |
| 241 | "bottom-left corner is a straight" | 241 | assert_eq!(target_at(23, 5), BetTarget::Straight { number: 34 }); |
| 242 | ); | 242 | assert_eq!(target_at(5, 3), BetTarget::Straight { number: 8 }); |
| 243 | assert_eq!(target_at(0, 0), BetTarget::Straight { number: 3 }); | 243 | |
| 244 | assert_eq!(target_at(12, 0), BetTarget::Straight { number: 36 }); | 244 | // Every one of the 36 numbers can be bet straight. |
| 245 | assert_eq!(target_at(12, 3), BetTarget::Straight { number: 34 }); | 245 | let mut reachable = Vec::new(); |
| 246 | 246 | for column in 0..12usize { | |
| 247 | assert_eq!(target_at(0, 1), BetTarget::Split { a: 2, b: 3 }); | 247 | for row in 0..3usize { |
| 248 | assert_eq!(target_at(12, 1), BetTarget::Split { a: 35, b: 36 }); | 248 | let cursor = Cursor::Lattice { |
| 249 | assert_eq!(target_at(1, 0), BetTarget::Split { a: 3, b: 6 }); | 249 | x: 2 * column + 1, |
| 250 | y: 2 * row + 1, | ||
| 251 | }; | ||
| 252 | if let Some(BetTarget::Straight { number }) = cursor.target() { | ||
| 253 | reachable.push(number); | ||
| 254 | } | ||
| 255 | } | ||
| 256 | } | ||
| 257 | reachable.sort_unstable(); | ||
| 258 | assert_eq!(reachable, (1..=36).collect::<Vec<_>>()); | ||
| 259 | } | ||
| 250 | 260 | ||
| 261 | #[test] | ||
| 262 | fn lines_between_cells_are_splits_and_crossings_are_corners() { | ||
| 263 | // Vertical lines sit between two columns. | ||
| 264 | assert_eq!(target_at(2, 5), BetTarget::Split { a: 1, b: 4 }); | ||
| 265 | assert_eq!(target_at(2, 3), BetTarget::Split { a: 2, b: 5 }); | ||
| 266 | assert_eq!(target_at(22, 1), BetTarget::Split { a: 33, b: 36 }); | ||
| 267 | |||
| 268 | // Horizontal lines sit between two rows. | ||
| 269 | assert_eq!(target_at(1, 4), BetTarget::Split { a: 1, b: 2 }); | ||
| 270 | assert_eq!(target_at(3, 2), BetTarget::Split { a: 5, b: 6 }); | ||
| 271 | assert_eq!(target_at(23, 4), BetTarget::Split { a: 34, b: 35 }); | ||
| 272 | |||
| 273 | // Crossings cover four cells. | ||
| 251 | assert_eq!( | 274 | assert_eq!( |
| 252 | target_at(1, 1), | 275 | target_at(2, 4), |
| 253 | BetTarget::Corner { | 276 | BetTarget::Corner { |
| 254 | numbers: [2, 3, 5, 6] | 277 | numbers: [1, 2, 4, 5] |
| 255 | } | 278 | } |
| 256 | ); | 279 | ); |
| 257 | assert_eq!( | 280 | assert_eq!( |
| 258 | target_at(6, 2), | 281 | target_at(12, 4), |
| 259 | BetTarget::Corner { | 282 | BetTarget::Corner { |
| 260 | numbers: [16, 17, 19, 20] | 283 | numbers: [16, 17, 19, 20] |
| 261 | } | 284 | } |
| @@ -264,31 +287,54 @@ fn lattice_points_become_straights_splits_and_corners() { | |||
| 264 | 287 | ||
| 265 | #[test] | 288 | #[test] |
| 266 | fn the_cursor_walks_the_felt_and_the_outside_rows() { | 289 | fn the_cursor_walks_the_felt_and_the_outside_rows() { |
| 267 | let bottom = Cursor::Lattice { x: 0, y: 3 }; | 290 | let bottom = Cursor::Lattice { x: 1, y: 5 }; |
| 291 | // One step right is the split between 1 and 4, two steps is number 4. | ||
| 292 | assert_eq!( | ||
| 293 | bottom.moved(Direction::Right), | ||
| 294 | Cursor::Lattice { x: 2, y: 5 } | ||
| 295 | ); | ||
| 296 | assert_eq!( | ||
| 297 | bottom.moved(Direction::Right).moved(Direction::Right), | ||
| 298 | Cursor::Lattice { x: 3, y: 5 } | ||
| 299 | ); | ||
| 300 | // One step up is the split between 1 and 2. | ||
| 301 | assert_eq!(bottom.moved(Direction::Up), Cursor::Lattice { x: 1, y: 4 }); | ||
| 302 | |||
| 268 | assert_eq!(bottom.moved(Direction::Down), Cursor::Dozen(0)); | 303 | assert_eq!(bottom.moved(Direction::Down), Cursor::Dozen(0)); |
| 269 | assert_eq!( | 304 | assert_eq!( |
| 270 | Cursor::Lattice { x: 12, y: 3 }.moved(Direction::Down), | 305 | Cursor::Lattice { x: 23, y: 5 }.moved(Direction::Down), |
| 271 | Cursor::Dozen(2) | 306 | Cursor::Dozen(2) |
| 272 | ); | 307 | ); |
| 273 | assert_eq!( | 308 | assert_eq!( |
| 274 | Cursor::Lattice { x: 0, y: 0 }.moved(Direction::Up), | 309 | Cursor::Lattice { x: 1, y: 1 }.moved(Direction::Up), |
| 275 | Cursor::Zero | 310 | Cursor::Zero |
| 276 | ); | 311 | ); |
| 277 | assert_eq!(Cursor::Zero.moved(Direction::Down), Cursor::Lattice { x: 0, y: 0 }); | 312 | assert_eq!( |
| 313 | Cursor::Zero.moved(Direction::Down), | ||
| 314 | Cursor::Lattice { x: 1, y: 1 } | ||
| 315 | ); | ||
| 278 | 316 | ||
| 279 | assert_eq!(Cursor::Dozen(0).moved(Direction::Up), Cursor::Lattice { x: 1, y: 3 }); | 317 | assert_eq!( |
| 318 | Cursor::Dozen(0).moved(Direction::Up), | ||
| 319 | Cursor::Lattice { x: 1, y: 5 } | ||
| 320 | ); | ||
| 280 | assert_eq!(Cursor::Dozen(0).moved(Direction::Down), Cursor::Column(0)); | 321 | assert_eq!(Cursor::Dozen(0).moved(Direction::Down), Cursor::Column(0)); |
| 322 | assert_eq!(Cursor::Dozen(2).moved(Direction::Up), Cursor::Lattice { x: 17, y: 5 }); | ||
| 281 | assert_eq!(Cursor::Column(2).moved(Direction::Up), Cursor::Dozen(2)); | 323 | assert_eq!(Cursor::Column(2).moved(Direction::Up), Cursor::Dozen(2)); |
| 282 | assert_eq!(Cursor::Column(1).moved(Direction::Down), Cursor::Outside(2)); | 324 | assert_eq!(Cursor::Column(1).moved(Direction::Down), Cursor::Outside(2)); |
| 283 | assert_eq!(Cursor::Outside(3).moved(Direction::Up), Cursor::Column(1)); | 325 | assert_eq!(Cursor::Outside(3).moved(Direction::Up), Cursor::Column(1)); |
| 284 | 326 | ||
| 285 | // Edges stay put instead of wrapping. | 327 | // Edges stay put instead of wrapping. |
| 286 | assert_eq!(Cursor::Dozen(0).moved(Direction::Left), Cursor::Dozen(0)); | ||
| 287 | assert_eq!(Cursor::Outside(5).moved(Direction::Right), Cursor::Outside(5)); | ||
| 288 | assert_eq!( | 328 | assert_eq!( |
| 289 | Cursor::Lattice { x: 0, y: 2 }.moved(Direction::Left), | 329 | Cursor::Lattice { x: 1, y: 3 }.moved(Direction::Left), |
| 290 | Cursor::Lattice { x: 0, y: 2 } | 330 | Cursor::Lattice { x: 1, y: 3 } |
| 331 | ); | ||
| 332 | assert_eq!( | ||
| 333 | Cursor::Lattice { x: 23, y: 3 }.moved(Direction::Right), | ||
| 334 | Cursor::Lattice { x: 23, y: 3 } | ||
| 291 | ); | 335 | ); |
| 336 | assert_eq!(Cursor::Dozen(0).moved(Direction::Left), Cursor::Dozen(0)); | ||
| 337 | assert_eq!(Cursor::Outside(5).moved(Direction::Right), Cursor::Outside(5)); | ||
| 292 | } | 338 | } |
| 293 | 339 | ||
| 294 | #[test] | 340 | #[test] |
| @@ -305,6 +351,7 @@ fn every_cursor_round_trips_through_its_encoded_form() { | |||
| 305 | } | 351 | } |
| 306 | assert_eq!(Cursor::parse("nonsense"), Cursor::default()); | 352 | assert_eq!(Cursor::parse("nonsense"), Cursor::default()); |
| 307 | assert_eq!(Cursor::parse("lattice:99:0"), Cursor::default()); | 353 | assert_eq!(Cursor::parse("lattice:99:0"), Cursor::default()); |
| 354 | assert_eq!(Cursor::parse("lattice:0:1"), Cursor::default()); | ||
| 308 | assert_eq!(Cursor::parse("dozen:7"), Cursor::default()); | 355 | assert_eq!(Cursor::parse("dozen:7"), Cursor::default()); |
| 309 | } | 356 | } |
| 310 | 357 | ||
