Files
troupe-standup/wizard-work/spark/test_array_intersection.py
T

32 lines
817 B
Python

#!/usr/bin/env python3
"""Test file for array_intersection.py"""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
from array_intersection import array_intersection
# Test cases
tests = [
([1, 2, 3, 4, 5], [3, 4, 5, 6, 7], [3, 4, 5]),
([1, 1, 2, 2], [2, 2, 3, 3], [2]),
([], [1, 2, 3], []),
([1, 2, 3], [], []),
(['a', 'b'], ['b', 'c'], ['b']),
]
all_passed = True
for arr1, arr2, expected in tests:
result = array_intersection(arr1, arr2)
if result != expected:
print(f'FAIL: {arr1} ∩ {arr2} = {result}, expected {expected}')
all_passed = False
else:
print(f'PASS: {arr1} ∩ {arr2} = {result}')
if all_passed:
print('All tests passed!')
sys.exit(0)
else:
print('Some tests failed!')
sys.exit(1)