Skip to content

Commit 3ba1811

Browse files
test: Add dynamic chunking tests
1 parent 6c83a23 commit 3ba1811

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/test_algorithm.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import random
12
from src.thread.utils import algorithm
23

34

@@ -20,3 +21,25 @@ def test_chunking_3():
2021
(76, 88),
2122
(88, 100),
2223
]
24+
25+
26+
def test_chunking_dynamic():
27+
dataset_length = random.randint(400, int(10e6))
28+
thread_count = random.randint(2, 100)
29+
30+
expected_chunk_length_low = dataset_length // thread_count
31+
expected_chunk_high = dataset_length % thread_count
32+
33+
i = 0
34+
heap = []
35+
while i < dataset_length:
36+
chunk_length = expected_chunk_length_low + int(expected_chunk_high > 0)
37+
b = i + chunk_length
38+
39+
heap.append((i, b))
40+
expected_chunk_high -= 1
41+
i = b
42+
43+
assert (
44+
algorithm.chunk_split(dataset_length, thread_count) == heap
45+
), f'\nLength: {dataset_length}\nThreads: {thread_count}\nExpected: {heap}\nActual: {algorithm.chunk_split(dataset_length, thread_count)}'

0 commit comments

Comments
 (0)