def shifted_points_within_range(points, minimum, maximum, precision = 4): # Handle input errors allow_vector_matrix(points, 'first') compare_scalars(minimum, maximum, 'second', 'third') positive_integer(precision) # Grab general points general_points = [] for point in points: # Handle coordinate pairs if isinstance(point, list): if isinstance(point[0], str): general_points.append(point[0]) # Handle single coordinates else: if isinstance(point, str): general_points.append(point) # Generate options for inputs optional_points = [] for point in general_points: # Grab initial value and periodic unit initial_value_index = point.find(' + ') initial_value = float(point[:initial_value_index]) periodic_unit_index = initial_value_index + 3 periodic_unit = float(point[periodic_unit_index:-1]) # Increase or decrease initial value to fit into range alternative_initial_value = shift_into_range(initial_value, periodic_unit, minimum, maximum) # Generate additional values within range generated_elements = generate_elements(alternative_initial_value, periodic_unit, precision) optional_points += generated_elements # Separate numerical inputs from string inputs separated_points = separate_elements(optional_points) numerical_points = separated_points['numerical'] other_points = separated_points['other'] # Sort numerical inputs sorted_points = sorted_list(numerical_points) # Reduce numerical inputs to within a given range selected_points = [x for x in sorted_points if x >= minimum and x <= maximum] # Round numerical inputs rounded_points = rounded_list(selected_points, precision) # Sort string inputs sorted_other_points = sorted_strings(other_points) # Combine numerical and string inputs result = rounded_points + sorted_other_points return result
def test_shift_range_above_negative(self): shift_range_above_negative = shift_into_range(31, -2, 10, 20) self.assertEqual(shift_range_above_negative, 19)
def test_shift_range_unfit_below_negative(self): shift_range_unfit_below_negative = shift_into_range(1, -30, 10, 20) self.assertEqual(shift_range_unfit_below_negative, 31)
def test_shift_range_below_negative(self): shift_range_below_negative = shift_into_range(1, -2, 10, 20) self.assertEqual(shift_range_below_negative, 11)
def test_shift_range_at_max_negative(self): shift_range_at_max_negative = shift_into_range(20, -2, 10, 20) self.assertEqual(shift_range_at_max_negative, 20)
def test_shift_range_unfit_above_positive(self): shift_range_unfit_above_positive = shift_into_range(31, 30, 10, 20) self.assertEqual(shift_range_unfit_above_positive, 31)
def test_shift_range_at_min_positive(self): shift_range_at_min_positive = shift_into_range(10, 2, 10, 20) self.assertEqual(shift_range_at_min_positive, 10)
def test_shift_range_within_positive(self): shift_range_within_positive = shift_into_range(11, 2, 10, 20) self.assertEqual(shift_range_within_positive, 11)