test(build_map_list_multiple, [true((Result1, Result2) = ([a-A, b-B, c-C, d-D], [b(identifier(A),Type,_), b(identifier(B),Type,_), b(identifier(C),Type,_),b(identifier(D),Type,_)]))]) :-
build_map_list([b(identifier(a),Type,_),b(identifier(b),Type,_),b(identifier(c),Type,_),b(identifier(d),Type,_)], Result1, Result2).
test(build_map_list_none, [true((Result1, Result2) = ([], []))]) :-
build_map_list([], Result1, Result2).
test(build_map_list_one, [true((Result1, Result2) = ([a-A], [b(identifier(A),Type,_)]))]) :-
build_map_list([b(identifier(a),Type,_)], Result1, Result2).
test(lookup_variable_present, [true(Result = A)]) :-
lookup(a, [a-A], Result).
test(lookup_variable_absent, [fail]) :-
lookup(b, [a-_], _).
test(lookup_variable_at_the_end, [true(Result = A)]) :-
lookup(a, [b-_, a-A], Result).
test(rebrand_identifier, [true(Result = A)]) :-
expressions(b(identifier(a), integer, _), b(identifier(Result), integer, _), [a-A], _).
test(let_substitution, [true((After, Modified) = ([x-_], [b(let([b(identifier(f),integer,_)],b(equal(b(identifier(f),integer,_),b(integer(5),integer,_)),pred,_),b(assign_single_id(b(identifier(x),integer,_),b(add(b(identifier(f),integer,_),b(integer(1),integer,_)),integer,_)),subst,_)),subst,_)]))]) :-
substitutions(b(let([b(identifier(f),integer,[nodeid(pos(37,1,9,13,9,14)),readonly])],b(equal(b(identifier(f),integer,[nodeid(pos(39,1,9,18,9,19)),readonly]),b(integer(5),integer,[nodeid(pos(40,1,9,22,9,23))])),pred,[nodeid(pos(38,1,9,18,9,23))]),b(assign_single_id(b(identifier(x),integer,[nodeid(pos(42,1,9,27,9,28)),loc(local,test,abstract_variables)]),b(add(b(identifier(f),integer,[nodeid(pos(44,1,9,30,9,31)),readonly]),b(integer(1),integer,[nodeid(pos(45,1,9,32,9,33))])),integer,[nodeid(pos(43,1,9,30,9,33))])),subst,[nodeid(pos(41,1,9,27,9,33))])),subst,[nodeid(pos(36,1,9,9,9,37))]), Modified, [], After).
test(simple, [true((After, Modified) = ([x-_], b(if([b(if_elsif(b(greater(b(identifier(x),integer,_),b(integer(4),integer,_)),pred,_),b(assign_single_id(b(identifier(x),integer,_),b(integer(4),integer,_)),subst,_)),subst,_)]),subst,_)))]) :-
substitutions(b(if([b(if_elsif(b(greater(b(identifier(x),integer,[nodeid(pos(49,1,10,12,10,13)),loc(local,test,abstract_variables)]),b(integer(4),integer,[nodeid(pos(50,1,10,16,10,17))])),pred,[nodeid(pos(48,1,10,12,10,17))]),b(assign_single_id(b(identifier(x),integer,[nodeid(pos(52,1,12,7,12,8)),loc(local,test,abstract_variables)]),b(integer(4),integer,[nodeid(pos(53,1,12,12,12,13))])),subst,[nodeid(pos(51,1,12,7,12,13))])),subst,[nodeid(pos(47,1,10,9,13,6))])]),subst,[nodeid(pos(47,1,10,9,13,6))]),
Modified,
[],
After).
test(if_iflse, [nondet, true((After, Modified) = ([x-_], b(if([b(if_elsif(b(less(b(identifier(x),integer,_),b(integer(5),integer,_)),pred,_),b(assign_single_id(b(identifier(x),integer,_),b(integer(4),integer,_)),subst,_)),subst,_),b(if_elsif(b(greater(b(identifier(x),integer,_),b(integer(5),integer,_)),pred,_),b(assign_single_id(b(identifier(x),integer,_),b(integer(5),integer,_)),subst,_)),subst,_),b(if_elsif(b(truth,pred,_),b(assign_single_id(b(identifier(x),integer,_),b(integer(6),integer,_)),subst,_)),subst,_)]),subst,_)))]) :-
substitutions(b(if([b(if_elsif(b(less(b(identifier(x),integer,[nodeid(pos(68,1,20,13,20,14)),loc(local,test,abstract_variables)]),b(integer(5),integer,[nodeid(pos(69,1,20,17,20,18))])),pred,[nodeid(pos(67,1,20,13,20,18))]),b(assign_single_id(b(identifier(x),integer,[nodeid(pos(71,1,22,7,22,8)),loc(local,test,abstract_variables)]),b(integer(4),integer,[nodeid(pos(72,1,22,12,22,13))])),subst,[nodeid(pos(70,1,22,7,22,13))])),subst,[nodeid(pos(66,1,20,10,28,6))]),b(if_elsif(b(greater(b(identifier(x),integer,[nodeid(pos(75,1,23,9,23,10)),loc(local,test,abstract_variables)]),b(integer(5),integer,[nodeid(pos(76,1,23,13,23,14))])),pred,[nodeid(pos(74,1,23,9,23,14))]),b(assign_single_id(b(identifier(x),integer,[nodeid(pos(78,1,25,7,25,8)),loc(local,test,abstract_variables)]),b(integer(5),integer,[nodeid(pos(79,1,25,12,25,13))])),subst,[nodeid(pos(77,1,25,7,25,13))])),subst,[nodeid(pos(73,1,23,3,25,13))]),b(if_elsif(b(truth,pred,[nodeid(none)]),b(assign_single_id(b(identifier(x),integer,[nodeid(pos(81,1,27,7,27,8)),loc(local,test,abstract_variables)]),b(integer(6),integer,[nodeid(pos(82,1,27,12,27,13))])),subst,[nodeid(pos(80,1,27,7,27,13))])),subst,[nodeid(none)])]),subst,[nodeid(pos(66,1,20,10,28,6))]),
Modified,
[],
After).
test(if_else, [nondet, true((After, Modified) = ([x-_], b(if([b(if_elsif(b(greater(b(identifier(x),integer,_),b(integer(4),integer,_)),pred,_),b(assign_single_id(b(identifier(x),integer,_),b(integer(4),integer,_)),subst,_)),subst,_),b(if_elsif(b(truth,pred,_),b(assign_single_id(b(identifier(x),integer,_),b(integer(3),integer,_)),subst,_)),subst,_)]),subst,_)))]) :-
substitutions(b(if([b(if_elsif(b(greater(b(identifier(x),integer,[nodeid(pos(57,1,14,13,14,14)),loc(local,test,abstract_variables)]),b(integer(4),integer,[nodeid(pos(58,1,14,17,14,18))])),pred,[nodeid(pos(56,1,14,13,14,18))]),b(assign_single_id(b(identifier(x),integer,[nodeid(pos(60,1,16,7,16,8)),loc(local,test,abstract_variables)]),b(integer(4),integer,[nodeid(pos(61,1,16,12,16,13))])),subst,[nodeid(pos(59,1,16,7,16,13))])),subst,[nodeid(pos(55,1,14,10,19,6))]),b(if_elsif(b(truth,pred,[nodeid(none)]),b(assign_single_id(b(identifier(x),integer,[nodeid(pos(63,1,18,7,18,8)),loc(local,test,abstract_variables)]),b(integer(3),integer,[nodeid(pos(64,1,18,11,18,12))])),subst,[nodeid(pos(62,1,18,7,18,12))])),subst,[nodeid(none)])]),subst,[nodeid(pos(55,1,14,10,19,6))]),
Modified,
[],
After).
test(op_call_expr , [true((After, Modified) = ([], b(operation_call_in_expr(b(identifier(op('ToCal')),subst,_),[b(integer(5),integer,_)]),integer,[contains_wd_condition,nodeid(pos(30,1,9,17,9,25)),modifies([]),reads(['test2.z']),non_det_modifies([])])))]) :-
expressions(b(operation_call_in_expr(b(identifier(op('ToCal')),subst,[loc(seen,test2,promoted),inquiry,usesee(test2,op('ToCal'),seen),modifies([]),reads([z]),non_det_modifies([])]),[b(integer(5),integer,[nodeid(pos(32,1,9,23,9,24))])]),integer,[contains_wd_condition,nodeid(pos(30,1,9,17,9,25)),modifies([]),reads(['test2.z']),non_det_modifies([])]),
Modified,
[],
After).
test(op_call, [true(After=[])]) :-
substitutions(b(operation_call(b(identifier(op('ToCal')),_,_), _, _), _, _), b(operation_call(b(identifier(op(_)),_,_), _,_)),
[],
After).
test(prepared_operation, [true((FreeVars, FoundVars, PreparedOperation) = ([X,Y], ['floors', 'inccc' ], b(operation(X,[],[],b(precondition(b(less(b(identifier(Y),integer,[nodeid(pos(20,1,11,14,11,20)),loc(local,machineWithOneOperation,abstract_variables)]),b(integer(2),integer,[nodeid(pos(21,1,11,21,11,22))])),pred,[nodeid(pos(19,1,11,14,11,22))]),b(assign_single_id(b(identifier(Y),integer,[nodeid(pos(23,1,11,28,11,34)),loc(local,machineWithOneOperation,abstract_variables)]),b(add(b(identifier(floors),integer,[nodeid(pos(25,1,11,38,11,44)),loc(local,machineWithOneOperation,abstract_variables)]),b(integer(1),integer,[nodeid(pos(26,1,11,47,11,48))])),integer,[nodeid(pos(24,1,11,38,11,48))])),subst,[nodeid(pos(22,1,11,28,11,48))])),subst,[nodeid(pos(18,1,11,10,11,52))])))))]) :-
prepare_operation(
b(operation(inccc,[],[],b(precondition(b(less(b(identifier(floors),integer,[nodeid(pos(20,1,11,14,11,20)),loc(local,machineWithOneOperation,abstract_variables)]),b(integer(2),integer,[nodeid(pos(21,1,11,21,11,22))])),pred,[nodeid(pos(19,1,11,14,11,22))]),b(assign_single_id(b(identifier(floors),integer,[nodeid(pos(23,1,11,28,11,34)),loc(local,machineWithOneOperation,abstract_variables)]),b(add(b(identifier(floors),integer,[nodeid(pos(25,1,11,38,11,44)),loc(local,machineWithOneOperation,abstract_variables)]),b(integer(1),integer,[nodeid(pos(26,1,11,47,11,48))])),integer,[nodeid(pos(24,1,11,38,11,48))])),subst,[nodeid(pos(22,1,11,28,11,48))])),subst,[nodeid(pos(18,1,11,10,11,52))]))),
PreparedOperation,
FoundVars,
FreeVars,
_Errors).
test(prepared_operation_initialisation, [true((FreeVars, FoundVars, PreparedOperation) = ([_], ['xx'], b(initialisation(b(assign_single_id(b(identifier(_),integer,_),b(integer(1),integer,_)),subst,_)))))]) :-
prepare_operation(b(initialisation(b(assign_single_id(b(identifier(xx),integer,[nodeid(pos(12,1,7,20,7,22)),loc(local,'IfAndPredicates',abstract_variables),not_initialised]),b(integer(1),integer,[nodeid(pos(13,1,7,26,7,27))])),subst,[nodeid(pos(11,1,7,20,7,27))]))),
PreparedOperation,
FoundVars,
FreeVars,
_Errors).