Skip to content

Commit

Permalink
Fix sorted testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
salt-die committed Nov 26, 2023
1 parent ae91671 commit 972d522
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/mind_the_gaps/gaps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from collections.abc import Callable
from dataclasses import dataclass, field
from functools import total_ordering
from itertools import pairwise
from operator import and_, or_, xor
from typing import Literal, Protocol, Self

Expand Down Expand Up @@ -173,8 +172,13 @@ def __post_init__(self):
if not isinstance(endpoint, Endpoint):
self.endpoints[i] = Endpoint(endpoint, "[" if i % 2 == 0 else "]")

if any(a >= b for a, b in pairwise(self.endpoints)):
raise GapsNotSorted("Intervals overlap or are unsorted.")
for i in range(len(self.endpoints) - 1):
a = self.endpoints[i]
b = self.endpoints[i + 1]
if a.value > b.value or (
a.value == b.value and a.boundary + b.boundary not in {"[]", ")("}
):
raise GapsNotSorted("Intervals overlap or are unsorted.")

def __invert__(self) -> Self:
return self ^ Gaps(
Expand Down

0 comments on commit 972d522

Please sign in to comment.