%%% KL1-B Test for B_Function (Exception) %%%
% B_Min %%%%%%%%%%%%%%%%% abcdefghijkl
% B_Max %%%%%%%%%%%%%%%%% abcdefghijkl
% B_Abs %%%%%%%%%%%%%%%%% abcdefg

:- module b_func_e.
:- public go/0
,do_min/3,do_max/3,do_abs/2.

go:- put_console(ascii#"%%% KL1-B Test for B_Function (Exception) %%%"), put_console(key#lf) | min.

min:- put_console(ascii#"% B_Min %%%%%%%%%%%%%%%%% ") | min00.

min00:- true | execute_in_shoen(do_min,{16#"7FFFFFFF",16#"7FFFFFFF",Z},R), min00(R,Z).
min00(success,_):- put_console(c#"a") | min01.
otherwise.
min00(_,_):- put_console(c#"*") | min01.

min01:- true | execute_in_shoen(do_min,{16#"7FFFFFFF",16#"80000000",Z},R), min01(R,Z).
min01(success,_):- put_console(c#"b") | min02.
otherwise.
min01(_,_):- put_console(c#"*") | min02.

min02:- true | execute_in_shoen(do_min,{0,atom,Z},R), min02(R,Z).
min02(illegal_input,_):- put_console(c#"c") | min03.
otherwise.
min02(_,_):- put_console(c#"*") | min03.

min03:- true | execute_in_shoen(do_min,{0,12.34,Z},R), min03(R,Z).
min03(illegal_input,_):- put_console(c#"d") | min04.
otherwise.
min03(_,_):- put_console(c#"*") | min04.

min04:- true | execute_in_shoen(do_min,{0,[list],Z},R), min04(R,Z).
min04(illegal_input,_):- put_console(c#"e") | min05.
otherwise.
min04(_,_):- put_console(c#"*") | min05.

min05:- true | execute_in_shoen(do_min,{0,{0,1},Z},R), min05(R,Z).
min05(illegal_input,_):- put_console(c#"f") | min06.
otherwise.
min05(_,_):- put_console(c#"*") | min06.

min06:- true | execute_in_shoen(do_min,{0,ascii#"String",Z},R), min06(R,Z).
min06(illegal_input,_):- put_console(c#"g") | min07.
otherwise.
min06(_,_):- put_console(c#"*") | min07.

min07:- true | execute_in_shoen(do_min,{atom,0,Z},R), min07(R,Z).
min07(illegal_input,_):- put_console(c#"h") | min08.
otherwise.
min07(_,_):- put_console(c#"*") | min08.

min08:- true | execute_in_shoen(do_min,{12.34,0,Z},R), min08(R,Z).
min08(illegal_input,_):- put_console(c#"i") | min09.
otherwise.
min08(_,_):- put_console(c#"*") | min09.

min09:- true | execute_in_shoen(do_min,{[list],0,Z},R), min09(R,Z).
min09(illegal_input,_):- put_console(c#"j") | min10.
otherwise.
min09(_,_):- put_console(c#"*") | min10.

min10:- true | execute_in_shoen(do_min,{{0,1},0,Z},R), min10(R,Z).
min10(illegal_input,_):- put_console(c#"k") | min11.
otherwise.
min10(_,_):- put_console(c#"*") | min11.

min11:- true | execute_in_shoen(do_min,{ascii#"String",0,Z},R), min11(R,Z).
min11(illegal_input,_):- put_console(c#"l") | min12.
otherwise.
min11(_,_):- put_console(c#"*") | min12.

min12:- put_console(key#lf) | max.

max:- put_console(ascii#"% B_Max %%%%%%%%%%%%%%%%% ") | max00.

max00:- true | execute_in_shoen(do_max,{16#"7FFFFFFF",16#"7FFFFFFF",Z},R), max00(R,Z).
max00(success,_):- put_console(c#"a") | max01.
otherwise.
max00(_,_):- put_console(c#"*") | max01.

max01:- true | execute_in_shoen(do_max,{16#"7FFFFFFF",16#"80000000",Z},R), max01(R,Z).
max01(success,_):- put_console(c#"b") | max02.
otherwise.
max01(_,_):- put_console(c#"*") | max02.

max02:- true | execute_in_shoen(do_max,{0,atom,Z},R), max02(R,Z).
max02(illegal_input,_):- put_console(c#"c") | max03.
otherwise.
max02(_,_):- put_console(c#"*") | max03.

max03:- true | execute_in_shoen(do_max,{0,12.34,Z},R), max03(R,Z).
max03(illegal_input,_):- put_console(c#"d") | max04.
otherwise.
max03(_,_):- put_console(c#"*") | max04.

max04:- true | execute_in_shoen(do_max,{0,[list],Z},R), max04(R,Z).
max04(illegal_input,_):- put_console(c#"e") | max05.
otherwise.
max04(_,_):- put_console(c#"*") | max05.

max05:- true | execute_in_shoen(do_max,{0,{0,1},Z},R), max05(R,Z).
max05(illegal_input,_):- put_console(c#"f") | max06.
otherwise.
max05(_,_):- put_console(c#"*") | max06.

max06:- true | execute_in_shoen(do_max,{0,ascii#"String",Z},R), max06(R,Z).
max06(illegal_input,_):- put_console(c#"g") | max07.
otherwise.
max06(_,_):- put_console(c#"*") | max07.

max07:- true | execute_in_shoen(do_max,{atom,0,Z},R), max07(R,Z).
max07(illegal_input,_):- put_console(c#"h") | max08.
otherwise.
max07(_,_):- put_console(c#"*") | max08.

max08:- true | execute_in_shoen(do_max,{12.34,0,Z},R), max08(R,Z).
max08(illegal_input,_):- put_console(c#"i") | max09.
otherwise.
max08(_,_):- put_console(c#"*") | max09.

max09:- true | execute_in_shoen(do_max,{[list],0,Z},R), max09(R,Z).
max09(illegal_input,_):- put_console(c#"j") | max10.
otherwise.
max09(_,_):- put_console(c#"*") | max10.

max10:- true | execute_in_shoen(do_max,{{0,1},0,Z},R), max10(R,Z).
max10(illegal_input,_):- put_console(c#"k") | max11.
otherwise.
max10(_,_):- put_console(c#"*") | max11.

max11:- true | execute_in_shoen(do_max,{ascii#"String",0,Z},R), max11(R,Z).
max11(illegal_input,_):- put_console(c#"l") | max12.
otherwise.
max11(_,_):- put_console(c#"*") | max12.

max12:- put_console(key#lf) | abs.

abs:- put_console(ascii#"% B_Abs %%%%%%%%%%%%%%%%% ") | abs00.

abs00:- true | execute_in_shoen(do_abs,{16#"7FFFFFFF",Z},R), abs00(R,Z).
abs00(success,_):- put_console(c#"a") | abs01.
otherwise.
abs00(_,_):- put_console(c#"*") | abs01.

abs01:- true | execute_in_shoen(do_abs,{16#"80000000",Z},R), abs01(R,Z).
abs01(integer_overflow,_):- put_console(c#"b") | abs02.
otherwise.
abs01(_,_):- put_console(c#"*") | abs02.

abs02:- true | execute_in_shoen(do_abs,{atom,Z},R), abs02(R,Z).
abs02(illegal_input,_):- put_console(c#"c") | abs03.
otherwise.
abs02(_,_):- put_console(c#"*") | abs03.

abs03:- true | execute_in_shoen(do_abs,{12.34,Z},R), abs03(R,Z).
abs03(illegal_input,_):- put_console(c#"d") | abs04.
otherwise.
abs03(_,_):- put_console(c#"*") | abs04.

abs04:- true | execute_in_shoen(do_abs,{[list],Z},R), abs04(R,Z).
abs04(illegal_input,_):- put_console(c#"e") | abs05.
otherwise.
abs04(_,_):- put_console(c#"*") | abs05.

abs05:- true | execute_in_shoen(do_abs,{{0,1},Z},R), abs05(R,Z).
abs05(illegal_input,_):- put_console(c#"f") | abs06.
otherwise.
abs05(_,_):- put_console(c#"*") | abs06.

abs06:- true | execute_in_shoen(do_abs,{ascii#"String",Z},R), abs06(R,Z).
abs06(illegal_input,_):- put_console(c#"g") | abs07.
otherwise.
abs06(_,_):- put_console(c#"*") | abs07.

abs07:- put_console(key#lf) | done.

done:- true | true.

execute_in_shoen(P,A,R):- vector(A,L) |
	'Sho-en':execute({b_func_e,P,L},A, 0,0, -1, C0,R0),
	C0 = [add_resource(100),start|C],
	shoen_wait(R0,R,C).

shoen_wait([resource_added,started|R0],R,C):- true | shoen_check(R0,R,C).

shoen_check([terminated|_],R,C):- true |
	R=success, C=[].
shoen_check([exception(0,_,NewCode,NewArgv)|_],R,C):- true |
	NewCode=[], R=illegal_input, C=[abort].
shoen_check([exception(1,_,NewCode,NewArgv)|_],R,C):- true |
	NewCode=[], R=range_overflow, C=[abort].
shoen_check([exception(3,_,NewCode,NewArgv)|_],R,C):- true |
	NewCode=[], R=integer_overflow, C=[abort].

do_min(X,Y,Z):- true | Z:=min(X,Y).
do_max(X,Y,Z):- true | Z:=max(X,Y).
do_abs(X,Z):- true | Z:=abs(X).
