|
| 1 | +#%% |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +import numpy as np |
| 5 | +from intervaltree import Interval, IntervalTree |
| 6 | + |
| 7 | +from svirlpool.util import covtree |
| 8 | + |
| 9 | +#%% |
| 10 | + |
| 11 | +# ================================================================ |
| 12 | +# ----------100 -> 1,0,100,r0 |
| 13 | +# 20----------120 -> 1,20,120,r1 |
| 14 | +# 80----------180 -> 1,80,180,r2 |
| 15 | +# -> (0,20,1), (20,80,2), (80,100,3), (100,120,2), (120,180,1) |
| 16 | +# ================================================================ |
| 17 | + |
| 18 | +def test_parallel_coverage_computation__simple(): |
| 19 | + all_positions = {'1': [0, 20, 80, 100, 120, 180]} |
| 20 | + intervall_trees = {'1': IntervalTree([Interval(0, 100, 'r0'), Interval(20, 120, 'r1'), Interval(80, 180, 'r2')])} |
| 21 | + num_workers=2 |
| 22 | + result = covtree.parallel_coverage_computation(all_positions=all_positions, intervall_trees=intervall_trees, num_workers=num_workers) |
| 23 | + expected = {'1': IntervalTree([Interval(0, 20, 1), Interval(20, 80, 2), Interval(80, 100, 3), Interval(100, 120, 2), Interval(120, 180, 1)])} |
| 24 | + assert result == expected |
| 25 | + |
| 26 | +def test_construct_interval_trees_simple(): |
| 27 | + data = np.array([ |
| 28 | + ['1', '0', '100', 'r0'], |
| 29 | + ['1', '20', '120', 'r1'], |
| 30 | + ['1', '80', '180', 'r2']]) |
| 31 | + result = covtree.construct_interval_trees(data=data) |
| 32 | + expected = {'1': IntervalTree([Interval(0, 100, 'r0'), Interval(20, 120, 'r1'), Interval(80, 180, 'r2')])}, {'1': [0, 20, 80, 100, 120, 180]} |
| 33 | + assert result[0] == expected[0] |
| 34 | + assert result[1] == expected[1] |
0 commit comments