:- import abolish_table_pred/1, abolish_table_call/1 from tables.
% stress tests correct gc of layered abolishes of the same predicate

test:- test_pred_abolish(10),
	test_subgoal_abolish(10).

test_pred_abolish(0):-!,
	abolish_table_pred(tc_lr_p/2).
test_pred_abolish(N):-
	writeln(got_through_pred(N)),
	abolish_table_pred(tc_lr_p/2),
	(tc_lr_p(1,_),fail ; true),
	N1 is N - 1,
	test_pred_abolish(N1).

test_subgoal_abolish(0):-!,
	abolish_table_call(tc_lr_p(1,_)).
test_subgoal_abolish(N):-
	writeln(got_through_subgoal(N)),
	abolish_table_call(tc_lr_p(1,_)),
	(tc_lr_p(1,_),fail ; true),
	N1 is N - 1,
	test_subgoal_abolish(N1).

:- table tc_lr_p/2.
tc_lr_p(X,Y):- edge(X,Y).
tc_lr_p(X,Y):- tc_lr_p(X,Z),edge(Z,Y).

edge(X,Y):- X < 100,Y is X + 1.

