Skip to content

Commit 700a8c6

Browse files
committed
Add more tests for DAG CSE
1 parent 48cc5a6 commit 700a8c6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/cse.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,31 @@ end
1818
@test length(sorted_nodes) == 3
1919
@test isequal(sorted_nodes[1].rhs, a + b)
2020
@test isequal(sin(sorted_nodes[1].lhs), sorted_nodes[2].rhs)
21+
2122
expr = (a + b)^(a + b)
2223
sorted_nodes = topological_sort(expr)
2324
@test length(sorted_nodes) == 2
2425
@test isequal(sorted_nodes[1].rhs, a + b)
2526
ab_node = sorted_nodes[1].lhs
2627
@test isequal(ab_node^ab_node, sorted_nodes[2].rhs)
28+
let_expr = cse(expr)
29+
@test length(let_expr.pairs) == 1
30+
@test isequal(let_expr.pairs[1].rhs, a + b)
31+
corresponding_sym = let_expr.pairs[1].lhs
32+
@test isequal(let_expr.body, corresponding_sym^corresponding_sym)
33+
34+
expr = a + b
35+
sorted_nodes = topological_sort(expr)
36+
@test length(sorted_nodes) == 1
37+
@test isequal(sorted_nodes[1].rhs, a + b)
38+
let_expr = cse(expr)
39+
@test isempty(let_expr.pairs)
40+
@test isequal(let_expr.body, a + b)
41+
42+
expr = a
43+
sorted_nodes = topological_sort(expr)
44+
@test isempty(sorted_nodes)
45+
let_expr = cse(expr)
46+
@test isempty(let_expr.pairs)
47+
@test isequal(let_expr.body, a)
2748
end

0 commit comments

Comments
 (0)