[m-rev.] for review: another string__format test reorg

Peter Ross pro at missioncriticalit.com
Fri Nov 22 00:54:08 AEDT 2002


Hi,

For fjh to review.

===================================================================


Estimated hours taken: 2
Branches: main

Reorganize the string__format tests so that we only need one expected
output file for each test.

general/string_format_special_floats.exp:
general/string_format_special_floats.m:
	Test that NaNs and infinites are handled correctly, by
	internally checking in the test case that we generate a valid
	string rather than by checking the expected output.

general/Mmakefile:
	Add the new test.
	
general/string_format/string_format_f.exp:
general/string_format/string_format_f.m:
	Remove the test cases of infinite_floats.
	Remove the testing of +/-float__max as each C version of
	sprintf seems to print the number out to a different
	precision.

general/string_format/string_format_e.exp:
general/string_format/string_format_e.m:
general/string_format/string_format_g.exp:
general/string_format/string_format_g.m:
	Remove the test cases of infinite_floats.

Index: general/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/general/Mmakefile,v
retrieving revision 1.47
diff -u -r1.47 Mmakefile
--- general/Mmakefile	21 Nov 2002 08:00:58 -0000	1.47
+++ general/Mmakefile	21 Nov 2002 13:45:26 -0000
@@ -56,6 +56,7 @@
 		state_vars_typeclasses \
 		string_foldl_substring \
 		string_foldr_substring \
+		string_format_special_floats \
 		string_format_test \
 		string_format_test_2 \
 		string_format_test_3 \
Index: general/string_format_special_floats.exp
===================================================================
RCS file: general/string_format_special_floats.exp
diff -N general/string_format_special_floats.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ general/string_format_special_floats.exp	21 Nov 2002 13:45:26 -0000
@@ -0,0 +1,11 @@
+Infinity:
+                  %e: success
+                  %e: success
+                  %f: success
+                  %f: success
+                  %g: success
+                  %g: success
+Not a number:
+                  %e: success
+                  %f: success
+                  %g: success
Index: general/string_format_special_floats.m
===================================================================
RCS file: general/string_format_special_floats.m
diff -N general/string_format_special_floats.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ general/string_format_special_floats.m	21 Nov 2002 13:45:26 -0000
@@ -0,0 +1,64 @@
+%------------------------------------------------------------------------------%
+%------------------------------------------------------------------------------%
+
+:- module string_format_special_floats.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+%------------------------------------------------------------------------------%
+%------------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module float, list, string.
+
+%------------------------------------------------------------------------------%
+
+main -->
+	{ Inf = (max+max) },
+	io__write_string("Infinity:\n"),
+	list__foldl(test_floats(is_infinity, [Inf, -Inf]), ["%e", "%f", "%g"]),
+	io__write_string("Not a number:\n"),
+	list__foldl(test_floats(is_nan, [0.0 * Inf]), ["%e", "%f", "%g"]).
+
+:- pred test_floats(pred(string)::in(pred(in) is semidet), list(float)::in,
+		string::in, io::di, io::uo) is det.
+
+test_floats(IsValid, Floats, FormatString) -->
+	list__foldl(test_float(FormatString, IsValid), Floats).
+
+
+:- pred test_float(string::in, pred(string)::in(pred(in) is semidet),
+		float::in, io::di, io::uo) is det.
+
+test_float(FormatString, IsValid, Float) -->
+	{ FloatString = string__format(FormatString, [f(Float)]) },
+	io__format("%20s: ", [s(FormatString)]),
+	( { IsValid(FloatString) }->
+		io__write_string("success\n")
+	;
+		io__write_string("failure '" ++ FloatString ++ "'\n")
+	).
+
+:- pred is_infinity(string::in) is semidet.
+
+is_infinity(String) :-
+	LowerCaseString = string__to_lower(String),
+	( LowerCaseString = "infinity"
+	; LowerCaseString = "inf"
+	; LowerCaseString = "-infinity"
+	; LowerCaseString = "-inf"
+	).
+
+:- pred is_nan(string::in) is semidet.
+
+is_nan(String) :-
+	LowerCaseString = string__to_lower(String),
+	LowerCaseString = "nan".
+
+%------------------------------------------------------------------------------%
+%------------------------------------------------------------------------------%
Index: general/string_format/string_format_e.exp
===================================================================
RCS file: /home/mercury1/repository/tests/general/string_format/string_format_e.exp,v
retrieving revision 1.2
diff -u -r1.2 string_format_e.exp
--- general/string_format/string_format_e.exp	19 Nov 2002 11:00:49 -0000	1.2
+++ general/string_format/string_format_e.exp	21 Nov 2002 13:45:30 -0000
@@ -6,7 +6,6 @@
         %E:'-1.797693E+308'
         %E:'-2.225074E-308'
         %E:'-5.555556E+01'
-        %E:'-INF'
         %E:'0.000000E+00'
         %E:'1.000000E+00'
         %E:'1.000000E+01'
@@ -16,7 +15,6 @@
         %E:'1.797693E+308'
         %E:'2.225074E-308'
         %E:'5.555556E+01'
-        %E:'INF'
         %e:'-1.000000e+00'
         %e:'-1.000000e+01'
         %e:'-1.000000e+02'
@@ -25,7 +23,6 @@
         %e:'-1.797693e+308'
         %e:'-2.225074e-308'
         %e:'-5.555556e+01'
-        %e:'-inf'
         %e:'0.000000e+00'
         %e:'1.000000e+00'
         %e:'1.000000e+01'
@@ -35,7 +32,6 @@
         %e:'1.797693e+308'
         %e:'2.225074e-308'
         %e:'5.555556e+01'
-        %e:'inf'
        % E:' 0.000000E+00'
        % E:' 1.000000E+00'
        % E:' 1.000000E+01'

[snip]

Index: general/string_format/string_format_e.m
===================================================================
RCS file: /home/mercury1/repository/tests/general/string_format/string_format_e.m,v
retrieving revision 1.1
diff -u -r1.1 string_format_e.m
--- general/string_format/string_format_e.m	19 Nov 2002 09:42:30 -0000	1.1
+++ general/string_format/string_format_e.m	21 Nov 2002 13:45:30 -0000
@@ -31,14 +31,12 @@
 	list__foldl(output_list(rounding_floats), FormatStrs_e),
 	list__foldl(output_list(extreme_floats), FormatStrs_e),
 	list__foldl(output_list(denormal_floats), FormatStrs_e),
-	list__foldl(output_list(infinite_floats), FormatStrs_e),
 
 	list__foldl(output_list(standard_floats), FormatStrs_E),
 	list__foldl(output_list(trailing_zero_floats), FormatStrs_E),
 	list__foldl(output_list(rounding_floats), FormatStrs_E),
 	list__foldl(output_list(extreme_floats), FormatStrs_E),
 	list__foldl(output_list(denormal_floats), FormatStrs_E),
-	list__foldl(output_list(infinite_floats), FormatStrs_E),
 	[].
 
 %------------------------------------------------------------------------------%
Index: general/string_format/string_format_f.exp
===================================================================
RCS file: /home/mercury1/repository/tests/general/string_format/string_format_f.exp,v
retrieving revision 1.2
diff -u -r1.2 string_format_f.exp
--- general/string_format/string_format_f.exp	19 Nov 2002 11:00:50 -0000	1.2
+++ general/string_format/string_format_f.exp	21 Nov 2002 13:45:31 -0000
@@ -4,9 +4,7 @@
         %f:'-10.000000'
         %f:'-100.000000'
         %f:'-100000000000000000.000000'
-        %f:'-179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000'
         %f:'-55.555556'
-        %f:'-inf'
         %f:'0.000000'
         %f:'0.000000'
         %f:'0.000000'
@@ -14,9 +12,7 @@
         %f:'10.000000'
         %f:'100.000000'
         %f:'100000000000000000.000000'
-        %f:'179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000'
         %f:'55.555556'
-        %f:'inf'
        % f:' 0.000000'
        % f:' 0.000000'
        % f:' 0.000000'
@@ -24,27 +20,21 @@
        % f:' 10.000000'
        % f:' 100.000000'
        % f:' 100000000000000000.000000'
-       % f:' 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000'
        % f:' 55.555556'
-       % f:' inf'
        % f:'-0.000000'
        % f:'-0.000000'
        % f:'-1.000000'
        % f:'-10.000000'
        % f:'-100.000000'
        % f:'-100000000000000000.000000'
-       % f:'-179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000'
        % f:'-55.555556'
-       % f:'-inf'
        %#f:'-0.000000'
        %#f:'-0.000000'
        %#f:'-1.000000'
        %#f:'-10.000000'
        %#f:'-100.000000'
        %#f:'-100000000000000000.000000'
-       %#f:'-179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000'
        %#f:'-55.555556'
-       %#f:'-inf'
        %#f:'0.000000'
        %#f:'0.000000'
        %#f:'0.000000'
@@ -52,9 +42,7 @@
        %#f:'10.000000'
        %#f:'100.000000'
        %#f:'100000000000000000.000000'
-       %#f:'179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000'
        %#f:'55.555556'
-       %#f:'inf'
        %+f:'+0.000000'
        %+f:'+0.000000'
        %+f:'+0.000000'

[snip]

Index: general/string_format/string_format_f.m
===================================================================
RCS file: /home/mercury1/repository/tests/general/string_format/string_format_f.m,v
retrieving revision 1.2
diff -u -r1.2 string_format_f.m
--- general/string_format/string_format_f.m	20 Nov 2002 11:48:38 -0000	1.2
+++ general/string_format/string_format_f.m	21 Nov 2002 13:45:31 -0000
@@ -25,12 +25,17 @@
 main -->
 	{ FormatStrs_f = format_strings("f") },
 
+		% We don't test printing max because each different
+		% implementation of printf prints a different amount of
+		% significan digits leading to explosion in the number
+		% of expected output files.
+	{ ExtremeFloats = [f(min), f(-min)] },
+
 	list__foldl(output_list(standard_floats), FormatStrs_f),
 	list__foldl(output_list(trailing_zero_floats), FormatStrs_f),
 	list__foldl(output_list(rounding_floats), FormatStrs_f),
-	list__foldl(output_list(extreme_floats), FormatStrs_f),
+	list__foldl(output_list(ExtremeFloats), FormatStrs_f),
 	list__foldl(output_list(denormal_floats), FormatStrs_f),
-	list__foldl(output_list(infinite_floats), FormatStrs_f),
 	[].
 
 %------------------------------------------------------------------------------%
Index: general/string_format/string_format_g.exp
===================================================================
RCS file: /home/mercury1/repository/tests/general/string_format/string_format_g.exp,v
retrieving revision 1.2
diff -u -r1.2 string_format_g.exp
--- general/string_format/string_format_g.exp	19 Nov 2002 11:00:51 -0000	1.2
+++ general/string_format/string_format_g.exp	21 Nov 2002 13:45:35 -0000
@@ -6,7 +6,6 @@
         %G:'-1E+17'
         %G:'-2.22507E-308'
         %G:'-55.5556'
-        %G:'-INF'
         %G:'0'
         %G:'1'
         %G:'1.11254E-308'
@@ -16,7 +15,6 @@
         %G:'1E+17'
         %G:'2.22507E-308'
         %G:'55.5556'
-        %G:'INF'
         %g:'-1'
         %g:'-1.11254e-308'
         %g:'-1.79769e+308'
@@ -25,7 +23,6 @@
         %g:'-1e+17'
         %g:'-2.22507e-308'
         %g:'-55.5556'
-        %g:'-inf'
         %g:'0'
         %g:'1'
         %g:'1.11254e-308'
@@ -35,7 +32,6 @@
         %g:'1e+17'
         %g:'2.22507e-308'
         %g:'55.5556'
-        %g:'inf'
        % G:' 0'
        % G:' 1'
        % G:' 1.11254E-308'
@@ -45,7 +41,6 @@
        % G:' 1E+17'
        % G:' 2.22507E-308'
        % G:' 55.5556'
-       % G:' INF'
        % G:'-1'
        % G:'-1.11254E-308'
        % G:'-1.79769E+308'
@@ -54,7 +49,6 @@
        % G:'-1E+17'
        % G:'-2.22507E-308'
        % G:'-55.5556'
-       % G:'-INF'
        % g:' 0'
        % g:' 1'
        % g:' 1.11254e-308'

[snip]

Index: general/string_format/string_format_g.m
===================================================================
RCS file: /home/mercury1/repository/tests/general/string_format/string_format_g.m,v
retrieving revision 1.2
diff -u -r1.2 string_format_g.m
--- general/string_format/string_format_g.m	20 Nov 2002 11:48:38 -0000	1.2
+++ general/string_format/string_format_g.m	21 Nov 2002 13:45:35 -0000
@@ -31,14 +31,12 @@
 	list__foldl(output_list(rounding_floats), FormatStrs_g),
 	list__foldl(output_list(extreme_floats), FormatStrs_g),
 	list__foldl(output_list(denormal_floats), FormatStrs_g),
-	list__foldl(output_list(infinite_floats), FormatStrs_g),
 
 	list__foldl(output_list(standard_floats), FormatStrs_G),
 	list__foldl(output_list(trailing_zero_floats), FormatStrs_G),
 	list__foldl(output_list(rounding_floats), FormatStrs_G),
 	list__foldl(output_list(extreme_floats), FormatStrs_G),
 	list__foldl(output_list(denormal_floats), FormatStrs_G),
-	list__foldl(output_list(infinite_floats), FormatStrs_G),
 	[].
 
 %------------------------------------------------------------------------------%

--------------------------------------------------------------------------
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