()
| 3267 | |
| 3268 | #[test] |
| 3269 | fn test_replicate() { |
| 3270 | let mut world = GameWorld::test_world(); |
| 3271 | let worker = world.create_unit(Team::Red, MapLocation::new(Planet::Earth, 0, 0), UnitType::Worker).unwrap(); |
| 3272 | let _ = world.create_unit(Team::Blue, MapLocation::new(Planet::Earth, 1, 0), UnitType::Factory).unwrap(); |
| 3273 | |
| 3274 | // The worker cannot replicate to the west, because that space is off the map. |
| 3275 | assert![!world.can_replicate(worker, Direction::West)]; |
| 3276 | assert_err![world.replicate(worker, Direction::West), GameError::Overheated]; |
| 3277 | world.end_round(); |
| 3278 | assert_err![world.replicate(worker, Direction::West), GameError::LocationOffMap]; |
| 3279 | |
| 3280 | // The worker cannot replicate to the east, because that space is obstructed. |
| 3281 | assert![!world.can_replicate(worker, Direction::East)]; |
| 3282 | assert_err![world.replicate(worker, Direction::East), GameError::LocationNotEmpty]; |
| 3283 | |
| 3284 | // The worker can replicate to the north. |
| 3285 | assert![world.can_replicate(worker, Direction::North)]; |
| 3286 | assert![world.replicate(worker, Direction::North).is_ok()]; |
| 3287 | assert_eq![world.karbonite(), 93]; |
| 3288 | |
| 3289 | // The child cannot replicate when there isn't enough Karbonite. |
| 3290 | world.my_team_mut().karbonite = 0; |
| 3291 | let child = world.sense_unit_at_location(MapLocation::new(Planet::Earth, 0, 1)).unwrap().unwrap().id(); |
| 3292 | world.end_round(); |
| 3293 | assert![!world.can_replicate(child, Direction::North)]; |
| 3294 | assert_err![world.replicate(child, Direction::North), GameError::InsufficientKarbonite]; |
| 3295 | |
| 3296 | // After acquiring more Karbonite, replication is possible. |
| 3297 | world.my_team_mut().karbonite += 1000; |
| 3298 | assert![world.can_replicate(child, Direction::North)]; |
| 3299 | assert![world.replicate(child, Direction::North).is_ok()]; |
| 3300 | |
| 3301 | // The child cannot replicate again this round. |
| 3302 | assert![!world.can_replicate(child, Direction::East)]; |
| 3303 | assert_err![world.replicate(child, Direction::East), GameError::Overheated]; |
| 3304 | |
| 3305 | // Even after ending the round, the child cannot replicate immediately again. |
| 3306 | world.end_round(); |
| 3307 | assert![!world.can_replicate(child, Direction::East)]; |
| 3308 | assert_err![world.replicate(child, Direction::East), GameError::Overheated]; |
| 3309 | } |
| 3310 | |
| 3311 | #[test] |
| 3312 | fn test_repair() { |
nothing calls this directly
no test coverage detected