File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change
1
+ import random
1
2
from src .thread .utils import algorithm
2
3
3
4
@@ -20,3 +21,25 @@ def test_chunking_3():
20
21
(76 , 88 ),
21
22
(88 , 100 ),
22
23
]
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'\n Length: { dataset_length } \n Threads: { thread_count } \n Expected: { heap } \n Actual: { algorithm .chunk_split (dataset_length , thread_count )} '
You can’t perform that action at this time.
0 commit comments