-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from octoenergy/ranges.any-gaps
Add `ranges.any_gaps`
- Loading branch information
Showing
4 changed files
with
117 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,27 @@ | ||
import random | ||
from decimal import Decimal as D | ||
|
||
import pytest | ||
|
||
from xocto import ranges | ||
|
||
|
||
def test_any_overlapping(benchmark): | ||
ranges_ = [ranges.Range(D(i), D(i + 1)) for i in range(1000)] | ||
random.seed(42) | ||
def _shuffled(ranges_, *, seed=42): | ||
ranges_ = ranges_.copy() | ||
random.seed(seed) | ||
random.shuffle(ranges_) | ||
return ranges_ | ||
|
||
|
||
@pytest.mark.benchmark(group="ranges.any_overlapping") | ||
def test_any_overlapping(benchmark): | ||
ranges_ = _shuffled([ranges.Range(D(i), D(i + 1)) for i in range(1000)]) | ||
any_overlapping = benchmark(ranges.any_overlapping, ranges_) | ||
assert any_overlapping is False | ||
|
||
|
||
@pytest.mark.benchmark(group="ranges.any_gaps") | ||
def test_any_gaps(benchmark): | ||
ranges_ = _shuffled([ranges.Range(D(i), D(i + 1)) for i in range(1000)]) | ||
any_overlapping = benchmark(ranges.any_gaps, ranges_) | ||
assert any_overlapping is False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters