Tests Struct

Jan Burse, created Nov 06. 2019
/**
* Prolog code for the aggregate test cases.
*
* Warranty & Liability
* To the extent permitted by applicable law and unless explicitly
* otherwise agreed upon, XLOG Technologies GmbH makes no warranties
* regarding the provided information. XLOG Technologies GmbH assumes
* no liability that any problems might be solved with the information
* provided by XLOG Technologies GmbH.
*
* Rights & License
* All industrial property rights regarding the information - copyright
* and patent rights in particular - are the sole property of XLOG
* Technologies GmbH. If the company was not the originator of some
* excerpts, XLOG Technologies GmbH has at least obtained the right to
* reproduce, change and translate the information.
*
* Reproduction is restricted to the whole unaltered document. Reproduction
* of the information is only allowed for non-commercial uses. Selling,
* giving away or letting of the execution of the library is prohibited.
* The library can be distributed as part of your applications and libraries
* for execution provided this comment remains unchanged.
*
* Restrictions
* Only to be distributed with programs that add significant and primary
* functionality to the library. Not to be distributed with additional
* software intended to replace any components of the library.
*
* Trademarks
* Jekejeke is a registered trademark of XLOG Technologies GmbH.
*/
:- use_package(library(jekdev/reference/testing)).
:- multifile runner:ref/4.
:- discontiguous runner:ref/4.
:- multifile runner:case/4.
:- discontiguous runner:case/4.
:- use_module(library(advanced/aggregate)).
:- use_module(library(advanced/arith)).
:- use_module(library(basic/lists)).
/* bagof(T, A1^...^An^G, L, O) */
/* derived from bagof/3 test cases, type(hash) preserves input order */
runner:ref(bagof, 4, extend_struct, 'XLOG 2.4.1').
runner:case(bagof, 4, extend_struct, 'XLOG 2.4.1, XLOG 1a') :-
findall(Y-L, bagof(X, ((Y = 2; Y = 1; Y = 3), (X = 2; X = Y; X = 2)), L, [type(hash)]), [R|_]),
R == 2-[2, 2, 2].
runner:case(bagof, 4, extend_struct, 'XLOG 2.4.1, XLOG 1b') :-
findall(Y-L, bagof(X, ((Y = 2; Y = 1; Y = 3), (X = 2; X = Y; X = 2)), L, [type(hash)]), [_, R|_]),
R == 1-[2, 1, 2].
runner:case(bagof, 4, extend_struct, 'XLOG 2.4.1, XLOG 1c') :-
findall(Y-L, bagof(X, ((Y = 2; Y = 1; Y = 3), (X = 2; X = Y; X = 2)), L, [type(hash)]), [_, _, R|_]),
R == 3-[2, 3, 2].
runner:case(bagof, 4, extend_struct, 'XLOG 2.4.1, XLOG 1d') :-
findall(Y-L, bagof(X, ((Y = 2; Y = 1; Y = 3), (X = 2; X = Y; X = 2)), L, [type(hash)]), [_, _, _]).
/* setof(T, A1^...^An^G, L, O) */
/* derived from setof/3 test cases, type(hash) preserves input order */
runner:ref(setof, 4, extend_struct, 'XLOG 2.4.2').
runner:case(setof, 4, extend_struct, 'XLOG 2.4.2, XLOG 1a') :-
findall(Y-L, setof(X, ((Y = 2; Y = 1; Y = 3), (X = 2; X = Y; X = 2)), L, [type(hash)]), [R|_]),
R == 2-[2].
runner:case(setof, 4, extend_struct, 'XLOG 2.4.2, XLOG 1b') :-
findall(Y-L, setof(X, ((Y = 2; Y = 1; Y = 3), (X = 2; X = Y; X = 2)), L, [type(hash)]), [_, R|_]),
R == 1-[2, 1].
runner:case(setof, 4, extend_struct, 'XLOG 2.4.2, XLOG 1c') :-
findall(Y-L, setof(X, ((Y = 2; Y = 1; Y = 3), (X = 2; X = Y; X = 2)), L, [type(hash)]), [_, _, R|_]),
R == 3-[2, 3].
runner:case(setof, 4, extend_struct, 'XLOG 2.4.2, XLOG 1d') :-
findall(Y-L, setof(X, ((Y = 2; Y = 1; Y = 3), (X = 2; X = Y; X = 2)), L, [type(hash)]), [_, _, _]).
/* aggregate_all(A, G, S): */
runner:ref(aggregate_all, 3, extend_struct, 'XLOG 2.4.3').
runner:case(aggregate_all, 3, extend_struct, 'XLOG 2.4.3, XLOG 1') :-
aggregate_all(sum(X), between(1, 10, X), S),
S == 55.
runner:case(aggregate_all, 3, extend_struct, 'XLOG 2.4.3, XLOG 2') :-
aggregate_all((sum(X), max(X)), between(1, 10, X), S),
S == (55, 10).
runner:case(aggregate_all, 3, extend_struct, 'XLOG 2.4.3, XLOG 3') :-
aggregate_all(sum(1), fail, S),
S == 0.
runner:case(aggregate_all, 3, extend_struct, 'XLOG 2.4.3, XLOG 4') :-
catch(aggregate_all(_, between(1, 10, _), _), error(E, _), true),
E == instantiation_error.
runner:case(aggregate_all, 3, extend_struct, 'XLOG 2.4.3, XLOG 5') :-
catch(aggregate_all(sum(_), 1, _), error(E, _), true),
E == type_error(callable, 1).
runner:case(aggregate_all, 3, extend_struct, 'XLOG 2.4.3, XLOG 6') :-
aggregate_all(first(@<, X), member(X, [goedel, escher, bach]), S),
S == bach.
/* aggregate_all(A, G, S, O): */
/* derived from aggregate_all/3 test cases, eager(true) returns results earlier */
runner:ref(aggregate_all, 4, extend_struct, 'XLOG 2.4.4').
runner:case(aggregate_all, 4, extend_struct, 'XLOG 2.4.4, XLOG 1a') :-
findall(N, aggregate_all(max(X), (X = 1; X = 2; X = 1), N, [eager(true)]), [R|_]),
R == 1.
runner:case(aggregate_all, 4, extend_struct, 'XLOG 2.4.4, XLOG 1b') :-
findall(N, aggregate_all(max(X), (X = 1; X = 2; X = 1), N, [eager(true)]), [_, R|_]),
R == 2.
runner:case(aggregate_all, 4, extend_struct, 'XLOG 2.4.4, XLOG 1c') :-
findall(N, aggregate_all(max(X), (X = 1; X = 2; X = 1), N, [eager(true)]), [_, _]).
/* aggregate(A, G, S): */
runner:ref(aggregate, 3, extend_struct, 'XLOG 2.4.5').
runner:case(aggregate, 3, extend_struct, 'XLOG 2.4.5, XLOG 1a') :-
findall(Y-S, aggregate(sum(X), ((Y = 2; Y = 1; Y = 2),
between(1, 3, X)), S), [R|_]),
R == 1-6.
runner:case(aggregate, 3, extend_struct, 'XLOG 2.4.5, XLOG 1b') :-
findall(Y-S, aggregate(sum(X), ((Y = 2; Y = 1; Y = 2),
between(1, 3, X)), S), [_, R|_]),
R == 2-12.
runner:case(aggregate, 3, extend_struct, 'XLOG 2.4.5, XLOG 1c') :-
findall(Y-S, aggregate(sum(X), ((Y = 2; Y = 1; Y = 2),
between(1, 3, X)), S), [_, _]).
runner:case(aggregate, 3, extend_struct, 'XLOG 2.4.5, XLOG 2a') :-
findall((Y-S, A-B), aggregate((sum(X), max(X)), ((Y = A; Y = B; Y = A),
between(1, 3, X)), S), [(R, A-B)|_]),
R == A-(12, 3).
runner:case(aggregate, 3, extend_struct, 'XLOG 2.4.5, XLOG 2b') :-
findall((Y-S, A-B), aggregate((sum(X), max(X)), ((Y = A; Y = B; Y = A),
between(1, 3, X)), S), [_, (R, A-B)|_]),
R == B-(6, 3).
runner:case(aggregate, 3, extend_struct, 'XLOG 2.4.5, XLOG 2c') :-
findall((Y-S, A-B), aggregate((sum(X), max(X)), ((Y = A; Y = B; Y = A),
between(1, 3, X)), S), [_, _]).
runner:case(aggregate, 3, extend_struct, 'XLOG 2.4.5, XLOG 3') :-
\+ aggregate(sum(1), fail, _).
runner:case(aggregate, 3, extend_struct, 'XLOG 2.4.5, XLOG 4') :-
aggregate(mul(X), between(1, 10, X), S),
S == 3628800.
runner:case(aggregate, 3, extend_struct, 'XLOG 2.4.5, XLOG 5') :-
catch(aggregate(_, ((Y = 1; Y = 2), between(1, 10, _)), _), error(E, _), true),
E == instantiation_error.
runner:case(aggregate, 3, extend_struct, 'XLOG 2.4.5, XLOG 6') :-
catch(aggregate(sum(_), ((Y = 1; Y = 2), 1), _), error(E, _), true),
E == type_error(callable, 1).
runner:case(aggregate, 3, extend_struct, 'XLOG 2.4.5, XLOG 7') :-
aggregate(last(@<, X), member(X, [goedel, escher, bach]), S),
S == goedel.
/* aggregate(A, G, S, O): */
/* derived from aggregate/3 test cases, eager(true) returns results earlier */
runner:ref(aggregate, 4, extend_struct, 'XLOG 2.4.6').
runner:case(aggregate, 4, extend_struct, 'XLOG 2.4.6, XLOG 1a') :-
findall(Y-N, aggregate(max(X), ((Y = 2; Y = 1), (X = 1; X = Y; X = 1)), N, [eager(true)]), [R|_]),
R == 2-1.
runner:case(aggregate, 4, extend_struct, 'XLOG 2.4.6, XLOG 1b') :-
findall(Y-N, aggregate(max(X), ((Y = 2; Y = 1), (X = 1; X = Y; X = 1)), N, [eager(true)]), [_, R|_]),
R == 2-2.
runner:case(aggregate, 4, extend_struct, 'XLOG 2.4.6, XLOG 1c') :-
findall(Y-N, aggregate(max(X), ((Y = 2; Y = 1), (X = 1; X = Y; X = 1)), N, [eager(true)]), [_, _, R|_]),
R == 1-1.
runner:case(aggregate, 4, extend_struct, 'XLOG 2.4.6, XLOG 1d') :-
findall(Y-N, aggregate(max(X), ((Y = 2; Y = 1), (X = 1; X = Y; X = 1)), N, [eager(true)]), [_, _, _]).

Comments