Prolog "string"
Admin User, erstellt 07. Apr. 2025
/**
* Prolog code for the structure string theory test cases.
*
* Source of test cases are the following standards:
* - Prolog General Core ISO/IEC 13211-1
*
* Warranty & Liability
* To the extent permitted by applicable law and unless explicitly
* otherwise agreed upon, XLOG Technologies AG makes no warranties
* regarding the provided information. XLOG Technologies AG assumes
* no liability that any problems might be solved with the information
* provided by XLOG Technologies AG.
*
* Rights & License
* All industrial property rights regarding the information - copyright
* and patent rights in particular - are the sole property of XLOG
* Technologies AG. If the company was not the originator of some
* excerpts, XLOG Technologies AG 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 AG.
*/
runner_file(structure, string, 'ISO 8.16 atoms').
/****************************************************************/
/* String Predicate */
/****************************************************************/
/* atom_length(X, Y) */
runner_pred(atom_length, 2, structure, string, 'ISO 8.16.1.4').
runner_case(atom_length, 2, structure, string, 'ISO 8.16.1.4, ISO 1') :-
atom_length('enchanted evening', N), N == 17.
runner_case(atom_length, 2, structure, string, 'ISO 8.16.1.4, ISO 3') :-
atom_length('', N), N == 0.
runner_case(atom_length, 2, structure, string, 'ISO 8.16.1.4, ISO 4') :-
\+ atom_length('scarlet', 5).
runner_case(atom_length, 2, structure, string, 'ISO 8.16.1.4, ISO 5') :-
catch(atom_length(_, 4), error(E, _), true),
E == instantiation_error.
runner_case(atom_length, 2, structure, string, 'ISO 8.16.1.4, ISO 6') :-
catch(atom_length(1.23, 4), error(E, _), true),
E == type_error(atom, 1.23).
runner_case(atom_length, 2, structure, string, 'ISO 8.16.1.4, XLOG 1') :-
\+ atom_length(atom, '4').
/* atom_concat(X, Y, Z) */
runner_pred(atom_concat, 3, structure, string, 'ISO 8.16.2.4').
runner_case(atom_concat, 3, structure, string, 'ISO 8.16.2.4, ISO 1') :-
atom_concat('hello', ' world', S),
S == 'hello world'.
runner_case(atom_concat, 3, structure, string, 'ISO 8.16.2.4, ISO 2') :-
atom_concat(T, ' world', 'small world'),
T == 'small'.
runner_case(atom_concat, 3, structure, string, 'ISO 8.16.2.4, ISO 3') :-
\+ atom_concat('hello', ' world', 'small world').
runner_case(atom_concat, 3, structure, string, 'ISO 8.16.2.4, ISO 4a') :-
atom_concat(T1, T2, 'hello'), !,
T1 == '', T2 == 'hello'.
runner_case(atom_concat, 3, structure, string, 'ISO 8.16.2.4, ISO 4b') :-
findall(T1-T2,atom_concat(T1, T2, 'hello'),[_,T1-T2|_]),
T1 == 'h', T2 == 'ello'.
runner_case(atom_concat, 3, structure, string, 'ISO 8.16.2.4, ISO 5') :-
catch(atom_concat('small', _, _), error(E, _), true),
E == instantiation_error.
/* sub_atom(X, Y, Z, T, U) */
runner_pred(sub_atom, 5, structure, string, 'ISO 8.16.3.4').
runner_case(sub_atom, 5, structure, string, 'ISO 8.16.3.4, ISO 1') :-
sub_atom(abracadabra, 0, 5, _, S),
S == abrac.
runner_case(sub_atom, 5, structure, string, 'ISO 8.16.3.4, ISO 2') :-
sub_atom(abracadabra, _, 5, 0, S),
S == dabra.
runner_case(sub_atom, 5, structure, string, 'ISO 8.16.3.4, ISO 3') :-
sub_atom(abracadabra, 3, L, 3, S),
L == 5, S == acada.
runner_case(sub_atom, 5, structure, string, 'ISO 8.16.3.4, ISO 4a') :-
sub_atom(abracadabra, B, 2, A, ab), !,
B == 0, A == 9.
runner_case(sub_atom, 5, structure, string, 'ISO 8.16.3.4, ISO 4b') :-
findall(A-B,sub_atom(abracadabra, B, 2, A, ab),[_,A-B|_]),
B == 7, A == 2.
runner_case(sub_atom, 5, structure, string, 'ISO 8.16.3.4, ISO 5') :-
sub_atom('Banana', 3, 2, _, S),
S == 'an'.
runner_case(sub_atom, 5, structure, string, 'ISO 8.16.3.4, ISO 6a') :-
sub_atom(charity, _, 3, _, S), !,
S == 'cha'.
runner_case(sub_atom, 5, structure, string, 'ISO 8.16.3.4, ISO 6b') :-
findall(S,sub_atom(charity, _, 3, _, S),[_,S|_]),
S == 'har'.
runner_case(sub_atom, 5, structure, string, 'ISO 8.16.3.4, ISO 7a') :-
sub_atom(ab, Start, Length, _, Sub_atom), !,
Start == 0, Length == 0, Sub_atom == ''.
runner_case(sub_atom, 5, structure, string, 'ISO 8.16.3.4, ISO 7b') :-
findall(Start-Length-Sub_atom, sub_atom(ab, Start, Length, _, Sub_atom),
[_,Start-Length-Sub_atom|_]),
Start == 0, Length == 1, Sub_atom == 'a'.
/* atom_codes(X, Y) */
runner_pred(atom_codes, 2, structure, string, 'ISO 8.16.5.4').
runner_case(atom_codes, 2, structure, string, 'ISO 8.16.5.4, ISO 1') :-
atom_codes('', L), L == "".
runner_case(atom_codes, 2, structure, string, 'ISO 8.16.5.4, ISO 2') :-
atom_codes([], L), L == "[]".
runner_case(atom_codes, 2, structure, string, 'ISO 8.16.5.4, ISO 3') :-
atom_codes(''', L), L == "'".
runner_case(atom_codes, 2, structure, string, 'ISO 8.16.5.4, ISO 4') :-
atom_codes(ant, L), L == "ant".
runner_case(atom_codes, 2, structure, string, 'ISO 8.16.5.4, ISO 5') :-
atom_codes(Str, "sop"), Str == sop.
runner_case(atom_codes, 2, structure, string, 'ISO 8.16.5.4, ISO 6') :-
[H]="N", atom_codes('North', [H|T]), T == "orth".
runner_case(atom_codes, 2, structure, string, 'ISO 8.16.5.4, ISO 7') :-
\+ atom_codes(soap, "sop").
runner_case(atom_codes, 2, structure, string, 'ISO 8.16.5.4, ISO 8') :-
catch(atom_codes(_,_), error(E,_), true),
E == instantiation_error.
runner_case(atom_codes, 2, structure, string, 'ISO 8.16.5.4, XLOG 1') :-
atom_codes(X, [97,16,98]), X == 'a\20\b'.
/* char_code(X, Y) */
runner_pred(char_code, 2, structure, string, 'ISO 8.16.6.4').
runner_case(char_code, 2, structure, string, 'ISO 8.16.6.4, ISO 1') :-
char_code(a,Code), Code == 97.
runner_case(char_code, 2, structure, string, 'ISO 8.16.6.4, ISO 2') :-
char_code(Str,99), Str == c.
runner_case(char_code, 2, structure, string, 'ISO 8.16.6.4, ISO 3') :-
char_code(Str,0'c), Str == c.
runner_case(char_code, 2, structure, string, 'ISO 8.16.6.4, ISO 4') :-
char_code(Str,163), Str == '£'.
runner_case(char_code, 2, structure, string, 'ISO 8.16.6.4, ISO 5') :-
\+ char_code(b,84).
runner_case(char_code, 2, structure, string, 'ISO 8.16.6.4, ISO 6') :-
catch(char_code(ab,_), error(E,_), true),
E == type_error(character, ab).
runner_case(char_code, 2, structure, string, 'ISO 8.16.6.4, ISO 7') :-
catch(char_code(_,_), error(E,_), true),
E == instantiation_error.