write unitest and pytest for below code
"""
arrays.py
A comprehensive implementation of array data structures and algorithms in Python,
adhering to PEP-8 standards. This module covers basic to advanced array operations,
including searching, sorting, dynamic resizing, and multi-dimensional arrays.
Dependencies:
- torch (only if tensor operations are required)
"""
from typing import TypeVar, Generic, Optional, List, Any
T = TypeVar('T')
class Array(Generic[T]):
"""
A dynamic array class similar to a simplified Python list.
"""
code
Assistant
def __init__(self, capacity: int = 16) -> None:
"""
Initializes the array with a specified capacity.
Args:
capacity (int): The initial capacity of the array.
"""
if capacity <= 0:
raise ValueError("Capacity must be positive.")
self._capacity: int = capacity
self._size: int = 0
self._data: List[Optional[T]] = [None] * self._capacity
def __len__(self) -> int:
"""Returns the number of elements in the array."""
return self._size
def __getitem__(self, index: int) -> T:
"""
Retrieves the element at the specified index.
Args:
index (int): The index of the element to retrieve.
Returns:
T: The element at the given index.
Raises:
IndexError: If index is out of bounds.
"""
if not 0 <= index < self._size:
raise IndexError("Index out of bounds.")
return self._data[index] # type: ignore
def __setitem__(self, index: int, value: T) -> None:
"""
Sets the element at the specified index to the given value.
Args:
index (int): The index of the element to set.
value (T): The value to set at the specified index.
Raises:
IndexError: If index is out of bounds.
"""
if not 0 <= index < self._size:
raise IndexError("Index out of bounds.")
self._data[index] = value
def append(self, value: T) -> None:
"""
Appends an element to the end of the array.
Args:
value (T): The value to append.
"""
if self._size == self._capacity:
self._resize(2 * self._capacity)
self._data[self._size] = value
self._size += 1
def insert(self, index: int, value: T) -> None:
"""
Inserts an element at the specified index.
Args:
index (int): The index at which to insert the element.
value (T): The value to insert.
Raises:
IndexError: If index is out of bounds.
"""
if not 0 <= index <= self._size:
raise IndexError("Index out of bounds.")
if self._size == self._capacity:
self._resize(2 * self._capacity)
for i in range(self._size, index, -1):
self._data[i] = self._data[i - 1]
self._data[index] = value
self._size += 1
def remove(self, value: T) -> None:
"""
Removes the first occurrence of the specified value.
Args:
value (T): The value to remove.
Raises:
ValueError: If the value is not found.
"""
index = self.index_of(value)
if index == -1:
raise ValueError("Value not found in array.")
self.pop(index)
def pop(self, index: int) -> T:
"""
Removes and returns the element at the specified index.
Args:
index (int): The index of the element to remove.
Returns:
T: The removed element.
Raises:
IndexError: If index is out of bounds.
"""
if not 0 <= index < self._size:
raise IndexError("Index out of bounds.")
value = self._data[index]
for i in range(index, self._size - 1):
self._data[i] = self._data[i + 1]
self._data[self._size - 1] = None
self._size -= 1
if 0 < self._size < self._capacity // 4:
self._resize(self._capacity // 2)
return value # type: ignore
def index_of(self, value: T) -> int:
"""
Returns the index of the first occurrence of the specified value.
Args:
value (T): The value to find.
Returns:
int: The index of the value, or -1 if not found.
"""
for i in range(self._size):
if self._data[i] == value:
return i
return -1
def _resize(self, new_capacity: int) -> None:
"""
Resizes the internal storage to a new capacity.
Args:
new_capacity (int): The new capacity.
"""
new_data: List[Optional[T]] = [None] * new_capacity
for i in range(self._size):
new_data[i] = self._data[i]
self._data = new_data
self._capacity = new_capacity
def clear(self) -> None:
"""Clears all elements from the array."""
self._data = [None] * self._capacity
self._size = 0
def contains(self, value: T) -> bool:
"""
Checks if the array contains the specified value.
Args:
value (T): The value to check.
Returns:
bool: True if the value is found, False otherwise.
"""
return self.index_of(value) != -1
def to_list(self) -> List[T]:
"""
Converts the array to a standard Python list.
Returns:
List[T]: The list containing all elements of the array.
"""
return [self._data[i] for i in range(self._size)] # type: ignore
class ArrayAlgorithms:
"""
A collection of static methods implementing common array algorithms.
"""
code
@staticmethod
def linear_search(arr: Array[T], target: T) -> int:
"""
Performs a linear search for the target in the array.
Args:
arr (Array[T]): The array to search.
target (T): The target value.
Returns:
int: The index of the target, or -1 if not found.
"""
for i in range(len(arr)):
if arr[i] == target:
return i
return -1
@staticmethod
def binary_search(arr: Array[T], target: T) -> int:
"""
Performs a binary search for the target in a sorted array.
Args:
arr (Array[T]): The sorted array to search.
target (T): The target value.
Returns:
int: The index of the target, or -1 if not found.
"""
left: int = 0
right: int = len(arr) - 1
while left <= right:
mid: int = left + (right - left) // 2
mid_val = arr[mid]
if mid_val == target:
return mid
elif mid_val < target:
left = mid + 1
else:
right = mid - 1
return -1
@staticmethod
def bubble_sort(arr: Array[T]) -> None:
"""
Sorts the array in ascending order using the bubble sort algorithm.
Args:
arr (Array[T]): The array to sort.
"""
n = len(arr)
for i in range(n):
swapped = False
for j in range(0, n - i - 1):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
swapped = True
if not swapped:
break
@staticmethod
def selection_sort(arr: Array[T]) -> None:
"""
Sorts the array in ascending order using the selection sort algorithm.
Args:
arr (Array[T]): The array to sort.
"""
n = len(arr)
for i in range(n):
min_idx = i
for j in range(i + 1, n):
if arr[j] < arr[min_idx]:
min_idx = j
if min_idx != i:
arr[i], arr[min_idx] = arr[min_idx], arr[i]
@staticmethod
def insertion_sort(arr: Array[T]) -> None:
"""
Sorts the array in ascending order using the insertion sort algorithm.
Args:
arr (Array[T]): The array to sort.
"""
for i in range(1, len(arr)):
key = arr[i]
j = i - 1
while j >= 0 and arr[j] > key:
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key
@staticmethod
def quick_sort(arr: Array[T]) -> None:
"""
Sorts the array in ascending order using the quick sort algorithm.
Args:
arr (Array[T]): The array to sort.
"""
def _quick_sort(low: int, high: int) -> None:
if low < high:
pi = partition(low, high)
_quick_sort(low, pi - 1)
_quick_sort(pi + 1, high)
def partition(low: int, high: int) -> int:
pivot = arr[high]
i = low - 1
for j in range(low, high):
if arr[j] <= pivot:
i += 1
arr[i], arr[j] = arr[j], arr[i]
arr[i + 1], arr[high] = arr[high], arr[i + 1]
return i + 1
_quick_sort(0, len(arr) - 1)
@staticmethod
def merge_sort(arr: Array[T]) -> None:
"""
Sorts the array in ascending order using the merge sort algorithm.
Args:
arr (Array[T]): The array to sort.
"""
def _merge_sort(left: int, right: int) -> None:
if left < right:
mid = (left + right) // 2
_merge_sort(left, mid)
_merge_sort(mid + 1, right)
merge(left, mid, right)
def merge(left: int, mid: int, right: int) -> None:
n1 = mid - left + 1
n2 = right - mid
L: List[Optional[T]] = [arr[left + i] for i in range(n1)] # type: ignore
R: List[Optional[T]] = [arr[mid + 1 + j] for j in range(n2)] # type: ignore
i = j = 0
k = left
while i < n1 and j < n2:
if L[i] is not None and R[j] is not None:
if L[i] <= R[j]:
arr[k] = L[i] # type: ignore
i += 1
else:
arr[k] = R[j] # type: ignore
j += 1
k += 1
while i < n1:
arr[k] = L[i] # type: ignore
i += 1
k += 1
while j < n2:
arr[k] = R[j] # type: ignore
j += 1
k += 1
_merge_sort(0, len(arr) - 1)
class MultiDimensionalArray:
"""
A class representing a multi-dimensional array.
"""
code
def __init__(self, dimensions: List[int]) -> None:
"""
Initializes a multi-dimensional array with the specified dimensions.
Args:
dimensions (List[int]): A list representing the size of each dimension.
Raises:
ValueError: If any dimension size is non-positive.
"""
if not dimensions:
raise ValueError("Dimensions list cannot be empty.")
for dim in dimensions:
if dim <= 0:
raise ValueError("All dimensions must be positive integers.")
self.dimensions: List[int] = dimensions
self.size: int = 1
for dim in dimensions:
self.size *= dim
self.data: Array[Any] = Array[Any](self.size)
def _get_flat_index(self, indices: List[int]) -> int:
"""
Converts multi-dimensional indices to a flat index.
Args:
indices (List[int]): A list of indices for each dimension.
Returns:
int: The corresponding flat index.
Raises:
IndexError: If any index is out of bounds.
"""
if len(indices) != len(self.dimensions):
raise IndexError("Number of indices must match number of dimensions.")
flat_index = 0
multiplier = 1
for i in reversed(range(len(self.dimensions))):
if not 0 <= indices[i] < self.dimensions[i]:
raise IndexError(f"Index {indices[i]} out of bounds for dimension {i}.")
flat_index += indices[i] * multiplier
multiplier *= self.dimensions[i]
return flat_index
def get(self, indices: List[int]) -> Any:
"""
Retrieves the value at the specified multi-dimensional indices.
Args:
indices (List[int]): The multi-dimensional indices.
Returns:
Any: The value at the specified indices.
"""
flat_index = self._get_flat_index(indices)
return self.data[flat_index]
def set(self, indices: List[int], value: Any) -> None:
"""
Sets the value at the specified multi-dimensional indices.
Args:
indices (List[int]): The multi-dimensional indices.
value (Any): The value to set.
"""
flat_index = self._get_flat_index(indices)
self.data[flat_index] = value
def to_nested_list(self) -> Any:
"""
Converts the multi-dimensional array to a nested Python list.
Returns:
Any: The nested list representation.
"""
def build_nested_list(dim: int, start: int) -> Any:
if dim == len(self.dimensions) - 1:
return [self.data[i] for i in range(start, start + self.dimensions[dim])]
nested = []
step = 1
for d in self.dimensions[dim + 1:]:
step *= d
for i in range(self.dimensions[dim]):
nested.append(build_nested_list(dim + 1, start + i * step))
return nested
return build_nested_list(0, 0)
class SparseArray(Generic[T]):
"""
A sparse array implementation using a dictionary to store non-zero elements.
"""
code
def __init__(self, size: int) -> None:
"""
Initializes a sparse array of a given size.
Args:
size (int): The size of the array.
Raises:
ValueError: If size is non-positive.
"""
if size <= 0:
raise ValueError("Size must be a positive integer.")
self.size: int = size
self.data: dict[int, T] = {}
def __getitem__(self, index: int) -> T:
"""
Retrieves the element at the specified index.
Args:
index (int): The index of the element.
Returns:
T: The element at the specified index.
Raises:
IndexError: If index is out of bounds.
"""
if not 0 <= index < self.size:
raise IndexError("Index out of bounds.")
return self.data.get(index, 0) # Assuming default value is 0
def __setitem__(self, index: int, value: T) -> None:
"""
Sets the element at the specified index to the given value.
Args:
index (int): The index of the element.
value (T): The value to set.
Raises:
IndexError: If index is out of bounds.
"""
if not 0 <= index < self.size:
raise IndexError("Index out of bounds.")
if value != 0:
self.data[index] = value
elif index in self.data:
del self.data[index]
def to_dense(self) -> List[T]:
"""
Converts the sparse array to a dense list.
Returns:
List[T]: The dense list representation.
"""
return [self.data.get(i, 0) for i in range(self.size)] # Assuming default value is 0
def non_zero_elements(self) -> List[tuple[int, T]]:
"""
Returns a list of non-zero elements as tuples of (index, value).
Returns:
List[tuple[int, T]]: The list of non-zero elements.
"""
return list(self.data.items())
class ArrayUtilities:
"""
A utility class providing additional array-related functionalities.
"""
code
@staticmethod
def find_duplicates(arr: Array[T]) -> Array[T]:
"""
Finds and returns all duplicate elements in the array.
Args:
arr (Array[T]): The array to check for duplicates.
Returns:
Array[T]: An array containing all duplicate elements.
"""
seen: dict[T, int] = {}
duplicates: Array[T] = Array()
for i in range(len(arr)):
elem = arr[i]
if elem in seen:
if seen[elem] == 1:
duplicates.append(elem)
seen[elem] += 1
else:
seen[elem] = 1
return duplicates
@staticmethod
def rotate_right(arr: Array[T], k: int) -> None:
"""
Rotates the array to the right by k steps.
Args:
arr (Array[T]): The array to rotate.
k (int): Number of steps to rotate.
Raises:
ValueError: If k is negative.
"""
n = len(arr)
if k < 0:
raise ValueError("k must be non-negative.")
k = k % n
if k == 0:
return
ArrayUtilities._reverse(arr, 0, n - 1)
ArrayUtilities._reverse(arr, 0, k - 1)
ArrayUtilities._reverse(arr, k, n - 1)
@staticmethod
def _reverse(arr: Array[T], start: int, end: int) -> None:
"""
Reverses elements in the array from start to end indices.
Args:
arr (Array[T]): The array to reverse.
start (int): Starting index.
end (int): Ending index.
"""
while start < end:
arr[start], arr[end] = arr[end], arr[start]
start += 1
end -= 1
@staticmethod
def maximum_subarray(arr: Array[T]) -> T:
"""
Finds the contiguous subarray with the maximum sum using Kadane's algorithm.
Args:
arr (Array[T]): The array of integers.
Returns:
T: The maximum subarray sum.
Raises:
ValueError: If the array is empty.
"""
if len(arr) == 0:
raise ValueError("Array is empty.")
max_so_far = arr[0]
current_max = arr[0]
for i in range(1, len(arr)):
current_max = max(arr[i], current_max + arr[i])
max_so_far = max(max_so_far, current_max)
return max_so_far
@staticmethod
def merge_two_sorted_arrays(arr1: Array[T], arr2: Array[T]) -> Array[T]:
"""
Merges two sorted arrays into a single sorted array.
Args:
arr1 (Array[T]): The first sorted array.
arr2 (Array[T]): The second sorted array.
Returns:
Array[T]: The merged sorted array.
"""
merged = Array[T](len(arr1) + len(arr2))
i = j = 0
while i < len(arr1) and j < len(arr2):
if arr1[i] <= arr2[j]:
merged.append(arr1[i])
i += 1
else:
merged.append(arr2[j])
j += 1
while i < len(arr1):
merged.append(arr1[i])
i += 1
while j < len(arr2):
merged.append(arr2[j])
j += 1
return merged
Certainly! Below are comprehensive unit tests for your arrays.py module using both unittest and pytest. These tests cover the primary functionalities of each class and method you've implemented. You can expand upon these as needed to cover more edge cases or additional methods.
Using unittest
Create a separate test file, e.g., test_arrays_unittest.py, and include the following tests:
python
# test_arrays_unittest.py
import unittest
from arrays import (
Array,
ArrayAlgorithms,
MultiDimensionalArray,
SparseArray,
ArrayUtilities
)
class TestArray(unittest.TestCase):
def setUp(self):
self.array = Array[int]()
def test_initialization(self):
self.assertEqual(len(self.array), 0)
self.assertEqual(self.array._capacity, 16)
def test_append(self):
self.array.append(10)
self.assertEqual(len(self.array), 1)
self.assertEqual(self.array[0], 10)
def test_get_set_item(self):
self.array.append(20)
self.assertEqual(self.array[0], 20)
self.array[0] = 30
self.assertEqual(self.array[0], 30)
with self.assertRaises(IndexError):
_ = self.array[1]
def test_insert(self):
self.array.append(1)
self.array.append(3)
self.array.insert(1, 2)
self.assertEqual(self.array.to_list(), [1, 2, 3])
with self.assertRaises(IndexError):
self.array.insert(5, 10)
def test_remove(self):
self.array.append(5)
self.array.append(10)
self.array.append(5)
self.array.remove(5)
self.assertEqual(self.array.to_list(), [10, 5])
with self.assertRaises(ValueError):
self.array.remove(100)
def test_pop(self):
self.array.append(7)
self.array.append(8)
popped = self.array.pop(0)
self.assertEqual(popped, 7)
self.assertEqual(len(self.array), 1)
with self.assertRaises(IndexError):
self.array.pop(5)
def test_index_of(self):
self.array.append(9)
self.array.append(10)
self.assertEqual(self.array.index_of(10), 1)
self.assertEqual(self.array.index_of(100), -1)
def test_clear(self):
self.array.append(1)
self.array.append(2)
self.array.clear()
self.assertEqual(len(self.array), 0)
def test_contains(self):
self.array.append(3)
self.assertTrue(self.array.contains(3))
self.assertFalse(self.array.contains(4))
def test_resize(self):
for i in range(20):
self.array.append(i)
self.assertEqual(self.array._capacity, 32)
for _ in range(16):
self.array.pop(0)
self.assertEqual(self.array._capacity, 16)
class TestArrayAlgorithms(unittest.TestCase):
def setUp(self):
self.array = Array[int]()
for i in [1, 3, 5, 7, 9]:
self.array.append(i)
def test_linear_search_found(self):
index = ArrayAlgorithms.linear_search(self.array, 5)
self.assertEqual(index, 2)
def test_linear_search_not_found(self):
index = ArrayAlgorithms.linear_search(self.array, 4)
self.assertEqual(index, -1)
def test_binary_search_found(self):
index = ArrayAlgorithms.binary_search(self.array, 7)
self.assertEqual(index, 3)
def test_binary_search_not_found(self):
index = ArrayAlgorithms.binary_search(self.array, 2)
self.assertEqual(index, -1)
def test_bubble_sort(self):
unsorted_array = Array[int]()
for num in [5, 1, 4, 2, 8]:
unsorted_array.append(num)
ArrayAlgorithms.bubble_sort(unsorted_array)
self.assertEqual(unsorted_array.to_list(), [1, 2, 4, 5, 8])
def test_selection_sort(self):
unsorted_array = Array[int]()
for num in [64, 25, 12, 22, 11]:
unsorted_array.append(num)
ArrayAlgorithms.selection_sort(unsorted_array)
self.assertEqual(unsorted_array.to_list(), [11, 12, 22, 25, 64])
def test_insertion_sort(self):
unsorted_array = Array[int]()
for num in [12, 11, 13, 5, 6]:
unsorted_array.append(num)
ArrayAlgorithms.insertion_sort(unsorted_array)
self.assertEqual(unsorted_array.to_list(), [5, 6, 11, 12, 13])
def test_quick_sort(self):
unsorted_array = Array[int]()
for num in [10, 7, 8, 9, 1, 5]:
unsorted_array.append(num)
ArrayAlgorithms.quick_sort(unsorted_array)
self.assertEqual(unsorted_array.to_list(), [1, 5, 7, 8, 9, 10])
def test_merge_sort(self):
unsorted_array = Array[int]()
for num in [38, 27, 43, 3, 9, 82, 10]:
unsorted_array.append(num)
ArrayAlgorithms.merge_sort(unsorted_array)
self.assertEqual(unsorted_array.to_list(), [3, 9, 10, 27, 38, 43, 82])
class TestMultiDimensionalArray(unittest.TestCase):
def setUp(self):
self.md_array = MultiDimensionalArray([2, 3])
def test_initialization(self):
self.assertEqual(self.md_array.dimensions, [2, 3])
self.assertEqual(self.md_array.size, 6)
def test_set_get(self):
self.md_array.set([0, 0], 'a')
self.md_array.set([1, 2], 'b')
self.assertEqual(self.md_array.get([0, 0]), 'a')
self.assertEqual(self.md_array.get([1, 2]), 'b')
with self.assertRaises(IndexError):
self.md_array.get([2, 0])
def test_to_nested_list(self):
values = ['a', 'b', 'c', 'd', 'e', 'f']
for i in range(2):
for j in range(3):
self.md_array.set([i, j], values[i * 3 + j])
nested = self.md_array.to_nested_list()
self.assertEqual(nested, [['a', 'b', 'c'], ['d', 'e', 'f']])
class TestSparseArray(unittest.TestCase):
def setUp(self):
self.sparse = SparseArray[int](5)
def test_initialization(self):
self.assertEqual(self.sparse.size, 5)
self.assertEqual(self.sparse.to_dense(), [0, 0, 0, 0, 0])
def test_set_get_item(self):
self.sparse[0] = 10
self.sparse[3] = 20
self.assertEqual(self.sparse[0], 10)
self.assertEqual(self.sparse[3], 20)
self.assertEqual(self.sparse[1], 0)
with self.assertRaises(IndexError):
_ = self.sparse[5]
def test_set_zero(self):
self.sparse[2] = 30
self.assertEqual(self.sparse[2], 30)
self.sparse[2] = 0
self.assertEqual(self.sparse[2], 0)
self.assertNotIn(2, self.sparse.data)
def test_to_dense(self):
self.sparse[1] = 15
self.sparse[4] = 25
self.assertEqual(self.sparse.to_dense(), [0, 15, 0, 0, 25])
def test_non_zero_elements(self):
self.sparse[0] = 5
self.sparse[2] = 10
expected = [(0, 5), (2, 10)]
self.assertCountEqual(self.sparse.non_zero_elements(), expected)
class TestArrayUtilities(unittest.TestCase):
def setUp(self):
self.array = Array[int]()
for num in [1, 2, 3, 2, 4, 3, 5]:
self.array.append(num)
def test_find_duplicates(self):
duplicates = ArrayUtilities.find_duplicates(self.array)
self.assertEqual(duplicates.to_list(), [2, 3])
def test_rotate_right(self):
ArrayUtilities.rotate_right(self.array, 2)
self.assertEqual(self.array.to_list(), [4, 3, 1, 2, 3, 2, 5])
def test_rotate_right_full_rotation(self):
original = self.array.to_list().copy()
ArrayUtilities.rotate_right(self.array, len(self.array))
self.assertEqual(self.array.to_list(), original)
def test_rotate_right_zero(self):
original = self.array.to_list().copy()
ArrayUtilities.rotate_right(self.array, 0)
self.assertEqual(self.array.to_list(), original)
def test_rotate_right_negative(self):
with self.assertRaises(ValueError):
ArrayUtilities.rotate_right(self.array, -1)
def test_maximum_subarray(self):
self.array = Array[int]()
for num in [-2,1,-3,4,-1,2,1,-5,4]:
self.array.append(num)
max_sum = ArrayUtilities.maximum_subarray(self.array)
self.assertEqual(max_sum, 6) # [4,-1,2,1]
def test_maximum_subarray_empty(self):
empty_array = Array[int]()
with self.assertRaises(ValueError):
ArrayUtilities.maximum_subarray(empty_array)
def test_merge_two_sorted_arrays(self):
arr1 = Array[int]()
arr2 = Array[int]()
for num in [1, 3, 5]:
arr1.append(num)
for num in [2, 4, 6]:
arr2.append(num)
merged = ArrayUtilities.merge_two_sorted_arrays(arr1, arr2)
self.assertEqual(merged.to_list(), [1, 2, 3, 4, 5, 6])
def test_merge_two_sorted_arrays_with_duplicates(self):
arr1 = Array[int]()
arr2 = Array[int]()
for num in [1, 2, 2, 3]:
arr1.append(num)
for num in [2, 3, 4]:
arr2.append(num)
merged = ArrayUtilities.merge_two_sorted_arrays(arr1, arr2)
self.assertEqual(merged.to_list(), [1, 2, 2, 2, 3, 3, 4])
if __name__ == '__main__':
unittest.main()
Running the Tests
To run the unittest tests, execute the following command in your terminal:
bash
python test_arrays_unittest.py
Using pytest
Create another test file, e.g., test_arrays_pytest.py, and include the following tests:
python
Running the Tests
To run the pytest tests, ensure you have pytest installed:
bash
pip install pytest
Then execute the tests with:
bash
pytest test_arrays_pytest.py
Additional Tips
Organize Tests by Class/Functionality:
For larger modules, consider organizing tests into separate classes or modules based on functionality or the class being tested.
Use Fixtures for Reusability:
As demonstrated, pytest fixtures like empty_array and populated_array help create reusable test setups.
Cover Edge Cases:
Ensure that you test edge cases such as empty arrays, single-element arrays, boundary indices, etc.
Test Performance for Large Inputs:
For algorithms like sorting, you might want to test their behavior with very large arrays to ensure they perform as expected.
Mock External Dependencies:
If your classes interact with external libraries (e.g., torch), consider using mocking to simulate those interactions.
Continuous Integration:
Integrate your tests with CI/CD pipelines to automatically run tests on new changes.
By implementing these tests, you ensure that your array data structures and algorithms are robust, reliable, and maintainable. Feel free to expand upon these tests to cover more scenarios and edge cases as your project grows.