% ------------------------------------------------------------------------------------------------------
% Test Case to meta test the test case meta test query functions
% ------------------------------------------------------------------------------------------------------

testcase("metaTestCase.prova").

%-----------------------------------------------------------------------
% Imported libraries
%-----------------------------------------------------------------------
:-eval(consult('ContractLog/utils.prova')).
:-eval(consult('ContractLog/math.prova')).
:-eval(consult('ContractLog/list.prova')).
:-eval(consult('ContractLog/testcase.prova')).
:-eval(consult('ContractLog/update.prova')).


% ------------------------------------------------------------------------------------------------------
% Meta test rules 
% ------------------------------------------------------------------------------------------------------

p(X):-q(X).


% ------------------------------------------------------------------------------------------------------
% Test facts
% ------------------------------------------------------------------------------------------------------

q(a).
q(b).
q(c).
q(d).
neg(p(f)).

% ------------------------------------------------------------------------------------------------------
% Tests
% ------------------------------------------------------------------------------------------------------

% meta test testQuery
testSuccess("testQuery test 1","succeeded"):-testcase("metaTestCase.prova"), testQuery(p(a)). 
testFailure("testQuery test 1","failed - Can not derive p(a)"):-not(testSuccess("testQuery test 1",Message)).

% meta test testQuery
testSuccess("testQuery test 2","succeeded"):-testcase("metaTestCase.prova"), testQuery(p(X)). 
testFailure("testQuery test 2","failed - No answers for p(X)"):-not(testSuccess("testQuery test 2",Message)).

% meta test testNotQuery
testSuccess("testNotQuery test","succeeded"):-testcase("metaTestCase.prova"), testNotQuery(p(e)). 
testFailure("testNotQuery test","failed - p(e) can be derived"):-not(testSuccess("testNotQuery test",Message)).

% meta test testNegQuery
testSuccess("testNegQuery test","succeeded"):-testcase("metaTestCase.prova"), testNegQuery(p(f)). 
testFailure("testNegQuery test","failed - Can not derive neg(p(f))"):-not(testSuccess("testNegQuery test",Message)).

% meta test testNumberOfResults
testSuccess("testNumberOfResults test 1","succeeded"):-testcase("metaTestCase.prova"), testNumberOfResults(p(X),4). 
testFailure("testNumberOfResults test 1","failed - Wrong number of results"):-not(testSuccess("testNumberOfResults test 1",Message)).

% meta test testNumberOfResults
testSuccess("testNumberOfResults test 2","succeeded"):-testcase("metaTestCase.prova"), testNumberOfResults(p(Y),Y,4). 
testFailure("testNumberOfResults test 2","failed - Wrong number of results"):-not(testSuccess("testNumberOfResults test 2",Message)).

% meta test testNumberOfResultsMore
testSuccess("testNumberOfResultsMore test 1","succeeded"):-testcase("metaTestCase.prova"), testNumberOfResultsMore(p(X),3). 
testFailure("testNumberOfResultsMore test 1","failed - Wrong number of results"):-not(testSuccess("testNumberOfResultsMore test 1",Message)).

% meta test testNumberOfResultsMore
testSuccess("testNumberOfResultsMore test 2","succeeded"):-testcase("metaTestCase.prova"), testNumberOfResultsMore(p(Y),Y,3). 
testFailure("testNumberOfResultsMore test 2","failed - Wrong number of results"):-not(testSuccess("testNumberOfResultsMore test 2",Message)).

% meta test testNumberOfResultsLess
testSuccess("testNumberOfResultsLess test 1","succeeded"):-testcase("metaTestCase.prova"), testNumberOfResultsLess(p(X),5). 
testFailure("testNumberOfResultsLess test 1","failed - Wrong number of results"):-not(testSuccess("testNumberOfResultsLess test 1",Message)).

% meta test testNumberOfResultsLess
testSuccess("testNumberOfResultsLess test 2","succeeded"):-testcase("metaTestCase.prova"), testNumberOfResultsLess(p(Y),Y,5). 
testFailure("testNumberOfResultsLess test 2","failed - Wrong number of results"):-not(testSuccess("testNumberOfResultsLess test 2",Message)).

% meta test testResult 2
testSuccess("testResult test","succeeded"):-testcase("metaTestCase.prova"), testResult(p(X),p(a)). 
testFailure("testResult test","failed - Wrong result"):-not(testSuccess("testResult test",Message)).

% meta test testResults (positive)
testSuccess("testResults test 1","succeeded"):-testcase("metaTestCase.prova"), testResults(p(Y),Y,[a,b,c]). 
testFailure("testResults test 1","failed - Wrong answers for variable"):-not(testSuccess("testResults test 1",Message)).

% meta test testResults 2 (negative)
testSuccess("testResults test 2","succeeded"):-testcase("metaTestCase.prova"), testResults(neg(p(Y)),Y,[f]). 
testFailure("testResults test 2","failed - Wrong answers for variable"):-not(testSuccess("testResults test 2",Message)).

% meta test testResultsOrder 
testSuccess("testResultsOrder test","succeeded"):-testcase("metaTestCase.prova"), testResultsOrder(p(Y),Y,[a,b,c]). 
testFailure("testResultsOrder test","failed - Wrong answers or order of answers for variable"):-not(testSuccess("testResultsOrder test",Message)).

% meta test testQueryTime
testSuccess("testQueryTime test","succeeded"):-testcase("metaTestCase.prova"), testQueryTime(p(a),10000). 
testFailure("testQueryTime test","failed - Query took too much time"):-not(testSuccess("testQueryTime test",Message)).

% meta test testNotQueryTime
testSuccess("testNotQueryTime test","succeeded"):-testcase("metaTestCase.prova"), testNotQueryTime(p(e),10000). 
testFailure("testNotQueryTime test","failed - Query took too much time"):-not(testSuccess("testNotQueryTime test",Message)).

% meta test testNegQueryTime
testSuccess("testNegQueryTime test","succeeded"):-testcase("metaTestCase.prova"), testNegQueryTime(p(f),10000). 
testFailure("testNegQueryTime test","failed - Query took too much time"):-not(testSuccess("testNegQueryTime test",Message)).

% meta test getQueryTime
testSuccess("getQueryTime test",Time):-testcase("metaTestCase.prova"), getQueryTime(p(a),Time). 
testFailure("getQueryTime test","failed - Query failed"):-not(testSuccess("getQueryTime test",Message)).

runTest("metaTestCase.prova"):-
		testSuccess("testQuery test 1",Message),
		testSuccess("testQuery test 2",Message),
		testSuccess("testNotQuery test","succeeded"),
		testSuccess("testNegQuery test","succeeded"),
		testSuccess("testNumberOfResults test 1","succeeded"),
		testSuccess("testNumberOfResults test 2","succeeded"),
		testSuccess("testNumberOfResultsMore test 1","succeeded"),
		testSuccess("testNumberOfResultsMore test 2","succeeded"),
		testSuccess("testNumberOfResultsLess test 1","succeeded"),
		testSuccess("testNumberOfResultsLess test 2","succeeded"),
		testSuccess("testResult test","succeeded"),
		testSuccess("testResults test 1","succeeded"),
		testSuccess("testResults test 2","succeeded"),
		testSuccess("testResultsOrder test","succeeded"),
		testSuccess("testQueryTime test","succeeded"),
		testSuccess("testNotQueryTime test","succeeded"),
		testSuccess("testNegQueryTime test","succeeded"),
		testSuccess("getQueryTime test",Time).