Skip to content

Commit

Permalink
Use math.inf
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcr committed Nov 9, 2023
1 parent ad3385a commit bf552e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 3 additions & 5 deletions src/urn/constraint.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import itertools
import math
from collections.abc import Iterable, Sequence, Generator
from dataclasses import dataclass


INFINITY = float("inf")


@dataclass(eq=True)
class ConstraintItem:
"""Constraint on item.
Expand All @@ -14,7 +12,7 @@ class ConstraintItem:
"""
name: str
min_: int = 0
max_: int | float = INFINITY
max_: int | float = math.inf

def __and__(self, other):
if not isinstance(other, ConstraintItem):
Expand Down Expand Up @@ -52,4 +50,4 @@ def union_constraint_disjuncts(
for n in range(1, len(seq) + 1):
combs = itertools.combinations(seq, n)
for cmb in combs:
yield n, reduce_constraints(itertools.chain.from_iterable(cmb))
yield n, reduce_constraints(itertools.chain.from_iterable(cmb))
8 changes: 5 additions & 3 deletions tests/test_parsing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import math

import lark
import pytest

from urn.constraint import ConstraintItem, INFINITY
from urn.constraint import ConstraintItem
from urn.computation import ComputationDescription
from urn.constants import ComputationType, ComputationAction
from urn.parsing import BuildComputation
Expand Down Expand Up @@ -46,7 +48,7 @@ def parser(request):
selection_range=None,
collection={"A": 7},
constraints=[
[ConstraintItem("A", 0, 6), ConstraintItem("A", 4, INFINITY)]
[ConstraintItem("A", 0, 6), ConstraintItem("A", 4, math.inf)]
],
),
id="Count draw, two constraints on same item",
Expand All @@ -70,7 +72,7 @@ def parser(request):
selection_range=None,
collection={"A": 7},
constraints=[
[ConstraintItem("A", 5, INFINITY), ConstraintItem("A", 0, 6)]
[ConstraintItem("A", 5, math.inf), ConstraintItem("A", 0, 6)]
],
),
id="Count draw, repeated AND constraint using ','",
Expand Down

0 comments on commit bf552e3

Please sign in to comment.