37 lines
1.1 KiB
Julia
37 lines
1.1 KiB
Julia
|
|
function test_random_walk(g::DAG, n::Int64)
|
|
# the purpose here is to do "random" operations and reverse them again and validate that the graph stays the same and doesn't diverge
|
|
reset_graph!(g)
|
|
|
|
properties = graph_properties(g)
|
|
|
|
for i in 1:n
|
|
# choose push or pop
|
|
if rand(Bool)
|
|
# push
|
|
opt = get_operations(g)
|
|
|
|
# choose one of fuse/split/reduce
|
|
option = rand(1:3)
|
|
if option == 1 && !isempty(opt.nodeFusions)
|
|
push_operation!(g, rand(collect(opt.nodeFusions)))
|
|
elseif option == 2 && !isempty(opt.nodeReductions)
|
|
push_operation!(g, rand(collect(opt.nodeReductions)))
|
|
elseif option == 3 && !isempty(opt.nodeSplits)
|
|
push_operation!(g, rand(collect(opt.nodeSplits)))
|
|
else
|
|
i = i - 1
|
|
end
|
|
else
|
|
# pop
|
|
if (can_pop(g))
|
|
pop_operation!(g)
|
|
else
|
|
i = i - 1
|
|
end
|
|
end
|
|
end
|
|
|
|
return reset_graph!(g)
|
|
end
|