MCPcopy Index your code
hub / github.com/battlecode/battlecode-2018 / test_factory

Function test_factory

battlecode-engine/src/unit.rs:1389–1434  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1387
1388 #[test]
1389 fn test_factory() {
1390 // A worker cannot produce a robot.
1391 let loc = MapLocation::new(Planet::Earth, 0, 0);
1392 let worker = Unit::new(1, Team::Red, Worker, 0, OnMap(loc)).unwrap();
1393 assert_err!(worker.ok_if_can_produce_robot(Mage), GameError::InappropriateUnitType);
1394
1395 // A factory cannot produce a structure, but it can produce a mage.
1396 let mut factory = Unit::new(1, Team::Red, Factory, 0, OnMap(loc)).unwrap();
1397 factory.is_built = true;
1398 assert_err!(factory.factory_rounds_left(), GameError::NullValue);
1399 assert_err!(factory.ok_if_can_produce_robot(Factory), GameError::InappropriateUnitType);
1400 assert_err!(factory.ok_if_can_produce_robot(Rocket), GameError::InappropriateUnitType);
1401 assert!(factory.ok_if_can_produce_robot(Mage).is_ok());
1402
1403 // The factory cannot produce anything when it's already busy.
1404 factory.produce_robot(Mage);
1405 assert!(factory.ok_if_can_produce_robot(Mage).is_err());
1406
1407 // After a few rounds, the factory can produce again.
1408 for _ in 0..factory.factory_max_rounds_left().unwrap() - 1 {
1409 assert_eq!(factory.process_factory_round(), None);
1410 assert!(factory.ok_if_can_produce_robot(Mage).is_err());
1411 }
1412 assert_eq!(factory.process_factory_round(), Some(Mage));
1413 assert!(factory.ok_if_can_produce_robot(Mage).is_ok());
1414
1415 // Fill the factory to its max capacity.
1416 for id in 0..factory.structure_max_capacity().expect("unit has a capacity") {
1417 factory.load(id as UnitID);
1418 }
1419
1420 // The factory can produce one more robot, but it won't go in its garrison.
1421 assert!(factory.ok_if_can_produce_robot(Mage).is_ok());
1422 factory.produce_robot(Mage);
1423 for _ in 0..factory.factory_max_rounds_left().unwrap() * 2 {
1424 assert_eq!(factory.process_factory_round(), None);
1425 assert!(factory.ok_if_can_produce_robot(Mage).is_err());
1426 }
1427
1428 // After unloading the units, the factory will work again.
1429 for id in 0..factory.structure_max_capacity().expect("unit has a capacity") {
1430 assert_eq!(factory.unload_unit(), id as UnitID);
1431 }
1432 assert_eq!(factory.process_factory_round(), Some(Mage));
1433 assert!(factory.ok_if_can_produce_robot(Mage).is_ok());
1434 }
1435
1436 #[test]
1437 fn test_rockets() {

Callers

nothing calls this directly

Calls 4

produce_robotMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected