def test_text_world(self): with captured_io(StringIO()) as (out, err): text_world.setup_world("Bongo") text_world.update_position(10) text_world.do_right() text_world.update_position(20) self.assertEqual(text_world.position_y, 10) self.assertEqual(text_world.position_x, 20)
def do_back(robot_name, steps): """ Moves the robot forward the number of steps :param robot_name: :param steps: :return: (True, forward output text) """ if world.update_position(-steps, current_direction_index): #world.turtle_reference.back(steps) return True, ' > ' + robot_name + ' moved back by ' + str( steps) + ' steps.' else: return True, '' + robot_name + ': Sorry, I cannot go outside my safe zone.'
def do_forward(robot_name, steps): """ Moves the robot forward the number of steps :param robot_name: :param steps: :return: (True, forward output text) """ move = world.update_position(steps, current_direction_index) if move[0] == True: #world.turtle_reference.forward(steps) return True, ' > ' + robot_name + ' moved forward by ' + str( steps) + ' steps.' elif move[1] == "obstacle": return True, '' + robot_name + ': Sorry, There is an obstacle in the way.' else: return True, '' + robot_name + ': Sorry, I cannot go outside my safe zone.'
def test_update_1(self): txt.position_x = 50 txt.position_y = 50 txt.current_direction_index = 2 self.assertTrue(txt.update_position(50))
def test_update_4(self): txt.position_x = 50 txt.position_y = 180 txt.current_direction_index = 0 self.assertFalse(txt.update_position(60))
def test_update_3(self): txt.position_x = 50 txt.position_y = 0 txt.current_direction_index = 3 self.assertTrue(txt.update_position(60))
def test_update_position_false(self): steps = 500 self.assertEqual(w.update_position(steps), False)
def test_update_position(self): steps = 1 self.assertEqual(w.update_position(steps), True)
def test_update_position_out(self): self.assertEqual(world.update_position(206), False)
def test_update_position(self): self.assertEqual(world.update_position(6), True)
def test_start_world(self): world.start_world() world.update_position(51) world.show_position("hal")