def test_equality(self): creature_type = CreatureTypeFactory() cr1 = CreatureStateFactory(creature_type=creature_type) cr2 = CreatureStateFactory(creature_type=creature_type, controlling_player=cr1.controlling_player) self.assertEqual(cr1, cr2) cr2.controlling_player += 1 self.assertNotEqual(cr1, cr2)
def test_equality_when_different_uids(self): """Test equality when creature uids differ.""" bg1 = BattlegroundState() bg2 = BattlegroundState() uid1 = bg1.add_creature(CreatureStateFactory()) bg1.remove_creature(uid1) creature_state = CreatureStateFactory() bg1.add_creature(creature_state) bg2.add_creature(creature_state) self.assertEqual(bg1, bg2)
def test_equality_when_different_creature_order(self): """Test equality when creatures have been added in different orders.""" bg1 = BattlegroundState() bg2 = BattlegroundState() creature_state1 = CreatureStateFactory() creature_state2 = CreatureStateFactory() bg1.add_creature(creature_state1) bg1.add_creature(creature_state2) bg2.add_creature(creature_state2) bg2.add_creature(creature_state1) self.assertEqual(bg1, bg2)
def test_creature_type_attributes(self): """Test that the CreatureType attributes (power, toughness, etc.) can be accessed from a CreatureState instance.""" creature_type = CreatureTypeFactory() creature_state = CreatureStateFactory(creature_type=creature_type) self.assertEqual(creature_state.power, creature_type.power) self.assertEqual(creature_state.toughness, creature_type.toughness)
def test_serialization(self): for s in self.SERIALIZATION_FIXTURES: self.assertEqual(repr(CreatureState.from_string(s, 0)), s, 'Invalid deserialize & serialize transformation') for _ in range(5): cr = CreatureStateFactory(controlling_player=0) self.assertEqual(CreatureState.from_string(repr(cr), 0), cr)
def test_creature_accessor(self): """Test that the creatures can be accessed via their uid.""" bg = BattlegroundStateFactory() h1 = bg.normalize() uid = bg.add_creature(CreatureStateFactory()) bg[uid].tap() self.assertNotEqual(bg.normalize(), h1)
def test_tap_and_untap(self): creature_state = CreatureStateFactory(tapped=False) normalized = creature_state.normalize() creature_state.tap() self.assertNotEqual(creature_state.normalize(), normalized) normalized = creature_state.normalize() creature_state.untap() self.assertNotEqual(creature_state.normalize(), normalized)
def test_normalize(self): bg = BattlegroundState() h1 = bg.normalize() uid = bg.add_creature(CreatureStateFactory()) h2 = bg.normalize() self.assertNotEqual(h1, h2) bg.remove_creature(uid) self.assertEqual(h1, bg.normalize())
def test_attack(self): """Test that .attack() is saved when normalized.""" state = CreatureStateFactory(tapped=False) normalized = state.normalize() state.attack() self.assertTrue(state.attacking) self.assertNotEqual(state.normalize(), normalized) state.remove_from_combat() self.assertEqual(state.normalize(), normalized)
def test_get_combat_assignment(self): bg = BattlegroundState() cr1 = bg.add_creature(CreatureStateFactory()) cr2 = bg.add_creature(CreatureStateFactory()) cr3 = bg.add_creature(CreatureStateFactory()) cr4 = bg.add_creature(CreatureStateFactory()) bg[cr1].attack() bg[cr2].attack() bg[cr3].block(cr1) bg[cr4].block(cr1) combat_assignment = bg.get_combat_assignment() self.assertIsInstance(combat_assignment, CombatAssignment) self.assertEqual(len(combat_assignment), 2) expected_ca = CombatAssignment({cr1: [cr3, cr4], cr2: []}) self.assertTrue(combat_assignment.is_reorder_of(expected_ca)) self.assertIsInstance(combat_assignment[cr1], tuple)
def test_block(self): """Test that .block(uid) is saved when normalized.""" state = CreatureStateFactory(tapped=False) self.assertFalse(state.blocking) normalized = state.normalize() state.block(47) self.assertEqual(state.blocking, 47) self.assertNotEqual(state.normalize(), normalized) state.remove_from_combat() self.assertEqual(state.normalize(), normalized)