예제 #1
0
class TestTeam(unittest.TestCase):
    """
    A test class for the Team module.
    """

    def setUp(self):
        """
        set up data used in the tests.
        setUp is called before each test function execution.
        """        
        self.maxSnails = 3
        self.team1 = Team("team1")
        self.team2 = Team("team2")
        self.team1.setGravity(Direction.UP)
        self.team2.setGravity(Direction.DOWN)
        
    def testInitialized(self):
        """
        Test if init goes good
        """
        self.assertEqual(self.team1.name, "team1")
        self.assertEqual(self.team1.hasTurn, False)
    
    def testAddSnails(self):
        self.team1.addSnails(self.maxSnails)
        self.assertEquals(self.team1.currentSnailWithTurn, self.team1.orderedSnailList[0])
        self.assertEqual(len(self.team1.sprites()), self.maxSnails)
        self.assertEqual(len(self.team1.orderedSnailList), self.maxSnails)
        self.assertEqual(self.team1.orderedSnailList[0].hasTurn, True)
        for i in range(0, len(self.team1.orderedSnailList)):
            if i == 0:
                self.assertEqual(self.team1.orderedSnailList[i].hasTurn, True)
            else:
                self.assertEqual(self.team1.orderedSnailList[i].hasTurn, False)
        
    def testNextSnailTurn(self):
        """
        Test if the next time get's the turn
        """
        # test if the currentSnailTurn is 0
        self.team1.addSnails(self.maxSnails)
        
        # Check when all the snails had the turn, if the first snail gets turn again
        for i in range(0, self.maxSnails):
            print i
            self.assertEqual(self.team1.orderedSnailList[i].hasTurn, True)
            self.team1.nextSnailTurn()
            self.assertEqual(self.team1.orderedSnailList[i].hasTurn, False)
            
            
        # check if the first snail in the list has the turn again
        self.assertEqual(self.team1.orderedSnailList[0].hasTurn, True)
예제 #2
0
class TestWeapon(unittest.TestCase):
    """
    A test class for the Weapon module.
    """

    def setUp(self):
        """
        set up data used in the tests.
        setUp is called before each test function execution.
        """        
        self.turnManager = TurnManager()
        self.teams = []
        
        self.team = Team("Akatsuki")
        self.team.addSnails(1)
        self.teams.append(self.team)
        
        self.turnManager.setTeams(self.teams)
        
        self.snail = None
        for snail in self.team.sprites():
            self.snail = snail
        
        self.weapon = Weapon("Canon", 20)
        self.weapon.ammo = 5
        
        
    def testInitialized(self):
        """
        Test if init goes good
        """
        self.assertEqual(self.weapon.name, "Canon")
        self.assertEqual(self.weapon.power, 20)
        self.assertEqual(self.weapon.ammo, 5)
        
    def testShoot(self):
        self.weapon.shoot()
        self.assertEqual(self.weapon.ammo, 4)