()
| 1435 | |
| 1436 | #[test] |
| 1437 | fn test_rockets() { |
| 1438 | let loc = MapLocation::new(Planet::Earth, 0, 0); |
| 1439 | let adjacent_loc = loc.add(Direction::North); |
| 1440 | let mars_loc = MapLocation::new(Planet::Mars, 0, 0); |
| 1441 | |
| 1442 | let mut rocket = Unit::new(1, Team::Red, Rocket, 0, OnMap(loc)).unwrap(); |
| 1443 | rocket.is_built = true; |
| 1444 | let mut robot = Unit::new(2, Team::Red, Mage, 0, OnMap(adjacent_loc)).unwrap(); |
| 1445 | |
| 1446 | // Rocket accessor methods should fail on a robot. |
| 1447 | assert!(robot.structure_max_capacity().is_err()); |
| 1448 | assert!(robot.rocket_is_used().is_err()); |
| 1449 | assert!(robot.structure_garrison().is_err()); |
| 1450 | assert_err!(robot.ok_if_can_launch_rocket(), GameError::InappropriateUnitType); |
| 1451 | assert!(robot.ok_if_can_unload_unit().is_err()); |
| 1452 | |
| 1453 | // Check accessor methods on the rocket. |
| 1454 | assert!(rocket.structure_max_capacity().unwrap() > 0); |
| 1455 | assert!(!rocket.rocket_is_used().unwrap()); |
| 1456 | assert_eq!(rocket.structure_garrison().unwrap().len(), 0); |
| 1457 | assert!(rocket.ok_if_can_load().is_ok()); |
| 1458 | assert!(rocket.ok_if_can_unload_unit().is_err()); |
| 1459 | assert!(rocket.ok_if_can_launch_rocket().is_ok()); |
| 1460 | |
| 1461 | // Load a unit and launch into space. |
| 1462 | rocket.load(robot.id()); |
| 1463 | assert_eq!(rocket.structure_garrison().unwrap(), vec![robot.id()]); |
| 1464 | assert!(rocket.ok_if_can_unload_unit().is_ok()); |
| 1465 | |
| 1466 | rocket.launch_rocket(); |
| 1467 | assert_eq!(rocket.location(), InSpace); |
| 1468 | assert!(rocket.rocket_is_used().unwrap()); |
| 1469 | |
| 1470 | // Proceed a round, then land the rocket. |
| 1471 | robot.end_round(); |
| 1472 | rocket.end_round(); |
| 1473 | rocket.land_rocket(mars_loc); |
| 1474 | assert_eq!(rocket.location(), OnMap(mars_loc)); |
| 1475 | |
| 1476 | // Unload the unit. |
| 1477 | assert!(rocket.ok_if_can_unload_unit().is_ok()); |
| 1478 | assert_eq!(rocket.unload_unit(), robot.id()); |
| 1479 | assert!(!rocket.ok_if_can_unload_unit().is_ok()); |
| 1480 | |
| 1481 | // Load too many units |
| 1482 | for i in 0..rocket.structure_max_capacity().unwrap() { |
| 1483 | assert!(rocket.ok_if_can_load().is_ok(), "failed to load unit {}", i); |
| 1484 | rocket.load(0); |
| 1485 | } |
| 1486 | assert!(rocket.ok_if_can_load().is_err()); |
| 1487 | } |
| 1488 | |
| 1489 | #[test] |
| 1490 | fn test_research() { |
nothing calls this directly
no test coverage detected