def testTankDoesNotEqualModifiedTank(self): modified = types.new_unit('Tank', consts.RED) modified.health -= 1 self.assertNotEqual(modified, types.new_unit('Tank', consts.RED)) modified = types.new_unit('Tank', consts.RED) modified.armor[0] = 1000.0 self.assertNotEqual(modified, types.new_unit('Tank', consts.RED))
def oneVsOther(self, AttackUnit, DefendUnit, delta, start_damage=0): attack_unit = types.new_unit(AttackUnit, consts.RED) attack_unit.health -= start_damage expected_attack_unit = types.new_unit(AttackUnit, consts.RED) expected_attack_unit.health -= start_damage defend_unit = types.new_unit(DefendUnit, consts.BLUE) expected_defend_unit = types.new_unit(DefendUnit, consts.BLUE) expected_defend_unit.health -= delta control.DoDamage(attack_unit, defend_unit) self.assertEqual(attack_unit, expected_attack_unit) self.assertEqual(defend_unit, expected_defend_unit)
def testPlayerGetUnit(self): player_ = player.Player(1) tank = types.new_unit('Tank', consts.RED) player_.add_unit(tank, 1) returned_tank = player_.get_unit(1) self.assertEqual(returned_tank, tank) self.assertRaises(Exception, player_.get_unit, 2)
def testRecon(self): recon = types.new_unit('Recon', consts.RED) self.assertEqual(recon.health, 10) self.assertEqual(recon.attacks, [types.new_attack('DoubleMachineGun')]) self.assertEqual(recon.armor, types.new_armor('WeakMetal')) self.assertEqual(recon.movement, types.new_movement('Tires')) self.assertEqual(recon.distance, 9)
def testInfantry(self): inf = types.new_unit('Infantry', consts.RED) self.assertEqual(inf.health, 10) self.assertEqual(inf.attacks, [types.new_attack('MachineGun')]) self.assertEqual(inf.armor, types.new_armor('BodyArmor')) self.assertEqual(inf.movement, types.new_movement('Feet')) self.assertEqual(inf.distance, 3)
def testWorldMove(self): world_ = world.World([13, 26]) world_.add_unit(13, types.new_unit('Tank', consts.RED)) self.assertEqual(world_.move_unit(13, 0, [(1, 1)]), True) self.assertEqual(world_.move_unit(13, 0, [(1, 1), (2, 2)]), False) self.assertEqual( world_.move_unit(13, 0, [(1, 1), (1, 2), (2, 2)]), True)
def testTank(self): tank = types.new_unit('Tank', consts.RED) self.assertEqual(tank.health, 10) self.assertEqual( tank.attacks, [types.new_attack('RegularCannon'), types.new_attack('MachineGun')]) self.assertEqual(tank.armor, types.new_armor('HeavyMetal')) self.assertEqual(tank.movement, types.new_movement('Treads')) self.assertEqual(tank.distance, 7)
def testPlayerAddUnit(self): player_ = player.Player(1) tank = types.new_unit('Tank', consts.RED) player_.add_unit(tank, 1) self.assertEqual(player_.units, {1: tank})
def testWorldAddUnit(self): world_ = world.World([13, 26]) tank = types.new_unit('Tank', consts.RED) world_.add_unit(26, tank) self.assertEqual(world_.get_player(26).units[0], tank)
def testSerializeTank(self): tank = types.new_unit('Tank', consts.RED) self.assertEqual(tank.serialize(True), {'name': 'Tank', 'health': 10})
def testTankDoesNotEqualRecon(self): self.assertNotEqual( types.new_unit('Tank', consts.RED), types.new_unit('Recon', consts.RED))
def testTankEqualsTank(self): self.assertEqual(types.new_unit('Tank', consts.RED), types.new_unit('Tank', consts.RED))