[m-rev.] diff 3/3: Add test case for map.equivalent/2

Paul Bone paul at bone.id.au
Fri Jun 28 16:26:36 AEST 2013


Add test case for map.equivalent/2

tests/general/map_equiv.m:
tests/general/map_equiv.exp:
    New test case.

tests/general/Mmakefile:
    Include new test case.
---
 tests/general/Mmakefile     |  1 +
 tests/general/map_equiv.exp |  4 ++++
 tests/general/map_equiv.m   | 52 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+)
 create mode 100644 tests/general/map_equiv.exp
 create mode 100644 tests/general/map_equiv.m

diff --git a/tests/general/Mmakefile b/tests/general/Mmakefile
index c6a8c7b..3b9d87b 100644
--- a/tests/general/Mmakefile
+++ b/tests/general/Mmakefile
@@ -37,6 +37,7 @@ ORDINARY_PROGS=	\
 		io_regression \
 		liveness \
 		liveness2 \
+		map_equiv \
 		mode_inf \
 		mode_inf_bug \
 		mode_inference_reorder \
diff --git a/tests/general/map_equiv.exp b/tests/general/map_equiv.exp
new file mode 100644
index 0000000..20c52fa
--- /dev/null
+++ b/tests/general/map_equiv.exp
@@ -0,0 +1,4 @@
+Match
+No match
+Match
+Different structure
diff --git a/tests/general/map_equiv.m b/tests/general/map_equiv.m
new file mode 100644
index 0000000..9871172
--- /dev/null
+++ b/tests/general/map_equiv.m
@@ -0,0 +1,52 @@
+%------------------------------------------------------------------------------%
+% map_equiv.m
+% Paul Bone 
+% vim: ft=mercury ff=unix ts=4 sw=4 et
+%------------------------------------------------------------------------------%
+
+:- module map_equiv.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+%------------------------------------------------------------------------------%
+%------------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module list.
+:- import_module map.
+:- import_module pair.
+
+%------------------------------------------------------------------------------%
+
+main(!IO) :-
+    map.from_assoc_list([1 - 1, 2 - 2, 3 - 3, 5 - 5, 6 - 6,
+        7 - 7, 9 - 9, 10 - 10], Map1),
+    test(Map1, Map1, !IO),    
+    set(7, 49, Map1, Map2),
+    test(Map1, Map2, !IO),
+    
+    List1 = [1 - 1, 2 - 2, 3 - 3, 4 - 4],
+    map.from_assoc_list(List1, Map3),
+    map.from_assoc_list(reverse(List1), Map4),
+    test(Map3, Map4, !IO),
+    ( Map3 = Map4 ->
+        io.write_string("Same structure\n", !IO)
+    ;
+        io.write_string("Different structure\n", !IO)
+    ).
+
+:- pred test(map(K, V)::in, map(K, V)::in, io::di, io::uo) is det.
+
+test(A, B, !IO) :-
+    ( equivalent(A, B) ->
+        io.write_string("Match\n", !IO)
+    ;
+        io.write_string("No match\n", !IO)
+    ).
+
+%------------------------------------------------------------------------------%
-- 
1.8.1.3




More information about the reviews mailing list