Skip to content
Merged
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
24 changes: 24 additions & 0 deletions tests/test_lowering.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@
from math_spec.where_parser import (
BooleanLiteralNode,
DimensionComparisonNode,
DimensionMembershipNode,
LookupMembershipNode,
ParameterComparisonNode,
ParameterDefinedNode,
ParameterMembershipNode,
)
from tests.fixtures import DISPATCH_MODEL, SMALL_MODEL, override, schema_of

Expand Down Expand Up @@ -167,6 +170,27 @@ def test_where_lowering(dispatch_schema, where, expected):
assert where_of(where, Namespace.of(dispatch_schema), 't') == expected


@pytest.mark.parametrize(
('where', 'expected'),
[
pytest.param('c in [1.5, 2.5]', ParameterMembershipNode('c', (1.5, 2.5)), id='over-a-parameter'),
pytest.param("g in ['g1', 'g2']", DimensionMembershipNode('g', ('g1', 'g2')), id='over-a-dimension'),
pytest.param("lk in ['h1']", LookupMembershipNode('lk', 'g', ('h1',)), id='over-a-groupable-lookup'),
pytest.param("tag in ['north']", LookupMembershipNode('tag', 'g', ('north',)), id='over-a-label-space'),
],
)
def test_a_membership_mask_reaches_the_program_unchanged(where, expected):
"""A `where` atom *is* the program's predicate — no lowering case rewrites one.

That is what lets a new atom (#254) cost nothing in `lowering.py`, and it is
the half no other suite covers: resolution proves the node is built and the
typesetter proves it prints, while only this asks whether it survives the
pass in between.
"""
program = lower_program(expand_piecewise(schema_of(SMALL_MODEL, **{'variables.p.where': where})))
assert program.variables['p'].where == expected, 'the atom the file wrote, not a rewrite of it'


def test_a_literal_amount_resolves_to_one_signed_number(dispatch_schema):
"""`offset=-1` parses as a unary minus over `1`; after resolution it is `-1`, for every reader alike."""
ns = Namespace.of(dispatch_schema)
Expand Down
Loading