Skip to content

Commit e56e7e7

Browse files
committed
tests + fixed unreachable states left in intersection
1 parent 2344380 commit e56e7e7

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

grape/automaton/tree_automaton.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ def __product_rules__(
146146

147147
def read_intersection(self, other: "DFTA[W, V]") -> "DFTA[tuple[U, W], V]":
148148
new_finals = set(el for el in itertools.product(self.finals, other.finals))
149-
return DFTA(self.__product_rules__(other), new_finals)
149+
d = DFTA(self.__product_rules__(other), new_finals)
150+
d.reduce()
151+
return d
150152

151153
def read_union(self, other: "DFTA[W, V]") -> "DFTA[tuple[U, W], V]":
152154
new_finals = set(

tests/cli/test_intersection.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from grape.automaton_generator import (
2+
depth_constraint,
3+
grammar_by_saturation,
4+
size_constraint,
5+
)
6+
from grape.dsl import DSL
7+
8+
9+
dsl = DSL(
10+
{
11+
"1": ("int", 1),
12+
"+": ("int -> int -> int", lambda x, y: x + y),
13+
}
14+
)
15+
16+
max_size = 5
17+
18+
19+
def test():
20+
size = grammar_by_saturation(dsl, "int->int", [size_constraint(0, 5)])
21+
depth = grammar_by_saturation(dsl, "int->int", [depth_constraint(0, 2)])
22+
inter = size.read_intersection(depth)
23+
other = grammar_by_saturation(
24+
dsl, "int->int", [depth_constraint(0, 2), size_constraint(0, 5)]
25+
)
26+
a = inter.trees_by_size(100)
27+
assert a == other.trees_by_size(100)

0 commit comments

Comments
 (0)