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_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_monster(self): attacker = Goblin() set_values([1]) with patch('game_engine.dice._random_int', side_effect=value): self.assertEqual( 3, roll_damage(attacker, None, attacker.get_actions()[0], HitType.HIT, None))
def test_goblin_attack_player(self): attacker = Goblin() target = Player('Bob', [10, 10, 10, 10, 10, 10], Human(), Fighter()) target.set_armor(armors[ArmorId.CHAIN_SHIRT]) target.set_left_hand(armors[ArmorId.SHIELD]) set_values([11]) with patch('game_engine.dice._random_int', side_effect=value): self.assertEqual(roll_to_hit(attacker, target, attacker.get_actions()[0], None), HitType.HIT)
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_goblin_stats(self): g = Goblin() self.assertEqual(g.get_str(), 8) self.assertEqual(g.get_dex(), 14) self.assertEqual(g.get_con(), 10) self.assertEqual(g.get_int(), 10) self.assertEqual(g.get_wis(), 8) self.assertEqual(g.get_cha(), 8)
def test_goblin_str_mod(self): g = Goblin() self.assertEqual(g.get_str_mod(), -1) self.assertEqual(g.get_dex_mod(), 2) self.assertEqual(g.get_con_mod(), 0) self.assertEqual(g.get_int_mod(), 0) self.assertEqual(g.get_wis_mod(), -1) self.assertEqual(g.get_cha_mod(), -1)
def test_unproficient_armor(self): attacker = Player('Bob', [10, 10, 17, 17, 17, 17], Human(), Rogue()) target = Goblin() attacker.set_armor(armors[ArmorId.PLATE]) set_values([20, 3]) with patch('game_engine.dice._random_int', side_effect=value): self.assertEqual(roll_to_hit(attacker, target, weapons[WeaponId.DAGGER], None), HitType.MISS)
def test_lucky(self): attacker = Player('Bob', [10, 10, 10, 10, 10, 10], StoutHalfling(), Fighter()) target = Goblin() attack = weapons[WeaponId.DAGGER] set_values([1, 17]) with patch('game_engine.dice._random_int', side_effect=value): self.assertEqual(roll_to_hit(attacker, target, attack, None), HitType.HIT)
def test_fs_archery(self): attacker = Player('Bob', [10, 10, 17, 17, 17, 17], Human(), Fighter()) attacker.add_fighting_style(Trait.FIGHTING_STYLE_ARCHERY) target = Goblin() set_values([11]) with patch('game_engine.dice._random_int', side_effect=value): self.assertEqual(roll_to_hit(attacker, target, weapons[WeaponId.SHORTBOW], None), HitType.HIT)
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_critical_miss(self): attacker = Player('Bob', [10, 10, 10, 10, 10, 10], Human(), Fighter()) target = Goblin() attack = weapons[WeaponId.DAGGER] set_values([1]) with patch('game_engine.dice._random_int', side_effect=value): self.assertEqual(roll_to_hit(attacker, target, attack, None), HitType.CRITICAL_MISS)
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_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_proficieny_matters_not_rogue(self): # makes sure to use the higher mod to be able to hit # goblin AC is 15 # rolls a 13 attacker = Player('Bob', [10, 10, 17, 17, 17, 17], Human(), Rogue()) target = Goblin() attack = weapons[WeaponId.MAUL] set_values([13]) with patch('game_engine.dice._random_int', side_effect=value): self.assertEqual(roll_to_hit(attacker, target, attack, None), HitType.MISS)
def test_proficieny_matters(self): # makes sure to use the higher mod to be able to hit # goblin AC is 15 # proficiency is +2 # rolls a 13 attacker = Player('Bob', [10, 10, 17, 17, 17, 17], StoutHalfling(), Fighter()) target = Goblin() attack = weapons[WeaponId.DAGGER] set_values([13]) with patch('game_engine.dice._random_int', side_effect=value): self.assertEqual(roll_to_hit(attacker, target, attack, None), HitType.HIT)
def test_ranged(self): # will hit if using the dex bonus not the str bonus (or no bonus for that matter) # goblin AC is 15 # proficiency is +2 # rolls a 10 # needs a dex mod of +3 to hit attacker = Player('Bob', [10, 17, 10, 10, 10, 10], StoutHalfling(), Fighter()) target = Goblin() attack = weapons[WeaponId.LIGHT_CROSSBOW] set_values([10]) with patch('game_engine.dice._random_int', side_effect=value): self.assertEqual(roll_to_hit(attacker, target, attack, None), HitType.HIT)
def test_goblin_initiative_patch(self): g = Goblin() with patch('game_engine.dice._random_int') as mock_roll: mock_roll.return_value = 10 self.assertEqual(g.roll_initiative(), 12)
def test_rounding_str_mod(self): g = Goblin() g.str = 13 # just for testing self.assertEqual(g.get_str_mod(), 1)
def test_get_ac(self): g = Goblin() self.assertEqual(g.get_ac(), 15)
def test_create_arena(self): f1 = Faction('Goblins', [Goblin()]) f2 = Faction('Orcs', [Orc()]) a = Arena([f1, f2]) self.assertIsNotNone(a)
def test_goblin_initiative(self): g = Goblin() # goblin dex mod self.assertTrue(3 <= g.roll_initiative() <= 22)
def test_get_hd(self): g = Goblin() self.assertEqual(g.get_hd(), '2d6')
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)
def test_goblin_actions(self): g = Goblin() self.assertIsInstance(g.get_actions()[0], Scimitar)
def test_get_hp(self): g = Goblin() self.assertTrue(2 <= g.get_hp() <= 12)
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_natural_1(self): attacker = Player('Bob', [18, 18, 17, 17, 17, 17], Human(), Fighter()) target = Goblin() set_values([1]) with patch('game_engine.dice._random_int', side_effect=value): self.assertEqual(roll_to_hit(attacker, target, weapons[WeaponId.DAGGER], None), HitType.CRITICAL_MISS)