()
| 2915 | |
| 2916 | #[test] |
| 2917 | fn test_rocket_failure() { |
| 2918 | // Create the game world. |
| 2919 | let mut world = GameWorld::test_world(); |
| 2920 | let earth_loc_a = MapLocation::new(Planet::Earth, 0, 0); |
| 2921 | let earth_loc_b = MapLocation::new(Planet::Earth, 0, 2); |
| 2922 | let mars_loc_off_map = MapLocation::new(Planet::Mars, 10000, 10000); |
| 2923 | let mars_loc_impassable = MapLocation::new(Planet::Mars, 0, 0); |
| 2924 | world.planet_maps.get_mut(&Planet::Mars).unwrap().is_passable_terrain[0][0] = false; |
| 2925 | let mars_loc_knight = MapLocation::new(Planet::Mars, 0, 1); |
| 2926 | let mars_loc_factory = MapLocation::new(Planet::Mars, 0, 2); |
| 2927 | let rocket_a = world.create_unit(Team::Red, earth_loc_a, UnitType::Rocket).unwrap(); |
| 2928 | world.get_unit_mut(rocket_a).unwrap().be_built(1000); |
| 2929 | let rocket_b = world.create_unit(Team::Red, earth_loc_b, UnitType::Rocket).unwrap(); |
| 2930 | world.get_unit_mut(rocket_b).unwrap().be_built(1000); |
| 2931 | let knight = world.create_unit(Team::Blue, mars_loc_knight, UnitType::Knight).unwrap(); |
| 2932 | let factory = world.create_unit(Team::Blue, mars_loc_factory, UnitType::Factory).unwrap(); |
| 2933 | |
| 2934 | // Failed launches. |
| 2935 | assert![!world.can_launch_rocket(rocket_a, earth_loc_b)]; |
| 2936 | assert_err![world.launch_rocket(rocket_a, earth_loc_b), GameError::SamePlanet]; |
| 2937 | assert![!world.can_launch_rocket(rocket_a, mars_loc_off_map)]; |
| 2938 | assert_err![world.launch_rocket(rocket_a, mars_loc_off_map), GameError::LocationOffMap]; |
| 2939 | assert![!world.can_launch_rocket(rocket_a, mars_loc_impassable)]; |
| 2940 | assert_err![world.launch_rocket(rocket_a, mars_loc_impassable), GameError::LocationNotEmpty]; |
| 2941 | |
| 2942 | // Rocket landing on a robot should destroy the robot. |
| 2943 | assert![world.can_launch_rocket(rocket_a, mars_loc_knight)]; |
| 2944 | assert![world.launch_rocket(rocket_a, mars_loc_knight).is_ok()]; |
| 2945 | world.end_turn(FILLER_TIME); |
| 2946 | world.end_turn(FILLER_TIME); |
| 2947 | world.land_rocket(rocket_a, mars_loc_knight); |
| 2948 | assert![world.my_unit(rocket_a).is_ok()]; |
| 2949 | world.end_turn(FILLER_TIME); |
| 2950 | assert_err![world.my_unit(knight), GameError::NoSuchUnit]; |
| 2951 | |
| 2952 | // Launch the rocket on Earth. |
| 2953 | world.end_turn(FILLER_TIME); |
| 2954 | assert![world.can_launch_rocket(rocket_b, mars_loc_factory)]; |
| 2955 | assert![world.launch_rocket(rocket_b, mars_loc_factory).is_ok()]; |
| 2956 | |
| 2957 | // Go forward two turns so that we're on Mars. |
| 2958 | world.end_turn(FILLER_TIME); |
| 2959 | world.end_turn(FILLER_TIME); |
| 2960 | |
| 2961 | // Rocket landing on a factory should destroy both units. |
| 2962 | world.land_rocket(rocket_b, mars_loc_factory); |
| 2963 | assert_err![world.my_unit(rocket_b), GameError::NoSuchUnit]; |
| 2964 | assert_err![world.my_unit(factory), GameError::NoSuchUnit]; |
| 2965 | } |
| 2966 | |
| 2967 | #[test] |
| 2968 | fn test_rocket_load() { |
nothing calls this directly
no test coverage detected