# remove_all.py
#
# ICS H32 Fall 2025
# Code Example
#
# An implementation of a function called remove_all, along with
# automated, assert-based tests for it.


def remove_all(the_list: list, value) -> list:
    '''
    Returns a new list containing all elements from the given list
    that are not equal to the search value.
    '''
    new_list = []
    found = False

    for element in the_list:
        if element != value:
            new_list.append(element)
        else:
            found = True

    if not found:
        raise ValueError('value not found in list')

    return new_list


# Tests for remove_all()
# -----------------------
# Normal cases (removing an element in the list)
assert remove_all([1, 3, 5, 7, 9, 11, 13], 3) == [1, 5, 7, 9, 11, 13]
assert remove_all([1, 3, 5, 7, 9, 11, 13], 7) == [1, 3, 5, 9, 11, 13]

# Boundary cases (remove the first, last, and only elements)
assert remove_all([1, 2, 3, 4, 5], 1) == [2, 3, 4, 5]
assert remove_all([1, 2, 3, 4, 5], 5) == [1, 2, 3, 4]
assert remove_all([11], 11) == []

# Error cases (removing elements not in the list)
try:
    remove_all([1, 3, 5, 7], 8)
    assert False, 'ValueError should have been raised'
except ValueError:
    pass

try:
    remove_all([], 8)
    assert False, 'ValueError should have been raised'
except ValueError:
    pass

# Removing repeated elements
assert remove_all([1, 3, 5, 7, 1, 3, 5, 7, 1, 3, 5, 7], 5) == [1, 3, 7, 1, 3, 7, 1, 3, 7]
assert remove_all([7, 7, 7, 7, 7, 7, 7], 7) == []
