% File: tests.pl
% includes commands to test the various parts of the code submitted.


%---------------------------------------------------------------

% tree examples in the restaurant domain

tree1(A) :- 
        A= t(bar,[y-T1,n-T2]),
        T1 =t(fri,[y-yes,n-no]),
        T2 =t(alt,[y-no,n-yes]).

tree2(A) :- A= 
           t(alt,[
             y-t(hun,[y-yes,n-no]),
             n-t(bar, [y-no,n-yes])
                  ]).

% assignment Section 2

test1a :- tree1(T1),tree_size(T1,Size),write(Size),nl.
test1b :- tree2(T2),tree_size(T2,Size),write(Size),nl.

% assignment Section 3

test2a :- tree1(T),evaluate(T,x1,Label),
          write('T1 classifies x1 as '),write(Label),nl.
test2b :- tree1(T),
          (tree_correct(T,x1)-> write('T1 correct on x1\n');
                                write('T1 wrong   on x1\n')).
test2c :- tree2(T),
          (tree_correct(T,x7)-> write('T2 correct on x7\n');
                                write('T2 wrong   on x7\n')).
test2d :- tree1(T),testtree(T).
test2e :- tree2(T),testtree(T).

% assignment Section 4

test3r :- learntree(simple,T),pretty_pr(T),nl,
          tree_size(T,Size),write('Tree size :'),
          write(Size),nl,
          testtree(T).

test3z :- learntree(simple,T),
          tree_size(T,Size),write('Tree size :'),
          write(Size),nl,
          testtree(T).

% assignment Section 5

% tests for the restaurant domain
% using attributes: alt, bar, fri, hun

test4ra :- training_data(L),remainder(alt,L,R),
          write('Remainder of alt is '),write(R),nl.

test4rb :- training_data(L),remainder(pat,L,R),
          write('Remainder of pat is '),write(R),nl.

test4rc :- training_data(L),gain(pat,L,G),
          write('Gain of pat is '),write(G),nl.

test4rd :- training_data(L),attributes(Attr),
          choose_attribute(gain,Attr,L,B,R),
          write('Best is '),write(B),write(' Rest is '),write(R),nl.

test4re :- learntree(gain,T),pretty_pr(T),
         tree_size(T,Size),write('Tree size :'),
         write(Size),nl,
         testtree(T).


% tests for the zoo domain
% using attributes: predator, legs

test4za :- training_data(L),remainder(predator,L,R),
           write('Remainder of predator is '),write(R),nl.

test4zb :- training_data(L),remainder(legs,L,R),
           write('Remainder of legs is '),write(R),nl.

test4zc :- training_data(L),attributes(Attr),
           choose_attribute(gain,Attr,L,B,R),
           write('Best is '),write(B),write(' Rest is '),write(R),nl.

test4zd :- learntree(gain,T),pretty_pr(T),
           tree_size(T,Size),write('Tree size :'),
           write(Size),nl,
           testtree(T).



% compiling all tests

allresttests :- 
            test1a, test1b, 
            test2a, test2b, test2c, test2d, test2e,
            test3r, 
            test4ra, test4rb, test4rc, test4rd, test4re.

allflagtests :- 
            test3f, 
            test4fa, test4fb, test4fc, test4fd.
