Files
mercury/tests/hard_coded/array_test2.m
Julien Fischer b9eca3ce6b Change the order of predicate arguments in the array module to make them
Branches: main

Change the order of predicate arguments in the array module to make them
more conducive to the use of state variable notation.

library/array.m:
	As above.

	Group clauses for functions with those of the corresponding
	predicate.

library/svarray.m:
library/hash_table.m:
library/io.m:
library/random.m:
compiler/lambda.m:
deep_profiler/array_util.m:
deep_profiler/callgraph.m:
deep_profiler/canonical.m:
deep_profiler/cliques.m:
deep_profiler/dense_bitset.m:
deep_profiler/measurements.m:
deep_profiler/profile.m:
deep_profiler/read_profile.m:
deep_profiler/startup.m:
tests/general/array_test.m:
tests/general/mode_inf.m:
tests/hard_coded/array_test2.m:
tests/hard_coded/lp.m:
tests/hard_coded/reuse_array.m:
	Conform to the above change and remove dependencies
	on the svarray module.

tests/general/set_test.m:
	Replace calls to set_bbbtree.size/2 with calls to
	set_bbbtree.count/2.

NEWS:
	Announce the above change.
2011-05-06 15:19:34 +00:00

110 lines
3.1 KiB
Mathematica

%-----------------------------------------------------------------------------%
:- module array_test2.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module array.
:- import_module bool.
:- import_module int.
:- import_module list.
%-----------------------------------------------------------------------------%
main(!IO) :-
% Exercise each of the native types for the Java backend.
test([10, 11, 12, 13, 14], !IO),
test([10.0, 11.1, 12.2, 13.3, 14.4], !IO),
test(['p', 'o', 'k', 'e', 'y'], !IO),
test([yes, no, yes, yes, no], !IO),
test(["ten", "eleven", "twelve", "thirteen", "fourteen"], !IO).
:- pred test(list(T)::in, io::di, io::uo) is det.
test(List, !IO) :-
io.write_string("----\n", !IO),
% Calls array.init, array.unsafe_insert_items.
array.from_list(List, Array),
% Calls array.bounds, array.fetch_items, array.foldr, array.elem,
% array.lookup.
array.to_list(Array, Elements),
io.write_string("size: ", !IO),
io.write_int(array.size(Array), !IO),
io.nl(!IO),
io.write_string("elements: ", !IO),
io.write(Elements, !IO),
io.nl(!IO),
( semidet_lookup(Array, -1, _) ->
io.write_string("error: out of bounds lookup suceeded\n", !IO)
;
io.write_string("good: out of bounds lookup averted\n", !IO)
),
( semidet_lookup(Array, list.length(List), _) ->
io.write_string("error: out of bounds lookup suceeded\n", !IO)
;
io.write_string("good: out of bounds lookup averted\n", !IO)
),
Elem = list.det_head(List),
array.copy(Array, ArrayB),
( semidet_set(-1, Elem, Array, _) ->
io.write_string("error: out of bounds set succeeded\n", !IO)
;
io.write_string("good: out of bounds set averted\n", !IO)
),
( semidet_set(5, Elem, ArrayB, _) ->
io.write_string("error: out of bounds set succeeded\n", !IO)
;
io.write_string("good: out of bounds set averted\n", !IO)
),
some [!A] (
array.from_list(List, !:A),
array.resize(list.length(List), Elem, !A),
io.write_string("resize without resizing: ", !IO),
io.write(!.A, !IO),
io.nl(!IO),
array.resize(1 + list.length(List)//2, Elem, !A),
io.write_string("shrink: ", !IO),
io.write(!.A, !IO),
io.nl(!IO),
array.resize(list.length(List), Elem, !A),
io.write_string("enlarge: ", !IO), % embiggen
io.write(!.A, !IO),
io.nl(!IO),
array.resize(0, Elem, !A),
io.write_string("empty: ", !IO),
io.write(!.A, !IO),
io.nl(!IO),
array.resize(0, Elem, !A),
io.write_string("still empty: ", !IO),
io.write(!.A, !IO),
io.nl(!IO),
array.resize(3, Elem, !A),
io.write_string("nonempty from empty: ", !IO),
io.write(!.A, !IO),
io.nl(!IO)
).
%-----------------------------------------------------------------------------%
% vim: ft=mercury ts=8 sts=4 sw=4 et