def set_probabilities(self, in_prob_see_door_if_door, in_prob_see_door_if_not_door): self.prob_see_door_if_door = in_prob_see_door_if_door self.prob_see_door_if_no_door = in_prob_see_door_if_not_door if __name__ == '__main__': ws_global = WorldState() ds_global = DoorSensor() rs_global = RobotState() # Robot should be at 0.5, no door at 0.5, so this should be false print("Testing probabilities for robot NOT in front of door") rs_global.robot_loc = ws_global.place_robot_not_in_front_of_door() if ds_global.is_in_front_of_door(ws_global, rs_global): raise ValueError("The robot should NOT be in front of a door") # Check that we get our probabilites back (mostly) count_returned_true = 0 for i in range(0, 1000): if ds_global.sensor_reading(ws_global, rs_global): count_returned_true += 1 prob_count = count_returned_true / 1000 if abs(prob_count - ds_global.prob_see_door_if_no_door) > 0.1: raise ValueError("Probability should be close to {}, is {}".format( ds_global.prob_see_door_if_no_door, prob_count)) print("Testing probabilities for robot in front of door")
def set_probabilities(self, in_prob_see_door_if_door, in_prob_see_door_if_not_door): self.prob_see_door_if_door = in_prob_see_door_if_door self.prob_see_door_if_no_door = in_prob_see_door_if_not_door if __name__ == '__main__': ws = WorldState() ds = DoorSensor() rs = RobotState() # Robot should be at 0.5, no door at 0.5, so this should be false print("Testing probabilities for robot NOT in front of door") rs.robot_loc = ws.place_robot_NOT_in_front_of_door() if ds.is_in_front_of_door(ws, rs): raise ValueError("The robot should NOT be in front of a door") # Check that we get our probabilites back (mostly) count_returned_true = 0 for i in range(0, 1000): if ds.sensor_reading(ws, rs) == True: count_returned_true += 1 prob_count = count_returned_true / 1000 if abs(prob_count - ds.prob_see_door_if_no_door) > 0.1: raise ValueError("Probability should be close to {}, is {}".format( ds.prob_see_door_if_no_door, prob_count)) print("Testing probabilities for robot in front of door")