def wrap(i_min: int, i_max: int, i: int) ->int:
    """Wrap i between i_min and i_max."""
    assert isinstance(i_min, int)
    assert isinstance(i_max, int)
    assert isinstance(i, int)
    assert i_min <= i_max
    i_range = i_max + 1 - i_min
    return ((i - i_min) % i_range + i_range) % i_range + i_min
