def test_get_winning_faction(self): f1 = Faction('Goblins', [Goblin(), Goblin()]) f2 = Faction('Orcs', [Orc(), Orc()]) a = Arena([f1, f2]) f1.get_entities()[0].state = EntityState.DEAD f1.get_entities()[1].state = EntityState.DEAD self.assertEqual(a.get_winning_faction(), f2)
def test_get_opposing_factions(self): f1 = Faction('Goblins', [Goblin()]) f2 = Faction('Orcs', [Orc()]) f3 = Faction('More Bad Orcs', [Orc()]) a = Arena([f1, f2, f3]) opposing = a.get_opposing_factions(f1) self.assertNotIn(f1, opposing)
def test_is_over(self): f1 = Faction('Goblins', [Goblin(), Goblin()]) f2 = Faction('Orcs', [Orc(), Orc()]) a = Arena([f1, f2]) f1.get_entities()[0].state = EntityState.DEAD f1.get_entities()[1].state = EntityState.DEAD self.assertTrue(a.is_over())
def test_death(self): s = Scimitar() o = Orc() with patch('game_engine.dice._random_int') as mock_roll: mock_roll.return_value = 100 # rolling 100 on a d6? Anyway this will kill the orc s.roll_damage(o) self.assertTrue(o.get_cur_hp() < 1) self.assertEqual(o.get_state(), EntityState.DEAD)
def test_roll_damage(self): s = Scimitar() o = Orc() with patch('game_engine.dice._random_int') as mock_roll: mock_roll.return_value = 3 # means 5 damage s.roll_damage(o) self.assertEqual(o.get_cur_hp(), o.get_hp() - 5) self.assertEqual(o.get_state(), EntityState.NORMAL)
def test_critical_hit(self): s = Scimitar() o = Orc() # dice rolls for a critical hit and then max damage of 18 set_values([20, 8, 8]) with patch('game_engine.dice._random_int', side_effect=value): hit = s.roll_to_hit(o) s.roll_damage(o, hit) self.assertEqual(o.cur_hp, o.get_hp() - 18)
def test_all_factions_dead(self): f1 = Faction('Goblins', [Goblin(), Goblin()]) f2 = Faction('Orcs', [Orc(), Orc()]) a = Arena([f1, f2]) f1.get_entities()[0].state = EntityState.DEAD f1.get_entities()[1].state = EntityState.DEAD f2.get_entities()[0].state = EntityState.DEAD f2.get_entities()[1].state = EntityState.DEAD self.assertIsNone(a.get_winning_faction())
def test_is_not_over(self): f1 = Faction('Goblins', [Goblin(), Goblin()]) f2 = Faction('Orcs', [Orc(), Orc()]) f3 = Faction('More Bad Orcs', [Orc(), Orc()]) a = Arena([f1, f2, f3]) # kill the first faction and then one from the other two f1.get_entities()[0].state = EntityState.DEAD f1.get_entities()[1].state = EntityState.DEAD f2.get_entities()[0].state = EntityState.DEAD f3.get_entities()[1].state = EntityState.DEAD self.assertFalse(a.is_over())
def test_random_target(self): g = Goblin() o1 = Orc() o2 = Orc() o3 = Orc() goblins = Faction('Goblins', [g]) orcs = Faction('Orcs', [o1, o2, o3]) arena = Arena([goblins, orcs]) # this is only for testing, need to set the arena on the goblin # normally this would happen via the take_turn method g.arena = arena g.select_target(TargetStrategy.RANDOM) self.assertTrue(g.target is not None) self.assertIn(g.target, [o1, o2, o3])
def test_roll_to_hit_critical(self): s = Scimitar() o = Orc() with patch('game_engine.dice._random_int') as mock_roll: mock_roll.return_value = 20 roll = s.roll_to_hit(o) self.assertEqual(roll, HitType.CRITICAL_HIT)
def test_roll_to_hit(self): s = Scimitar() o = Orc() with patch('game_engine.dice._random_int') as mock_roll: mock_roll.return_value = 3 roll = s.roll_to_hit(o) self.assertEqual(roll, HitType.MISS)
def test_initiative(self): f1 = Faction('Goblins', [Goblin()]) f2 = Faction('Orcs', [Orc()]) a = Arena([f1, f2]) with patch('game_engine.dice._random_int') as mock_roll: mock_roll.return_value = 10 a.determine_initiative_order() self.assertIsInstance(a.get_init_order()[0], Goblin) self.assertIsInstance(a.get_init_order()[1], Orc)
def test_goblin_vs_orc(self): # this means hp rolls, initiative rolls, to hit roll and damage rolls until one dead set_values([3, 3, 4, 4, 20, 10, 10, 3, 10, 8]) with patch('game_engine.dice._random_int', side_effect=value): f1 = Faction('Goblins', [Goblin()]) f2 = Faction('Orcs', [Orc()]) game = Game([f1, f2]) winner = game.play() self.assertEqual(winner.get_name(), 'Orcs')
def test_create_arena(self): f1 = Faction('Goblins', [Goblin()]) f2 = Faction('Orcs', [Orc()]) a = Arena([f1, f2]) self.assertIsNotNone(a)
def test_miss_damage(self): s = Scimitar() o = Orc() s.roll_damage(o, HitType.MISS) self.assertEqual(o.get_cur_hp(), o.get_hp())
def test_create_orc(self): o = Orc() self.assertIsNotNone(o)
def test_no_winning_faction_yet(self): f1 = Faction('Goblins', [Goblin(), Goblin()]) f2 = Faction('Orcs', [Orc(), Orc()]) a = Arena([f1, f2]) self.assertIsNone(a.get_winning_faction())
def test_goblin_attack_orc(self): attacker = Goblin() target = Orc() set_values([13]) with patch('game_engine.dice._random_int', side_effect=value): self.assertEqual(roll_to_hit(attacker, target, attacker.get_actions()[0], None), HitType.HIT)