[m-rev.] Bugfix for string__to_float

Ralph Becket rafe at cs.mu.OZ.AU
Tue Feb 12 12:38:54 AEDT 2002


Fergus Henderson, Monday, 11 February 2002:
> On 11-Feb-2002, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> > library/string.m:
> > 	Fixed a bug in string__to_float/2 which did not fail when it
> > 	should have (i.e. it now also fails if the string argument
> > 	has preceding whitespace or any trailing characters.)
> 
> The code looks fine, but how about a test case for the test suite?

Index: string_to_float.m
===================================================================
RCS file: string_to_float.m
diff -N string_to_float.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ string_to_float.m	12 Feb 2002 01:34:54 -0000
@@ -0,0 +1,49 @@
+%------------------------------------------------------------------------------%
+% string_to_float.m
+% Ralph Becket <rafe at cs.mu.oz.au>
+% Mon Feb 11 17:52:44 EST 2002
+% vim: ft=mercury ff=unix ts=4 sw=4 et tw=0 wm=0
+%
+%------------------------------------------------------------------------------%
+
+:- module string_to_float.
+
+:- interface.
+
+:- import_module io.
+
+
+
+:- pred main(io::di, io::uo) is det.
+
+%------------------------------------------------------------------------------%
+%------------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module list, string, float.
+
+%------------------------------------------------------------------------------%
+
+main -->
+    test("1.23"),
+    test("x1.23"),
+    test("1.23x"),
+    test("x1.23x"),
+    test(" 1.23"),
+    test("1.23 "),
+    test(" 1.23 ").
+
+:- pred test(string::in, io::di, io::uo) is det.
+
+test(S) -->
+    io__format("string__to_float(\"%s\") %s\n",
+        [ s(S),
+          s( if   string__to_float(S, X)
+             then string__format("= %f", [f(X)])
+             else "FAILS"
+          )
+        ]).
+
+%------------------------------------------------------------------------------%
+%------------------------------------------------------------------------------%

Index: string_to_float.exp
===================================================================
RCS file: string_to_float.exp
diff -N string_to_float.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ string_to_float.exp	12 Feb 2002 01:35:24 -0000
@@ -0,0 +1,7 @@
+string__to_float("1.23") = 1.230000
+string__to_float("x1.23") FAILS
+string__to_float("1.23x") FAILS
+string__to_float("x1.23x") FAILS
+string__to_float(" 1.23") FAILS
+string__to_float("1.23 ") FAILS
+string__to_float(" 1.23 ") FAILS

Index: Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/general/Mmakefile,v
retrieving revision 1.36
diff -u -r1.36 Mmakefile
--- Mmakefile	22 Jan 2002 14:21:52 -0000	1.36
+++ Mmakefile	12 Feb 2002 01:35:39 -0000
@@ -67,6 +67,7 @@
 		string_format_test_3 \
 		string_test \
 		string_test_2 \
+		string_to_float \
 		univ \
 		unreachable \
 		unsafe_uniqueness
--------------------------------------------------------------------------
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