def testDrawMap(self): expected = """ -------------------- | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | -------------------- """ snake = Snake() actual = snake.draw(None, None) self.assertMultiLineEqual(expected, actual, "Expected:\n\n{0}\nActual:\n\n{1}".format(expected, actual))
def testDrawSnakeHorizontal(self): expected = """ -------------------- | | | | | | | | | | | | | | | | | | | @@@@@ | | | | | | | | | | | | | | | | | | | | | -------------------- """ snake = Snake() snakePositions = [Coordinates(10,10), Coordinates(9,10), Coordinates(8,10), Coordinates(7,10), Coordinates(6,10)] actual = snake.draw(snakePositions, None) self.assertMultiLineEqual(expected, actual, "Expected:\n\n{0}\nActual:\n\n{1}".format(expected, actual))
def testDrawOtherFood(self): expected = """ -------------------- | * | | | | | | | | | | | | | | | | | | @@@@@ *| | | | | | | | | | | | | | | | * * | | | | | -------------------- """ snake = Snake() snakePositions = [Coordinates(10,10), Coordinates(9,10), Coordinates(8,10), Coordinates(7,10), Coordinates(6,10)] foodPositions = [Coordinates(5,1), Coordinates(2,18), Coordinates(17,18), Coordinates(20,10)] actual = snake.draw(snakePositions, foodPositions) self.assertMultiLineEqual(expected, actual, "Expected:\n\n{0}\nActual:\n\n{1}".format(expected, actual))
def testGenerateRandomFoodPositionOverSnakeFuzzTest(self): for i in range(100): snake = Snake() snakeCoordinatesList = snake.getSnakeCoordinates() snake.generateRandomFoodCoordinates(FOOD_STARTING_NUMBER) for foodCoordinates in snake.getFoodCoordinates(): if foodCoordinates in snakeCoordinatesList: raise AssertionError("Generated food coordinates shouldn't overlap snake!!!")
def testCreateNewFoodPositionOverFoodPositionFuzzTest(self): snake = Snake() for i in range(380): snake.generateRandomFoodCoordinates(1) seen = list() for foodCoordinates in snake.getFoodCoordinates(): if foodCoordinates in seen: raise AssertionError("Generated food coordinates shouldn't overlap other food coordinates!!!") else: seen.append(foodCoordinates)
def testGenerateRandomFoodPositionOverFoodPositionFuzzTest(self): for i in range(100): snake = Snake() snake.generateRandomFoodCoordinates(FOOD_STARTING_NUMBER) seen = list() for foodCoordinates in snake.getFoodCoordinates(): if foodCoordinates in seen: raise AssertionError("Generated food coordinates shouldn't overlap other food coordinates!!!") else: seen.append(foodCoordinates)
from production.snake import Snake snake = Snake() snake.start()
def __setUpSnakeForMovingDownRightBorderSafe(self): snake = Snake() snake.setSnakeCoordinates([Coordinates(19,19), Coordinates(19,18), Coordinates(19,17), Coordinates(19,16), Coordinates(19,15)]) return snake
def __setUpSnakeForMovingUpLeftBorderSafe(self): snake = Snake() snake.setSnakeCoordinates([Coordinates(2,2), Coordinates(2,3), Coordinates(2,4), Coordinates(2,5), Coordinates(2,6)]) return snake
def __setUpSnakeForMovingDownRightBorder(self): snake = Snake() snake.setSnakeCoordinates([Coordinates(20,20), Coordinates(20,19), Coordinates(20,18), Coordinates(20,17), Coordinates(20,16)]) return snake
def __setUpSnakeForMovingUpLeftBorder(self): snake = Snake() snake.setSnakeCoordinates([Coordinates(1,1), Coordinates(1,2), Coordinates(1,3), Coordinates(1,4), Coordinates(1,5)]) return snake
def __setUpSnakeForMovingLeftRightUp(self): snake = Snake() snake.setSnakeCoordinates([Coordinates(10,10), Coordinates(10,11), Coordinates(10,12), Coordinates(10,13), Coordinates(10,14)]) return snake
def testGenerateRandomHeadPositionBorderFuzzTest(self): for i in range(100): snake = Snake() if snake.generateRandomHeadCoordinates().x < 6: raise AssertionError("Generated x coordinate shouldn't be smaller than 5!!!")
def testGenerateRandomFoodPosition(self): snake = Snake() snake2 = Snake() snake.generateRandomFoodCoordinates(FOOD_STARTING_NUMBER) snake2.generateRandomFoodCoordinates(FOOD_STARTING_NUMBER) assert_that(snake.getFoodCoordinates(), not equal_to(snake2.getFoodCoordinates()))
def testGenerateRandomHeadPosition(self): snake = Snake() headCoordinates1 = snake.generateRandomHeadCoordinates() headCoordinates2 = snake.generateRandomHeadCoordinates() self.assertNotEqual(headCoordinates1, headCoordinates2, "Coordinates shouldn't be equal!\nCoordinates 1: X:{0},Y:{1}\nCoordinates 2: X:{2},Y:{3}".format(headCoordinates1.x, headCoordinates1.y, headCoordinates2.x, headCoordinates2.y))
def __setUpSnakeForMovingUpDownRight(self): snake = Snake() snake.setSnakeCoordinates([Coordinates(14,10), Coordinates(13,10), Coordinates(12,10), Coordinates(11,10), Coordinates(10,10)]) return snake