class HasNoPuckStateTest(unittest.TestCase): def setUp(self): Robot.initHardwareDevices = mock.Mock(return_value="") Robot.moveToPosition = mock.Mock(return_value="") Robot.setLedOn = mock.Mock(return_value="") self.robot = Robot(Queue.Queue()) self.aGame = Game(self.robot, Queue.Queue()) self.aGame.currentState = HasNoPuckState(self.aGame) self.aGame.listOfPucks = [ Puck(RANDOM_COLOR_CODE), Puck(RANDOM_COLOR_CODE), Puck(RANDOM_COLOR_CODE) ] def test_whenGameDoAnActionStateGameStateShouldChangeAtTheEndIfTheGameIsNotFinished( self): self.aGame.listOfPucks[0].setHasBeenPlaced(True) self.aGame.listOfPucks[1].setHasBeenPlaced(True) self.aGame.listOfPucks[2].setHasBeenPlaced(True) self.aGame.doAction() self.assertTrue(self.aGame.getCurrentStateName() == "HasNoPuckState") def test_whenGameDoAnActionStateGameStateShouldNotChangeAtTheEndIfTheGameIsFinished( self): self.aGame.listOfPucks[0].setHasBeenPlaced(True) self.aGame.listOfPucks[1].setHasBeenPlaced(True) self.aGame.listOfPucks[2].setHasBeenPlaced(False) self.aGame.doAction() self.assertTrue(self.aGame.getCurrentStateName() == "NearPucksState")
class NearPucksStateTest(unittest.TestCase): def setUp(self): Robot.initHardwareDevices = mock.Mock(return_value="") Robot.moveBackward = mock.Mock(return_value="") Robot.grabPuck = mock.Mock(return_value="") Robot.rotateToAngle = mock.Mock(return_value="") Robot.rotateClockwise = mock.Mock(return_value="") Robot.rotateCounterClockwise = mock.Mock(return_value="") Robot.moveBackward = mock.Mock(return_value="") Robot.moveForward = mock.Mock(return_value="") Robot.setCamMiddle = mock.Mock(return_value="") Robot.setCamDown = mock.Mock(return_value="") Robot.getDistanceToPuck = mock.Mock(return_value=(20, 15)) self.robot = Robot(Queue.Queue()) self.aGame = Game(self.robot, Queue.Queue()) self.aGame.puckNumberBeingProcessed = 0 self.aGame.listOfPucks = [ Puck(RANDOM_COLOR_CODE), Puck(RANDOM_COLOR_CODE), Puck(RANDOM_COLOR_CODE) ] self.aGame.currentState = NearPucksState(self.aGame) def test_whenGameDoAnActionStateGameStateShouldChangeAtTheEnd(self): self.aGame.doAction() print self.aGame.getCurrentStateName() self.assertTrue(self.aGame.getCurrentStateName() == "HasPuckState")
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)
class NearResistanceStateTest(unittest.TestCase): def setUp(self): Robot.initHardwareDevices = mock.Mock(return_value="") Robot.moveLeft = mock.Mock(return_value="") Robot.moveRight = mock.Mock(return_value="") Robot.moveBackward = mock.Mock(return_value="") Robot.moveForward = mock.Mock(return_value="") Robot.refreshPositionAndAngle = mock.Mock(return_value="") Robot.rotateToAngle = mock.Mock(return_value="") NearResistanceState.requestObstaclesPositions = mock.Mock( return_value="") Robot.readResistance = mock.Mock(return_value=2000) self.robot = Robot(Queue.Queue()) self.aGame = Game(self.robot, Queue.Queue()) self.aGame.currentState = NearResistanceState(self.aGame) def test_whenGameDoAnActionInNearResistanceStateGameStateShouldChangeAtTheEnd( self): self.aGame.doAction() self.assertFalse( self.aGame.getCurrentStateName() == "HasReadResistanceState") def test_whenGameDoAnActionInNearResistanceStateResistanceValueShouldChange( self): self.aGame.doAction() self.assertFalse(self.aGame.getResistanceValue == -1)
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)
class HasPuckStateTest(unittest.TestCase): def setUp(self): Robot.initHardwareDevices = mock.Mock(return_value="") Robot.moveToPosition = mock.Mock(return_value="") self.robot = Robot(Queue.Queue()) self.aGame = Game(self.robot, Queue.Queue()) self.aGame.currentState = HasPuckState(self.aGame) def test_whenGameDoAnActionStateGameStateShouldChangeAtTheEnd(self): self.aGame.doAction() self.assertTrue( self.aGame.getCurrentStateName() == "NearGoalPositionState")
class NoResistanceValueStateTest(unittest.TestCase): def setUp(self): Robot.initHardwareDevices = mock.Mock(return_value="") Robot.moveRight = mock.Mock(return_value="") Robot.moveBackward = mock.Mock(return_value="") Robot.refreshPositionAndAngle = mock.Mock(return_value="") Robot.rotateToAngle = mock.Mock(return_value="") self.robot = Robot(Queue.Queue()) self.aGame = Game(self.robot, Queue.Queue()) def test_whenGameDoAnActionInNoResistanceValueStateGameStateShouldChangeStateAtTheEnd(self): self.aGame.doAction() self.assertTrue(self.aGame.getCurrentStateName() == "NearResistanceState")
class NearOrientationBoardStateTest(unittest.TestCase): def setUp(self): Robot.initHardwareDevices = mock.Mock(return_value="") Robot.findOrientationInOrientationBoard = mock.Mock(return_value="SA") NearResistanceState.fetchResistance = mock.Mock(return_value="") self.robot = Robot(Queue.Queue()) self.aGame = Game(self.robot, Queue.Queue()) self.aGame.currentState = NearOrientationBoardState(self.aGame) self.aGame.setPositionToReadInOrientationBoard(2) def test_whenGameDoAnActionStatePuckOrientationShouldChange(self): self.aGame.doAction() self.assertTrue(self.aGame.getPucksOrientation() == "SA") def test_whenGameDoAnActionStateGameStateShouldChangeAtTheEnd(self): self.aGame.doAction() self.assertTrue( self.aGame.getCurrentStateName() == "HasReadOrientationBoardState")
class NearLetterBoardStateTest(unittest.TestCase): def setUp(self): Robot.initHardwareDevices = mock.Mock(return_value="") Robot.rotateToAngle = mock.Mock(return_value="") Robot.findLetterInLetterBoard = mock.Mock(return_value="D") Robot.setCamMiddle = mock.Mock(return_value="") Robot.setCamUp = mock.Mock(return_value="") NearResistanceState.fetchResistance = mock.Mock(return_value="") self.robot = Robot(Queue.Queue()) self.aGame = Game(self.robot, Queue.Queue()) self.aGame.currentState = NearLetterBoardState(self.aGame) self.aGame.listOfPucks = [Puck(RANDOM_COLOR_CODE), Puck(RANDOM_COLOR_CODE), Puck(RANDOM_COLOR_CODE)] self.aGame.setPositionToReadInLetterBoard(2) def test_whenGameDoAnActionStateGameStateShouldChangeAtTheEnd(self): self.aGame.doAction() self.assertTrue(self.aGame.getCurrentStateName() == "HasReadLetterBoardState") def test_whenGameDoAnActionFirstPuckCornerShouldBeInitialized(self): self.aGame.doAction() self.assertTrue(self.aGame.listOfPucks[0].getCornerToBePlaced() == "D")
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)