Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding a falling test of varRange #263

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tests/core/metahandlers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ class WeightedStringHandlerM(Root):
),
]

@dataclass
class Number():
number: int

@dataclass
class GenerateNumber(Root):
n: Annotated[Number, VarRange([Number(0),Number(1),Number(2)])]


class TestMetaHandler:
def test_int(self):
Expand Down Expand Up @@ -180,3 +188,12 @@ def test_union_int(self):
assert isinstance(n, UnionIntRangeM)
assert (0 <= n.x <= 10) or (20 <= n.x <= 30)
assert isinstance(n, Root)

def test_var_with_custom_class(self):
r = NativeRandomSource(seed=1)
g = extract_grammar([GenerateNumber], Root)
decider = MaxDepthDecider(r, g, 3)
n = random_node(r, g, Root, decider=decider)
assert isinstance(n, GenerateNumber)
assert n.x.number in [1,2,3]
assert isinstance(n, Root)
Loading