Example #1
0
class GameTest(unittest.TestCase):
    
    def setUp(self):
        Robot.initHardwareDevices = mock.Mock(return_value="")
        self.robot = Robot(Queue.Queue())
        self.game = Game(self.robot, Queue.Queue())
        
    def test_aGameWhenCreatedMustHaveZeroPuckInItsList(self):
        self.assertTrue(len(self.game.listOfPucks) == 0)
        
    def test_aGameWhenCreatedMustNotBeFinished(self):
        self.assertFalse(self.game.isFinished())
        
    def test_aGameWhenCreatedMustNotHaveAPuckBeingProcessed(self):
        self.assertTrue(self.game.getPuckNumberBeingProcessed() == 0)
        
    def test_aGameWhenCreatedMustNotHaveAResistanceValue(self):
        self.assertTrue(self.game.getResistanceValue() == -1)
        
    def test_aGameWhenCreatedMustNotHaveAPucksOrientation(self):
        self.assertTrue(self.game.getPucksOrientation() == "")
        
    def test_aGameWhenCreatedMustNotHaveAPositionToReadInitialisedForLetterBoard(self):
        self.assertTrue(self.game.getPositionToReadInLetterBoard() == -1)
        
    def test_aGameWhenCreatedMustNotHaveAPositionToReadInitialisedForOrientationBoard(self):
        self.assertTrue(self.game.getPositionToReadInOrientationBoard() == -1)
        
    def test_aGameWhenThreePucksPlacedShouldBeFinished(self):
        puck1 = Puck(RANDOM_COLOR_CODE)
        puck1.setHasBeenPlaced(True)
        puck2 = Puck(RANDOM_COLOR_CODE_1)
        puck2.setHasBeenPlaced(True)
        puck3 = Puck(RANDOM_COLOR_CODE_2)
        puck3.setHasBeenPlaced(True)
        self.game.listOfPucks.append(puck1)
        self.game.listOfPucks.append(puck2)
        self.game.listOfPucks.append(puck3)
        self.assertTrue(self.game.isFinished())
        
    def test_aGameWhenNotThreePucksPlacedShouldNotBeFinished(self):
        puck1 = Puck(RANDOM_COLOR_CODE)
        puck1.setHasBeenPlaced(True)
        puck2 = Puck(RANDOM_COLOR_CODE_1)
        puck2.setHasBeenPlaced(False)
        puck3 = Puck(RANDOM_COLOR_CODE_2)
        puck3.setHasBeenPlaced(True)
        self.game.listOfPucks.append(puck1)
        self.game.listOfPucks.append(puck2)
        self.game.listOfPucks.append(puck3)
        self.assertFalse(self.game.isFinished())
class HasReadResistanceStateTest(unittest.TestCase):
    def setUp(self):
        Robot.initHardwareDevices = mock.Mock(return_value="")
        Robot.moveToPosition = 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 = HasReadResistanceState(self.aGame)
        self.aGame.setResistanceValue(25000)
        HasReadResistanceState.splitResistanceValueInThreeNumbers = mock.Mock(
            return_value=(2, 5, 3))

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

    def test_whenGameDoAnActionPositionToReadInLetterBoardShouldChange(self):
        self.aGame.doAction()
        self.assertFalse(self.aGame.getPositionToReadInLetterBoard() == -1)

    def test_whenGameDoAnActionPositionToReadInOrientationBoardShouldChange(
            self):
        self.aGame.doAction()
        self.assertFalse(
            self.aGame.getPositionToReadInOrientationBoard() == -1)

    def test_whenGameDoAnActionListOfPucksShouldHaveThreePucks(self):
        self.aGame.doAction()
        self.assertTrue(len(self.aGame.listOfPucks) == 3)

    def test_whenGameDoAnActionPuckInListShouldNotBePlaced(self):
        self.aGame.doAction()
        self.assertFalse(self.aGame.listOfPucks[0].hasBeenPlaced)

    def test_whenGameDoAnActionPucksInListShouldNotHavePriorityToMinusOne(
            self):
        self.aGame.doAction()
        aPuckWithPriorityToMinusOneExist = False
        for puck in self.aGame.listOfPucks:
            if puck.getPriority() == -1:
                aPuckWithPriorityToMinusOneExist = True
        self.assertFalse(aPuckWithPriorityToMinusOneExist)

    def test_whenGameDoAnActionPuckInListShouldHaveCornerToBePlacedToNothing(
            self):
        self.aGame.doAction()
        self.assertTrue(self.aGame.listOfPucks[0].getCornerToBePlaced() == "")

    def test_whenGameDoAnActionWithResistanceValue25000PucksColorShouldBeRedGreenOrange(
            self):
        self.aGame.doAction()
        gameHasARedPuck = False
        gameHasAGreenPuck = False
        gameHasAOrangePuck = False
        for puck in self.aGame.listOfPucks:
            if puck.getPrimaryColor() == RED_COLOR_CODE:
                gameHasARedPuck = True
            if puck.getPrimaryColor() == ORANGE_COLOR_CODE:
                gameHasAGreenPuck = True
            if puck.getPrimaryColor() == GREEN_COLOR_CODE:
                gameHasAOrangePuck = True
        self.assertTrue(gameHasARedPuck)
        self.assertTrue(gameHasAGreenPuck)
        self.assertTrue(gameHasAOrangePuck)

    def test_whenGameDoAnActionWithResistanceValue25000PositionToReadInLetterBoardShouldBeTwo(
            self):
        self.aGame.doAction()
        self.assertTrue(self.aGame.getPositionToReadInLetterBoard() == 2)

    def test_whenGameDoAnActionWithResistanceValue25000PositionToReadInOrientationBoardShouldBeFive(
            self):
        self.aGame.doAction()
        self.assertTrue(self.aGame.getPositionToReadInOrientationBoard() == 3)