def test_bottom_left_top_right_constructor(self): bottom_left = Geometry.Point(0, 0) top_right = Geometry.Point(5, 5) board = RobotModel.Board(bottom_left) self.assertFalse(board.is_valid()) self.assertEqual(RobotModel.Board(bottom_left, top_right), board)
def test_is_valid_position_inside_point(self): self.VALID_BOARD = RobotModel.Board(Geometry.Point(0, 0), Geometry.Point(10, 10)) inside_point = Geometry.Point( self.VALID_BOARD.get_bottom_left().get_x() + 1, self.VALID_BOARD.get_bottom_left().get_y() + 1) self.assertTrue(self.VALID_BOARD.is_valid_position(inside_point))
def test_is_valid(self): x = 57 y = 90 self.assertFalse(Geometry.Point().is_valid()) self.assertFalse(Geometry.Point(x).is_valid()) self.assertFalse( Geometry.Point(Geometry.Point.INVALID_POSITION, y).is_valid()) self.assertTrue(Geometry.Point(x, y))
def test_to_normalized_vector(self): self.assertEqual(Geometry.Point(), Geometry.Orientation.INVALID.to_normalized_vector()) self.assertEqual(Geometry.Point(0, 1), Geometry.Orientation.NORTH.to_normalized_vector()) self.assertEqual(Geometry.Point(1, 0), Geometry.Orientation.EAST.to_normalized_vector()) self.assertEqual(Geometry.Point(0, -1), Geometry.Orientation.SOUTH.to_normalized_vector()) self.assertEqual(Geometry.Point(-1, 0), Geometry.Orientation.WEST.to_normalized_vector())
def test_eq_operator(self): x = 10 y = -25 self.assertTrue(Geometry.Point() == Geometry.Point()) self.assertTrue(Geometry.Point(x, y) == Geometry.Point(x, y)) self.assertFalse(Geometry.Point() == Geometry.Point(x, y)) self.assertFalse(Geometry.Point(x, y) == Geometry.Point(x + 1, y + 1))
def test_bottom_left_constructor(self): bottom_left = Geometry.Point(0, 0) board = RobotModel.Board(bottom_left) self.assertFalse(board.is_valid()) self.assertEqual( RobotModel.Board(bottom_left, self.FULL_INVALID_POINT), board)
def test_set_get_position(self): point = Geometry.Point(69, -90) robot = RobotModel.MobileRobot() robot.set_position(point) self.assertEqual(point, robot.get_position())
def test_set_get_bottom_left_constructor(self): bottom_left = Geometry.Point(-10, -10) board = RobotModel.Board() board.set_bottom_left(bottom_left) self.assertEqual(bottom_left, board.get_bottom_left())
def test_set_get_top_right_constructor(self): top_right = Geometry.Point(10, 10) board = RobotModel.Board() board.set_bottom_left(top_right) self.assertEqual(top_right, board.get_bottom_left())
def test_x_y_constructor(self): x = 2 y = 3 point = Geometry.Point(x, y) self.assertEqual(x, point.get_x()) self.assertEqual(y, point.get_y())
def test_set_get_x(self): x1 = 56 x2 = 45 point = Geometry.Point() point.set_x(x1) self.assertEqual(x1, point.get_x()) point.set_x(x2) self.assertEqual(x2, point.get_x())
def test_default_constructor(self): robot = RobotModel.MobileRobot() self.assertFalse(robot.get_position().is_valid()) self.assertEqual( Geometry.Point(Geometry.Point.INVALID_POSITION, Geometry.Point.INVALID_POSITION), robot.get_position()) self.assertFalse(robot.get_orientation().is_valid())
def test_set_get_y(self): y1 = 34 y2 = -500 point = Geometry.Point() point.set_y(y1) self.assertEqual(y1, point.get_y()) point.set_y(y2) self.assertEqual(y2, point.get_y())
def test_is_valid_position_in_margin_board(self): self.VALID_BOARD = RobotModel.Board(Geometry.Point(0, 0), Geometry.Point(10, 10)) left_margin_point = Geometry.Point( self.VALID_BOARD.get_bottom_left().get_x(), self.VALID_BOARD.get_bottom_left().get_y() + 1) bottom_margin_point = Geometry.Point( self.VALID_BOARD.get_bottom_left().get_x() + 1, self.VALID_BOARD.get_bottom_left().get_y()) right_margin_point = Geometry.Point( self.VALID_BOARD.get_top_right().get_x(), self.VALID_BOARD.get_top_right().get_y() - 1) top_margin_point = Geometry.Point( self.VALID_BOARD.get_top_right().get_x() - 1, self.VALID_BOARD.get_top_right().get_y()) bottom_left_margin_point = self.VALID_BOARD.get_bottom_left() top_left_margin_point = self.VALID_BOARD.get_top_right() top_right_margin_point = self.VALID_BOARD.get_top_right() bottom_right_margin_point = self.VALID_BOARD.get_bottom_left() self.assertTrue(self.VALID_BOARD.is_valid_position(left_margin_point)) self.assertTrue( self.VALID_BOARD.is_valid_position(bottom_margin_point)) self.assertTrue(self.VALID_BOARD.is_valid_position(right_margin_point)) self.assertTrue(self.VALID_BOARD.is_valid_position(top_margin_point)) self.assertTrue( self.VALID_BOARD.is_valid_position(bottom_left_margin_point)) self.assertTrue( self.VALID_BOARD.is_valid_position(top_left_margin_point)) self.assertTrue( self.VALID_BOARD.is_valid_position(top_right_margin_point)) self.assertTrue( self.VALID_BOARD.is_valid_position(bottom_right_margin_point))
def test_is_valid_position_outside_board(self): self.VALID_BOARD = RobotModel.Board(Geometry.Point(0, 0), Geometry.Point(10, 10)) out_left_point = Geometry.Point( self.VALID_BOARD.get_bottom_left().get_x() - 1, self.VALID_BOARD.get_bottom_left().get_y()) out_bottom_point = Geometry.Point( self.VALID_BOARD.get_bottom_left().get_x(), self.VALID_BOARD.get_bottom_left().get_y() - 1) out_right_point = Geometry.Point( self.VALID_BOARD.get_top_right().get_x() + 1, self.VALID_BOARD.get_top_right().get_y()) out_top_point = Geometry.Point( self.VALID_BOARD.get_top_right().get_x(), self.VALID_BOARD.get_top_right().get_y() + 1) out_bottom_left_point = Geometry.Point( self.VALID_BOARD.get_bottom_left().get_x() - 1, self.VALID_BOARD.get_bottom_left().get_y() - 1) out_top_left_point = Geometry.Point( self.VALID_BOARD.get_bottom_left().get_x() - 1, self.VALID_BOARD.get_top_right().get_y() + 1) out_top_right_point = Geometry.Point( self.VALID_BOARD.get_top_right().get_x() + 1, self.VALID_BOARD.get_top_right().get_y() + 1) out_bottom_right_point = Geometry.Point( self.VALID_BOARD.get_top_right().get_x() + 1, self.VALID_BOARD.get_bottom_left().get_y() - 1) self.assertFalse(self.VALID_BOARD.is_valid_position(out_left_point)) self.assertFalse(self.VALID_BOARD.is_valid_position(out_bottom_point)) self.assertFalse(self.VALID_BOARD.is_valid_position(out_right_point)) self.assertFalse(self.VALID_BOARD.is_valid_position(out_top_point)) self.assertFalse( self.VALID_BOARD.is_valid_position(out_bottom_left_point)) self.assertFalse( self.VALID_BOARD.is_valid_position(out_top_left_point)) self.assertFalse( self.VALID_BOARD.is_valid_position(out_top_right_point)) self.assertFalse( self.VALID_BOARD.is_valid_position(out_bottom_right_point))
def test_add_operator_valid_values(self): x = -100 y = 200 self.assertTrue(Geometry.Point(x + x, y + y), Geometry.Point(x, y) + Geometry.Point(x, y)) self.assertTrue(Geometry.Point(0, 0), Geometry.Point(x, y) + Geometry.Point(-x, -y))
def __init__(self, bottom_left=Geometry.Point(), top_right=Geometry.Point()): self.__bottom_left = bottom_left self.__top_right = top_right
def test_default_constructor(self): point = Geometry.Point() self.assertEqual(Geometry.Point.INVALID_POSITION, point.get_x()) self.assertEqual(Geometry.Point.INVALID_POSITION, point.get_y())
def __init__(self): self.__robot = MobileRobot() self.__board = Board(Geometry.Point(0, 0), Geometry.Point(4, 4))
def __init__(self): self.__position = Geometry.Point() self.__orientation = Geometry.Orientation.INVALID
class BoardTestCase(unittest.TestCase): FULL_INVALID_POINT = Geometry.Point(Geometry.Point.INVALID_POSITION, Geometry.Point.INVALID_POSITION) VALID_POINT = Geometry.Point(0, 0) INVALID_POINT = Geometry.Point() VALID_BOARD = RobotModel.Board(Geometry.Point(0, 0), Geometry.Point(10, 10)) def test_default_constructor(self): board = RobotModel.Board() self.assertFalse(board.is_valid()) self.assertEqual( RobotModel.Board(self.FULL_INVALID_POINT, self.FULL_INVALID_POINT), board) def test_bottom_left_constructor(self): bottom_left = Geometry.Point(0, 0) board = RobotModel.Board(bottom_left) self.assertFalse(board.is_valid()) self.assertEqual( RobotModel.Board(bottom_left, self.FULL_INVALID_POINT), board) def test_bottom_left_top_right_constructor(self): bottom_left = Geometry.Point(0, 0) top_right = Geometry.Point(5, 5) board = RobotModel.Board(bottom_left) self.assertFalse(board.is_valid()) self.assertEqual(RobotModel.Board(bottom_left, top_right), board) def test_set_get_bottom_left_constructor(self): bottom_left = Geometry.Point(-10, -10) board = RobotModel.Board() board.set_bottom_left(bottom_left) self.assertEqual(bottom_left, board.get_bottom_left()) def test_set_get_top_right_constructor(self): top_right = Geometry.Point(10, 10) board = RobotModel.Board() board.set_bottom_left(top_right) self.assertEqual(top_right, board.get_bottom_left()) def is_valid(self): self.assertFalse( RobotModel.Board(self.FULL_INVALID_POINT, self.FULL_INVALID_POINT).is_valid()) self.assertFalse( RobotModel.Board(self.VALID_POINT, self.FULL_INVALID_POINT).is_valid()) self.assertTrue( RobotModel.Board(self.VALID_POINT, self.VALID_POINT).is_valid()) def test_is_valid_position_not_valid_board(self): invalid_board = RobotModel.Board() self.assertFalse(invalid_board.is_valid_position(self.VALID_POINT)) self.assertFalse(invalid_board.is_valid_position(self.INVALID_POINT)) def test_is_valid_position_not_valid_point(self): valid_board = RobotModel.Board(self.VALID_POINT, self.VALID_POINT) self.assertFalse(valid_board.is_valid_position(self.INVALID_POINT)) def test_is_valid_position_outside_board(self): self.VALID_BOARD = RobotModel.Board(Geometry.Point(0, 0), Geometry.Point(10, 10)) out_left_point = Geometry.Point( self.VALID_BOARD.get_bottom_left().get_x() - 1, self.VALID_BOARD.get_bottom_left().get_y()) out_bottom_point = Geometry.Point( self.VALID_BOARD.get_bottom_left().get_x(), self.VALID_BOARD.get_bottom_left().get_y() - 1) out_right_point = Geometry.Point( self.VALID_BOARD.get_top_right().get_x() + 1, self.VALID_BOARD.get_top_right().get_y()) out_top_point = Geometry.Point( self.VALID_BOARD.get_top_right().get_x(), self.VALID_BOARD.get_top_right().get_y() + 1) out_bottom_left_point = Geometry.Point( self.VALID_BOARD.get_bottom_left().get_x() - 1, self.VALID_BOARD.get_bottom_left().get_y() - 1) out_top_left_point = Geometry.Point( self.VALID_BOARD.get_bottom_left().get_x() - 1, self.VALID_BOARD.get_top_right().get_y() + 1) out_top_right_point = Geometry.Point( self.VALID_BOARD.get_top_right().get_x() + 1, self.VALID_BOARD.get_top_right().get_y() + 1) out_bottom_right_point = Geometry.Point( self.VALID_BOARD.get_top_right().get_x() + 1, self.VALID_BOARD.get_bottom_left().get_y() - 1) self.assertFalse(self.VALID_BOARD.is_valid_position(out_left_point)) self.assertFalse(self.VALID_BOARD.is_valid_position(out_bottom_point)) self.assertFalse(self.VALID_BOARD.is_valid_position(out_right_point)) self.assertFalse(self.VALID_BOARD.is_valid_position(out_top_point)) self.assertFalse( self.VALID_BOARD.is_valid_position(out_bottom_left_point)) self.assertFalse( self.VALID_BOARD.is_valid_position(out_top_left_point)) self.assertFalse( self.VALID_BOARD.is_valid_position(out_top_right_point)) self.assertFalse( self.VALID_BOARD.is_valid_position(out_bottom_right_point)) def test_is_valid_position_in_margin_board(self): self.VALID_BOARD = RobotModel.Board(Geometry.Point(0, 0), Geometry.Point(10, 10)) left_margin_point = Geometry.Point( self.VALID_BOARD.get_bottom_left().get_x(), self.VALID_BOARD.get_bottom_left().get_y() + 1) bottom_margin_point = Geometry.Point( self.VALID_BOARD.get_bottom_left().get_x() + 1, self.VALID_BOARD.get_bottom_left().get_y()) right_margin_point = Geometry.Point( self.VALID_BOARD.get_top_right().get_x(), self.VALID_BOARD.get_top_right().get_y() - 1) top_margin_point = Geometry.Point( self.VALID_BOARD.get_top_right().get_x() - 1, self.VALID_BOARD.get_top_right().get_y()) bottom_left_margin_point = self.VALID_BOARD.get_bottom_left() top_left_margin_point = self.VALID_BOARD.get_top_right() top_right_margin_point = self.VALID_BOARD.get_top_right() bottom_right_margin_point = self.VALID_BOARD.get_bottom_left() self.assertTrue(self.VALID_BOARD.is_valid_position(left_margin_point)) self.assertTrue( self.VALID_BOARD.is_valid_position(bottom_margin_point)) self.assertTrue(self.VALID_BOARD.is_valid_position(right_margin_point)) self.assertTrue(self.VALID_BOARD.is_valid_position(top_margin_point)) self.assertTrue( self.VALID_BOARD.is_valid_position(bottom_left_margin_point)) self.assertTrue( self.VALID_BOARD.is_valid_position(top_left_margin_point)) self.assertTrue( self.VALID_BOARD.is_valid_position(top_right_margin_point)) self.assertTrue( self.VALID_BOARD.is_valid_position(bottom_right_margin_point)) def test_is_valid_position_inside_point(self): self.VALID_BOARD = RobotModel.Board(Geometry.Point(0, 0), Geometry.Point(10, 10)) inside_point = Geometry.Point( self.VALID_BOARD.get_bottom_left().get_x() + 1, self.VALID_BOARD.get_bottom_left().get_y() + 1) self.assertTrue(self.VALID_BOARD.is_valid_position(inside_point))
def test_add_operator_invalid_values(self): x = -100 y = 5 self.assertTrue(Geometry.Point(), Geometry.Point() + Geometry.Point()) self.assertTrue(Geometry.Point(), Geometry.Point(x) + Geometry.Point()) self.assertTrue( Geometry.Point(), Geometry.Point(Geometry.Point.INVALID_POSITION, y) + Geometry.Point(x)) self.assertTrue( Geometry.Point(), Geometry.Point(Geometry.Point.INVALID_POSITION, y) + Geometry.Point()) self.assertTrue(Geometry.Point(x + x), Geometry.Point(x) + Geometry.Point(x)) self.assertTrue( Geometry.Point(Geometry.Point.INVALID_POSITION, y), Geometry.Point(Geometry.Point.INVALID_POSITION, y) + Geometry.Point(Geometry.Point.INVALID_POSITION, y))
def set_request_arguments_from_input_interpreter_arguments( arguments, place_request): if len(arguments) == 3: place_request.set_position( Geometry.Point(int(arguments[0]), int(arguments[1]))) place_request.set_orientation(Geometry.Orientation[arguments[2]])