[m-rev.] Test case for string.base_string_to_int

Ralph Becket rafe at cs.mu.OZ.AU
Thu Jul 1 16:20:04 AEST 2004


Estimated hours taken: 0.2
Branches: main

tests/general/Mmakefile:
tests/general/base_string_to_int.m:
tests/general/base_string_to_int.exp:
	Added a test case for string.base_string_to_int/3.

Index: Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/general/Mmakefile,v
retrieving revision 1.51
diff -u -r1.51 Mmakefile
--- Mmakefile	26 Jun 2004 09:23:23 -0000	1.51
+++ Mmakefile	1 Jul 2004 06:18:05 -0000
@@ -9,6 +9,7 @@
 ORDINARY_PROGS=	\
 		arithmetic \
 		array_test \
+		base_string_to_int_test \
 		commit_bug \
 		commit_bug_2 \
 		complex_failure \
Index: base_string_to_int_test.exp
===================================================================
RCS file: base_string_to_int_test.exp
diff -N base_string_to_int_test.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ base_string_to_int_test.exp	1 Jul 2004 06:17:22 -0000
@@ -0,0 +1,10 @@
+string.base_string_to_int(10, "123", 123).
+string.base_string_to_int(10, "+123", 123).
+string.base_string_to_int(10, "-123", -123).
+string.base_string_to_int(10, "", _) failed.
+string.base_string_to_int(10, "+", _) failed.
+string.base_string_to_int(10, "-", _) failed.
+string.base_string_to_int(10, "123abc", _) failed.
+string.base_string_to_int(10, "abc", _) failed.
+string.base_string_to_int(10, "+abc", _) failed.
+string.base_string_to_int(10, "-abc", _) failed.
Index: base_string_to_int_test.m
===================================================================
RCS file: base_string_to_int_test.m
diff -N base_string_to_int_test.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ base_string_to_int_test.m	1 Jul 2004 06:16:45 -0000
@@ -0,0 +1,51 @@
+%-----------------------------------------------------------------------------%
+% base_string_to_int_test.m
+% Ralph Becket <rafe at cs.mu.oz.au>
+% Thu Jul  1 16:12:57 EST 2004
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%
+%-----------------------------------------------------------------------------%
+
+:- module base_string_to_int_test.
+
+:- interface.
+
+:- import_module io.
+
+
+
+:- pred main(io :: di, io :: uo) is det.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module int, list, string.
+
+%-----------------------------------------------------------------------------%
+
+main(!IO) :-
+    test("123", !IO),
+    test("+123", !IO),
+    test("-123", !IO),
+    test("", !IO),
+    test("+", !IO),
+    test("-", !IO),
+    test("123abc", !IO),
+    test("abc", !IO),
+    test("+abc", !IO),
+    test("-abc", !IO).
+
+
+:- pred test(string::in, io::di, io::uo) is det.
+
+test(S, !IO) :-
+    io.format("string.base_string_to_int(10, \"%s\", ", [s(S)], !IO),
+    ( if   string.base_string_to_int(10, S, N)
+      then io.format("%d).\n", [i(N)], !IO)
+      else io.format("_) failed.\n", [], !IO)
+    ).
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
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