:- module(testes23,[teste1/2,teste2/2,teste3/2,teste4/2,deve/3]). :- set_prolog_flag(unknown,fail). :- set_prolog_flag(report_error,false). :- discontiguous deve/3. :- style_check(-singleton). %%----------------------- supo(1,[3,4,4,5,2],[2,3,4,4,5]). supo(2,[[4,3,[2]]],[[3,4,[2]]]). supo(3,[[],1,[2,3],[1,2,3],2],[1,2,[],[1,2,3],[2,3]]). supo(4,[4,[4,3],[[5,4],7],[1,[[33]],3],[[],3]], [4,[1,3,[[33]]],[3,4],[3,[]],[7,[4,5]]]). teste1(N,R) :- header(superordena,R), teste1(N,R,1,0). teste1(N,_,5,N). teste1(N,R,Volta,Parcial) :- once(supo(Volta,L1,L2)), call_with_depth_limit(superordena(L1,LX),1000,RRR), (LX==L2,RRR<1000 -> passou(Volta,R), PP is Parcial + 1 ; npassou(Volta,R), PP is Parcial ), VV is Volta + 1, teste1(N,R,VV,PP). teste1(0,R,1,_) :- erro(superordena,R). %---- xdia(1,[[0, 3, 4],[0, 0, 3],[0,0,2]],sim). xdia(2,[[1,2],[0,1],[0,1]],nao). xdia(3,[[0, 1, 0],[1,2,3],[0,0,0]],nao). xdia(4,[[1,4,4,0],[0,0,5,5],[0,0,6,6],[0,0,0,7]],sim). teste2(N,R) :- header(triangular,R), teste2(N,R,1,0). teste2(N,_,5,N). teste2(N,R,Volta,Parcial) :- once(xdia(Volta,L1,L2)), (triangular(L1) -> (L2 = sim -> passou(Volta,R), PP is Parcial + 1 ; npassou(Volta,R), PP is Parcial ) ; (L2 = nao -> passou(Volta,R), PP is Parcial + 1 ; npassou(Volta,R), PP is Parcial ) ), VV is Volta + 1, teste2(N,R,VV,PP). teste2(0,R,1,_) :- erro(triangular,R). %---------------------- grf(1,[aresta(a,b,2),aresta(b,c,1),aresta(c,d,1),aresta(b,d,4) ,aresta(e,f,1),aresta(f,g,1),aresta(e,g,1) ,aresta(h,i,1)], [[a,b,c,d,8],[e,f,g,3],[h,i,1]]). grf(2, [aresta(c, b, 2), aresta(a, b, 1), aresta(b, c, 2), aresta(a, d, 1), aresta(b, a, 1)], [[a, b, d, c, 4]]). grf(3, [aresta(a,b,1),aresta(b,c,2),aresta(a,d,1),aresta(b,e,1),aresta(c,f,1) ,aresta(d,e,1),aresta(e,g,4),aresta(e,i,4),aresta(f,i,4) ,aresta(g,h,5),aresta(h,i,5)], [[a,b,c,d,e,f,g,h,i,29]]). grf(4,[aresta(a, b, 1), aresta(c, d, 10)], [[a,b,1],[c,d,10]]). teste3(N,R) :- header(componentes,R), teste3(N,R,1,0). teste3(N,_,5,N). teste3(N,R,Volta,Parcial) :- once(grf(Volta,L1,L2)), call_with_depth_limit(componentes(L1,LX),1000,RRR), (congru(L2,LX),RRR<1000 -> passou(Volta,R), PP is Parcial + 1 ; npassou(Volta,R), PP is Parcial ), VV is Volta + 1, teste3(N,R,VV,PP). teste3(0,R,1,_) :- erro(componentes,R). congru(A,B) :- length(A,N), length(B,N), sort(A,AA), sort(B,BB), cong(AA,BB). cong([],[]). cong([A|B],[X|Y]) :- sort(A,AA), sort(X,XX),!, AA = XX, cong(B,Y). %-------------------- teste4(N,R) :- header('banco/devedor',R),!, load_files('/l/wainer/g/lista4/deve1.pl',[silent(true)]), testa_banco(N1,R), (N1 = 1 -> format(R," testa banco OK~n",[]) ; format(R," testa banco ERRADO~n",[]) ), testa_devedor(N2,R), (N2 = 1 -> format(R," testa maiordevedor OK~n",[]) ; format(R," testa maiordevedor ERRADO~n",[]) ), N is 2*(N1 + N2). testa_banco(N,R) :- call_with_depth_limit(banco(X),1000,RRR), (X = c,RRR<1000 -> N = 1 ; N = 0). testa_banco(0,R) :- erro(banco,R). testa_devedor(N,R) :- call_with_depth_limit(maiordevedor(X),1000,RRR), (X = b,RRR<1000 -> N = 1 ; N = 0). testa_devedor(0,R) :- erro(maiordevedor,R).