Пример #1
0
    def test_privileges(self):
        # Werewolf tests
        self.assertTrue(IdentityMapper.can_kill(NotedPlayers.WEREWOLF))
        self.assertFalse(IdentityMapper.can_check(NotedPlayers.WEREWOLF))
        self.assertFalse(IdentityMapper.can_guard(NotedPlayers.WEREWOLF))

        # Seer tests
        self.assertFalse(IdentityMapper.can_kill(NotedPlayers.SEER))
        self.assertTrue(IdentityMapper.can_check(NotedPlayers.SEER))
        self.assertFalse(IdentityMapper.can_guard(NotedPlayers.SEER))

        # Witch tests
        self.assertTrue(IdentityMapper.can_kill(NotedPlayers.WITCH))
        self.assertFalse(IdentityMapper.can_check(NotedPlayers.WITCH))
        self.assertTrue(IdentityMapper.can_guard(NotedPlayers.WITCH))
Пример #2
0
class IdentityMapperTests(unittest.TestCase):
    def setUp(self):
        self.id_accountant = IdentityMapper()

    def test_villager_equality(self):
        """
        No matter what happens, two different villager instances (even with the
        same name and role), should not hash to the same dictionary slot for the
        Python implementation on which this code will run.
        """
        jango = WerewolfAI("Jango")
        clone_trooper = WerewolfAI("Jango")

        dummy_map = {}
        dummy_map[jango] = "Clone"
        dummy_map[clone_trooper] = "Trooper"

        self.assertNotEqual(dummy_map[jango], dummy_map[clone_trooper])

    def test_registration(self):
        # You shall not pass (the registration, throw exception)!
        dirty_name = "sauron" + IdentityMapper.RECORD_SEPARATOR
        dirty_name_villager = Villager(dirty_name)

        self.assertRaises(RegistrationError, self.id_accountant.register_identity, dirty_name_villager)

        dirty_job = IdentityMapper.RECORD_SEPARATOR + "balrog"
        dirty_job_villager = Villager("sauron", dirty_job)

        self.assertRaises(RegistrationError, self.id_accountant.register_identity, dirty_job_villager)

        # Ordinary cases
        # Test registration of all roles and ensure that they get the proper privileges
        normal_werewolf = WerewolfAI("fenrir")
        self.id_accountant.register_identity(normal_werewolf)
        self.assertEqual(
            self.id_accountant.get_privileges(normal_werewolf), IdentityMapper.PRIVILEGE_TABLE[NotedPlayers.WEREWOLF]
        )
Пример #3
0
 def setUp(self):
     self.id_accountant = IdentityMapper()