|
1 | 1 | #[cfg(test)] |
2 | 2 | mod tests { |
3 | | - use crate::plugin2026::field_type::FieldType; |
4 | | - use crate::plugin2026::test::common::*; |
5 | | - use crate::plugin2026::utils::coordinate::Coordinate; |
6 | | - use crate::plugin2026::utils::direction::Direction; |
7 | | - |
| 3 | + use crate::plugin2026::{ |
| 4 | + field_type::FieldType, test::common::*, utils::{ |
| 5 | + coordinate::Coordinate, |
| 6 | + direction::Direction |
| 7 | + } |
| 8 | + }; |
| 9 | + |
8 | 10 | #[test] |
9 | | - pub fn test01() { |
| 11 | + pub fn get_field_test() { |
10 | 12 | let b = create_test_board(); |
11 | 13 |
|
12 | | - println!("{}", b); |
| 14 | + assert_eq!(b.get_field(&Coordinate { x: 0, y: 4 }), Some(FieldType::OneS)); |
| 15 | + assert_eq!(b.get_field(&Coordinate { x: 7, y: 0 }), Some(FieldType::TwoL)); |
| 16 | + assert_eq!(b.get_field(&Coordinate { x: 3, y: 3 }), Some(FieldType::Empty)); |
| 17 | + assert_eq!(b.get_field(&Coordinate { x: 6, y: 2 }), Some(FieldType::Squid)); |
| 18 | + assert_eq!(b.get_field(&Coordinate { x: -2, y: 0 }), None); // out of bounds |
| 19 | + } |
| 20 | + |
| 21 | + #[test] |
| 22 | + pub fn get_fields_by_type_test() { |
| 23 | + let mut b = create_test_board(); |
| 24 | + |
| 25 | + // remove squids |
| 26 | + b.map[2][6] = FieldType::Empty; |
| 27 | + b.map[7][3] = FieldType::Empty; |
| 28 | + |
| 29 | + let one_s_positions = vec![ |
| 30 | + Coordinate {x: 0, y: 2}, |
| 31 | + Coordinate {x: 9, y: 2}, |
| 32 | + Coordinate {x: 0, y: 4}, |
| 33 | + Coordinate {x: 0, y: 6}, |
| 34 | + Coordinate {x: 9, y: 7}, |
| 35 | + Coordinate {x: 0, y: 8}, |
| 36 | + Coordinate {x: 9, y: 8}, |
| 37 | + ]; |
13 | 38 |
|
14 | | - for variant in Direction::all_directions() { |
15 | | - let c = Coordinate {x: 2, y: 1}; |
16 | | - let f = b.get_fields_in_direction(&c, &variant); |
17 | | - |
18 | | - print!("[ "); |
19 | | - for field in &f { |
20 | | - print!("{} ", field); |
| 39 | + assert_eq!(b.get_fields_by_type(FieldType::OneS), one_s_positions); |
| 40 | + assert_eq!(b.get_fields_by_type(FieldType::Squid), vec![]); |
| 41 | + } |
| 42 | + |
| 43 | + #[test] |
| 44 | + pub fn get_fields_in_direction_test() { |
| 45 | + let b = create_test_board(); |
| 46 | + let start = Coordinate {x: 2, y: 6}; |
| 47 | + |
| 48 | + for d in Direction::all_directions() { |
| 49 | + match d { |
| 50 | + Direction::Up => assert_eq!(b.get_fields_in_direction(&start, &d), vec![ |
| 51 | + FieldType::Empty, FieldType::Empty, FieldType::TwoS |
| 52 | + ]), |
| 53 | + Direction::UpRight => assert_eq!(b.get_fields_in_direction(&start, &d), vec![ |
| 54 | + FieldType::Squid, FieldType::Empty, FieldType::TwoM |
| 55 | + ]), |
| 56 | + Direction::Right => assert_eq!(b.get_fields_in_direction(&start, &d), vec![ |
| 57 | + FieldType::Empty, FieldType::Empty, FieldType::Empty, |
| 58 | + FieldType::Empty, FieldType::Empty, FieldType::Empty, FieldType::OneM |
| 59 | + ]), |
| 60 | + Direction::DownRight => assert_eq!(b.get_fields_in_direction(&start, &d), vec![ |
| 61 | + FieldType::Empty, FieldType::Empty, FieldType::Empty, |
| 62 | + FieldType::Squid, FieldType::Empty, FieldType::TwoS |
| 63 | + ]), |
| 64 | + Direction::Down => assert_eq!(b.get_fields_in_direction(&start, &d), vec![ |
| 65 | + FieldType::Empty, FieldType::Empty, FieldType::Empty, |
| 66 | + FieldType::Empty, FieldType::Empty, FieldType::TwoS |
| 67 | + ]), |
| 68 | + Direction::DownLeft => assert_eq!(b.get_fields_in_direction(&start, &d), vec![ |
| 69 | + FieldType::Empty, FieldType::OneS |
| 70 | + ]), |
| 71 | + Direction::Left => assert_eq!(b.get_fields_in_direction(&start, &d), vec![ |
| 72 | + FieldType::Empty, FieldType::OneS |
| 73 | + ]), |
| 74 | + Direction::UpLeft => assert_eq!(b.get_fields_in_direction(&start, &d), vec![ |
| 75 | + FieldType::Empty, FieldType::OneS |
| 76 | + ]), |
21 | 77 | } |
22 | | - print!("] {} {}", c, variant); |
23 | | - println!(); |
24 | 78 | } |
| 79 | + } |
25 | 80 |
|
26 | | - let mut sum = 0; |
| 81 | + #[test] |
| 82 | + pub fn get_fields_on_line_test() { |
| 83 | + let b = create_test_board(); |
| 84 | + let start = Coordinate {x: 2, y: 7}; |
| 85 | + let direction = Direction::Right; |
27 | 86 |
|
28 | | - for fvarient in FieldType::all_field_types() { |
29 | | - let f = b.get_fields_by_type(fvarient); |
30 | | - |
31 | | - print!("[ "); |
32 | | - for field in &f { |
33 | | - print!("{} ", field); |
34 | | - } |
35 | | - print!("]"); |
36 | | - println!(); |
| 87 | + assert_eq!(b.get_fields_on_line(&start, &direction), vec![ |
| 88 | + FieldType::OneL, FieldType::Empty, FieldType::Empty, |
| 89 | + FieldType::Squid, FieldType::Empty, FieldType::Empty, |
| 90 | + FieldType::Empty, FieldType::Empty, FieldType::Empty, FieldType::OneS |
| 91 | + ]); |
| 92 | + } |
37 | 93 |
|
38 | | - sum += f.len(); |
39 | | - } |
| 94 | + #[test] |
| 95 | + pub fn get_fish_on_line_test() { |
| 96 | + let b = create_test_board(); |
| 97 | + let start = Coordinate {x: 2, y: 7}; |
| 98 | + let direction = Direction::Right; |
40 | 99 |
|
41 | | - println!("{}", sum); |
| 100 | + assert_eq!(b.get_fish_on_line(&start, &direction), vec![ |
| 101 | + FieldType::OneL, FieldType::OneS |
| 102 | + ]); |
42 | 103 | } |
43 | 104 | } |
0 commit comments