class NearGoalPositionStateTest(unittest.TestCase):
    def setUp(self):
        Robot.initHardwareDevices = mock.Mock(return_value="")
        Robot.moveToPosition = mock.Mock(return_value="")
        Robot.moveToRight = mock.Mock(return_value="")
        Robot.moveForward = mock.Mock(return_value="")
        Robot.rotateToAngle = mock.Mock(return_value="")
        NearGoalPositionState.goToCorner = mock.Mock(return_value="")
        Robot.findLetterInLetterBoard = mock.Mock(return_value="D")
        Robot.dropPuck = mock.Mock(return_value="SA")
        NearPucksState.fetchPuck = mock.Mock(return_value="")
        self.robot = Robot(Queue.Queue())
        self.aGame = Game(self.robot, Queue.Queue())
        self.aGame.currentState = NearGoalPositionState(self.aGame)
        self.aGame.listOfPucks = [
            Puck(RANDOM_COLOR_CODE),
            Puck(RANDOM_COLOR_CODE),
            Puck(RANDOM_COLOR_CODE)
        ]
        self.aGame.setPucksOrientation("SA")
        self.aGame.setPositionToReadInLetterBoard(2)
        self.aGame.listOfPucks[0].setCornerToBePlaced("D")

    def test_whenGameDoAnActionStateGameStateShouldChangeAtTheEnd(self):
        self.aGame.doAction()
        self.assertTrue(self.aGame.getCurrentStateName() == "HasNoPuckState")

    def test_whenGameDoAnActionAtTheEndOneMorePuckShouldBePlaced(self):
        numberOfPucksPlacedAtStart = self.aGame.getNumberOfPucksPlaced()
        self.aGame.doAction()
        numberOfPucksPlacedAfter = self.aGame.getNumberOfPucksPlaced()
        self.assertTrue(numberOfPucksPlacedAfter > numberOfPucksPlacedAtStart)
Beispiel #2
0
class HasReadOrientationBoardStateTest(unittest.TestCase):

    def setUp(self):
        Robot.initHardwareDevices = mock.Mock(return_value="")
        Robot.moveLeft = mock.Mock(return_value="")
        Robot.moveRight = mock.Mock(return_value="")
        Robot.rotateToAngle = mock.Mock(return_value="")
        self.robot = Robot(Queue.Queue())
        self.aGame = Game(self.robot, Queue.Queue())
        self.aGame.currentState = HasReadOrientationBoardState(self.aGame)
        puck1 = Puck(RANDOM_COLOR_CODE)
        puck1.setPriority(1)
        puck2 = Puck(RANDOM_COLOR_CODE)
        puck2.setPriority(2)
        puck3 = Puck(RANDOM_COLOR_CODE)
        puck3.setPriority(1)
        self.aGame.listOfPucks = [puck1, puck2, puck3]
        self.aGame.setPucksOrientation("SA")
        self.aGame.listOfPucks[0].setCornerToBePlaced("D")
        self.aGame.setPositionToReadInOrientationBoard(3)

    def test_whenGameDoAnActionStateGameStateShouldChangeAtTheEnd(self):
        self.aGame.doAction()
        self.assertTrue(self.aGame.getCurrentStateName() == "NearPucksState")
        
    def test_puckListShouldBeResetAccordingToPriority(self):
        self.aGame.doAction()
        self.assertTrue(self.aGame.listOfPucks[0].getPriority() == 1)
        
    def test_whenGameDoAnActionPuckOneCornerShouldBeDWithSAOrientationAndDFirstCorner(self):
        self.aGame.doAction()
        self.assertTrue(self.aGame.listOfPucks[0].getCornerToBePlaced() == "D")
        
    def test_whenGameDoAnActionPuckTwoCornerShouldBeDWithSAOrientationAndDFirstCornerWithPrioritySetted(self):
        self.aGame.doAction()
        self.assertTrue(self.aGame.listOfPucks[1].getCornerToBePlaced() == "B")
        
    def test_whenGameDoAnActionPuckThreeCornerShouldBeDWithSAOrientationAndDFirstCornerWithPrioritySetted(self):
        self.aGame.doAction()
        self.assertTrue(self.aGame.listOfPucks[2].getCornerToBePlaced() == "C")

        
    def test_whenGameDoAnActionNoPuckShouldHavePriorityToMinusOne(self):
        self.aGame.doAction()
        allPuckHaveAPriority = True
        for puck in self.aGame.listOfPucks:
            if puck.getPriority() == -1:
                allPuckHaveAPriority = False
        self.assertTrue(allPuckHaveAPriority)
        
    def test_whenGameDoAnActionNoPuckShouldHaveCornerToNothing(self):
        self.aGame.doAction()
        allPuckHaveACorner = True
        for puck in self.aGame.listOfPucks:
            if puck.getCornerToBePlaced == "":
                allPuckHaveACorner = False
        self.assertTrue(allPuckHaveACorner)