[m-rev.] version_array bugfix and test case

Ralph Becket rafe at cs.mu.OZ.AU
Fri Oct 8 17:02:08 AEST 2004


Estimated hours taken: 2
Branches: main

Added a test case for version_array.m and fixed a few bugs.

library/version_array.m:
	Bug in version_array.rewind fixed.

tests/hard_coded/Mmakefile:
tests/hard_coded/version_array_test.m:
tests/hard_coded/version_array_test.exp:
	Test case added.

Index: library/version_array.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/version_array.m,v
retrieving revision 1.3
diff -u -r1.3 version_array.m
--- library/version_array.m	27 Sep 2004 16:31:20 -0000	1.3
+++ library/version_array.m	8 Oct 2004 06:16:39 -0000
@@ -460,9 +460,9 @@
     ML_va_resize(struct ML_va *VA0, MR_Integer N, MR_Word X) {
 
         MR_Integer i;
-        MR_Integer size_VA0 = ML_va_size(VA0);
-        MR_Integer min      = (N <= size_VA0 ? N : size_VA0);
-        struct ML_va *VA       = MR_GC_NEW(struct ML_va);
+        MR_Integer size_VA0  = ML_va_size(VA0);
+        MR_Integer min       = (N <= size_VA0 ? N : size_VA0);
+        struct ML_va *VA     = MR_GC_NEW(struct ML_va);
 
         VA->index            = -1;
         VA->value            = (MR_Word) NULL;
@@ -561,11 +561,10 @@
             return VA;
         }
 
-        I         = VA->index;
-        X         = VA->value;
-        VA        = ML_va_rewind(VA->rest.next);
-        VA->index = I;
-        VA->value = X;
+        I  = VA->index;
+        X  = VA->value;
+        VA = ML_va_rewind(VA->rest.next);
+        VA->rest.array->elements[I] = X;
 
         return VA;
     }
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.237
diff -u -r1.237 Mmakefile
--- tests/hard_coded/Mmakefile	5 Oct 2004 05:49:01 -0000	1.237
+++ tests/hard_coded/Mmakefile	8 Oct 2004 06:58:19 -0000
@@ -182,6 +182,7 @@
 	unused_float_box_test \
 	user_compare \
 	user_defined_equality2 \
+	version_array_test \
 	write \
 	write_reg1 \
 	write_reg2
Index: tests/hard_coded/version_array_test.exp
===================================================================
RCS file: tests/hard_coded/version_array_test.exp
diff -N tests/hard_coded/version_array_test.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/version_array_test.exp	8 Oct 2004 06:58:00 -0000
@@ -0,0 +1,10 @@
+ (size 0)
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9 (size 10)
+9, 8, 7, 6, 5, 4, 3, 2, 1, 0 (size 10)
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9 (size 10)
+7, 7, 7, 7, 7, 7, 7 (size 7)
+ (sum 49)
+7, 7, 7, 7 (size 4)
+7, 7, 7, 7, 9, 9, 9, 9, 9 (size 9)
+ (sum 73)
+7, 7, 7, 7 (size 4)
Index: tests/hard_coded/version_array_test.m
===================================================================
RCS file: tests/hard_coded/version_array_test.m
diff -N tests/hard_coded/version_array_test.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/version_array_test.m	8 Oct 2004 06:58:06 -0000
@@ -0,0 +1,60 @@
+%-----------------------------------------------------------------------------%
+% version_array_test.m
+% Ralph Becket <rafe at cs.mu.oz.au>
+% Fri Oct  8 15:00:25 EST 2004
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%
+%-----------------------------------------------------------------------------%
+
+:- module version_array_test.
+
+:- interface.
+
+:- import_module io.
+
+
+
+:- pred main(io :: di, io :: uo) is det.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module int, list, string, version_array.
+
+%-----------------------------------------------------------------------------%
+
+main(!IO) :-
+    A0 = version_array.empty,
+    A1 = version_array(0`..`9),
+    A2 = int.fold_up(func(I, A) = ( A ^ elem(I) := 9 - I ), 0, 9, A1),
+    io.write_list(to_list(A0), ", ", io.write_int, !IO),
+    io.format(" (size %d)\n", [i(size(A0))], !IO),
+    io.write_list(to_list(A1), ", ", io.write_int, !IO),
+    io.format(" (size %d)\n", [i(size(A1))], !IO),
+    io.write_list(to_list(A2), ", ", io.write_int, !IO),
+    io.format(" (size %d)\n", [i(size(A2))], !IO),
+    A3 = unsafe_rewind(A1),
+    io.write_list(to_list(A3), ", ", io.write_int, !IO),
+    io.format(" (size %d)\n", [i(size(A3))], !IO),
+    A4 = version_array.init(7, 7),
+    io.write_list(to_list(A4), ", ", io.write_int, !IO),
+    io.format(" (size %d)\n", [i(size(A4))], !IO),
+    S4 = foldl(func(X, A) = X + A, A4, 0),
+    io.format(" (sum %d)\n", [i(S4)], !IO),
+    A5 = resize(A4, 4, 4),
+    io.write_list(to_list(A5), ", ", io.write_int, !IO),
+    io.format(" (size %d)\n", [i(size(A5))], !IO),
+    A6 = resize(A5, 9, 9),
+    io.write_list(to_list(A6), ", ", io.write_int, !IO),
+    io.format(" (size %d)\n", [i(size(A6))], !IO),
+    S6 = foldl(func(X, A) = X + A, A6, 0),
+    io.format(" (sum %d)\n", [i(S6)], !IO),
+    A7 = copy(A5),
+    io.write_list(to_list(A7), ", ", io.write_int, !IO),
+    io.format(" (size %d)\n", [i(size(A7))], !IO),
+    true.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list