diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/array.py | 5 | ||||
-rw-r--r-- | src/util/range.py | 30 | ||||
-rw-r--r-- | src/util/test_array.py | 12 | ||||
-rw-r--r-- | src/util/test_range.py | 6 |
4 files changed, 0 insertions, 53 deletions
diff --git a/src/util/array.py b/src/util/array.py deleted file mode 100644 index bb4eee3..0000000 --- a/src/util/array.py +++ /dev/null @@ -1,5 +0,0 @@ -def insert_position(x, xs, is_reversed: bool) -> int: - for i, y in enumerate(xs): - if is_reversed and x >= y or not is_reversed and x <= y: - return i - return len(xs) diff --git a/src/util/range.py b/src/util/range.py deleted file mode 100644 index bd4b27e..0000000 --- a/src/util/range.py +++ /dev/null @@ -1,30 +0,0 @@ -from typing import NamedTuple, List - -class Range(NamedTuple): - start: int - length: int - -def from_indexes(indexes: List[int]) -> List[Range]: - ranges = [] - curr_range_start = 0 - curr_range_len = 0 - - last_index = -1 - - for index in sorted(indexes): - if index == curr_range_start + curr_range_len: - curr_range_len += 1 - else: - if curr_range_len > 0: - ranges.append(Range( - start = curr_range_start, - length = curr_range_len)) - curr_range_start = index - curr_range_len = 1 - - if curr_range_len > 0: - ranges.append(Range( - start = curr_range_start, - length = curr_range_len)) - - return ranges diff --git a/src/util/test_array.py b/src/util/test_array.py deleted file mode 100644 index 38759b9..0000000 --- a/src/util/test_array.py +++ /dev/null @@ -1,12 +0,0 @@ -from array import insert_position - -def test_insert_position(): - assert insert_position(0, [], False) == 0 - assert insert_position(1, [1, 2, 3], False) == 0 - assert insert_position(2, [1, 2, 3], False) == 1 - assert insert_position(3, [1, 2, 3], False) == 2 - assert insert_position(8, [1, 2, 3], False) == 3 - assert insert_position(8, [3, 2, 1], True) == 0 - assert insert_position(3, [3, 2, 1], True) == 0 - assert insert_position(2, [3, 2, 1], True) == 1 - assert insert_position(1, [3, 2, 1], True) == 2 diff --git a/src/util/test_range.py b/src/util/test_range.py deleted file mode 100644 index 0bd909b..0000000 --- a/src/util/test_range.py +++ /dev/null @@ -1,6 +0,0 @@ -from range import from_indexes, Range - -def test_from_indexes(): - assert from_indexes([]) == [] - assert from_indexes([1]) == [Range(1, 1)] - assert from_indexes([9, 6, 0, 10]) == [Range(0, 1), Range(6, 1), Range(9, 2)] |