battleship game in rust

Format document

authored by pebloop.dev and committed by

knot.nasso.dev 368c7124 994c4400

+28 -14
+28 -14
src/parser.rs
··· 22 22 23 23 impl Vector2u16 { 24 24 pub fn new(x: u16, y: u16) -> Self { 25 - Vector2u16 {x: x, y: y} 25 + Vector2u16 { x: x, y: y } 26 26 } 27 27 } 28 28 ··· 34 34 35 35 impl Boat { 36 36 pub fn new(first_pos: Vector2u16, last_pos: Vector2u16) -> Self { 37 - Boat { first_pos: first_pos, last_pos: last_pos } 37 + Boat { 38 + first_pos: first_pos, 39 + last_pos: last_pos, 40 + } 38 41 } 39 42 } 40 43 ··· 70 73 return Err(ParserError::InvalidCoordCount); 71 74 } 72 75 73 - 74 - Ok(Boat::new(create_coord(coordinates[0])?, create_coord(coordinates[1])?)) 76 + Ok(Boat::new( 77 + create_coord(coordinates[0])?, 78 + create_coord(coordinates[1])?, 79 + )) 75 80 } 76 81 77 82 fn create_coord(coord_str: &str) -> Result<Vector2u16, ParserError> { ··· 92 97 } 93 98 94 99 Ok(Vector2u16::new(col, row)) 95 - 96 100 } 97 101 98 102 #[cfg(test)] ··· 112 116 assert_eq!(coord2.y, 0); 113 117 114 118 let coord3 = create_coord("H8")?; 115 - 119 + 116 120 assert_eq!(coord3.x, 7); 117 121 assert_eq!(coord3.y, 7); 118 122 ··· 136 140 #[test] 137 141 fn test_create_ship() -> Result<(), ParserError> { 138 142 let ship = create_ship("C4:B1")?; 139 - 143 + 140 144 assert_eq!(ship.first_pos.x, 2); 141 145 assert_eq!(ship.first_pos.y, 3); 142 146 assert_eq!(ship.last_pos.x, 1); ··· 159 163 160 164 let ships = parse_ships(&mut &file[..])?; 161 165 162 - assert_eq!(ships[0], Boat::new(Vector2u16::new(1, 3), Vector2u16::new(2, 1))); 163 - assert_eq!(ships[1], Boat::new(Vector2u16::new(3, 0), Vector2u16::new(5, 2))); 164 - assert_eq!(ships[2], Boat::new(Vector2u16::new(5, 0), Vector2u16::new(5, 4))); 165 - assert_eq!(ships[3], Boat::new(Vector2u16::new(0, 0), Vector2u16::new(0, 1))); 166 + assert_eq!( 167 + ships[0], 168 + Boat::new(Vector2u16::new(1, 3), Vector2u16::new(2, 1)) 169 + ); 170 + assert_eq!( 171 + ships[1], 172 + Boat::new(Vector2u16::new(3, 0), Vector2u16::new(5, 2)) 173 + ); 174 + assert_eq!( 175 + ships[2], 176 + Boat::new(Vector2u16::new(5, 0), Vector2u16::new(5, 4)) 177 + ); 178 + assert_eq!( 179 + ships[3], 180 + Boat::new(Vector2u16::new(0, 0), Vector2u16::new(0, 1)) 181 + ); 166 182 167 183 Ok(()) 168 184 } 169 - 170 - 171 - } 185 + }