diff options
author | Russ Cox <rsc@golang.org> | 2009-01-15 16:16:42 -0800 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2009-01-15 16:16:42 -0800 |
commit | 1b3fa1f62001aceb5c673148356beb54ba91f87f (patch) | |
tree | 9d9b1dfbe73caef370fe08a30bd628ea18f62f20 /src/lib/strconv/atof_test.go | |
parent | fb7b8b51fb14a8209a05b940aea00fe7ef8c8385 (diff) | |
download | golang-1b3fa1f62001aceb5c673148356beb54ba91f87f.tar.gz |
make safe for new package local defaults
R=r
DELTA=462 (9 added, 33 deleted, 420 changed)
OCL=22879
CL=22885
Diffstat (limited to 'src/lib/strconv/atof_test.go')
-rw-r--r-- | src/lib/strconv/atof_test.go | 116 |
1 files changed, 58 insertions, 58 deletions
diff --git a/src/lib/strconv/atof_test.go b/src/lib/strconv/atof_test.go index ab4fcd146..5292b3d0d 100644 --- a/src/lib/strconv/atof_test.go +++ b/src/lib/strconv/atof_test.go @@ -10,92 +10,92 @@ import ( "testing" ) -type Test struct { +type AtofTest struct { in string; out string; err *os.Error; } -var tests = []Test { - Test{ "", "0", os.EINVAL }, - Test{ "1", "1", nil }, - Test{ "+1", "1", nil }, - Test{ "1x", "0", os.EINVAL }, - Test{ "1.1.", "0", os.EINVAL }, - Test{ "1e23", "1e+23", nil }, - Test{ "100000000000000000000000", "1e+23", nil }, - Test{ "1e-100", "1e-100", nil }, - Test{ "123456700", "1.234567e+08", nil }, - Test{ "99999999999999974834176", "9.999999999999997e+22", nil }, - Test{ "100000000000000000000001", "1.0000000000000001e+23", nil }, - Test{ "100000000000000008388608", "1.0000000000000001e+23", nil }, - Test{ "100000000000000016777215", "1.0000000000000001e+23", nil }, - Test{ "100000000000000016777216", "1.0000000000000003e+23", nil }, - Test{ "-1", "-1", nil }, - Test{ "-0", "-0", nil }, - Test{ "1e-20", "1e-20", nil }, - Test{ "625e-3", "0.625", nil }, +var atoftests = []AtofTest { + AtofTest{ "", "0", os.EINVAL }, + AtofTest{ "1", "1", nil }, + AtofTest{ "+1", "1", nil }, + AtofTest{ "1x", "0", os.EINVAL }, + AtofTest{ "1.1.", "0", os.EINVAL }, + AtofTest{ "1e23", "1e+23", nil }, + AtofTest{ "100000000000000000000000", "1e+23", nil }, + AtofTest{ "1e-100", "1e-100", nil }, + AtofTest{ "123456700", "1.234567e+08", nil }, + AtofTest{ "99999999999999974834176", "9.999999999999997e+22", nil }, + AtofTest{ "100000000000000000000001", "1.0000000000000001e+23", nil }, + AtofTest{ "100000000000000008388608", "1.0000000000000001e+23", nil }, + AtofTest{ "100000000000000016777215", "1.0000000000000001e+23", nil }, + AtofTest{ "100000000000000016777216", "1.0000000000000003e+23", nil }, + AtofTest{ "-1", "-1", nil }, + AtofTest{ "-0", "-0", nil }, + AtofTest{ "1e-20", "1e-20", nil }, + AtofTest{ "625e-3", "0.625", nil }, // largest float64 - Test{ "1.7976931348623157e308", "1.7976931348623157e+308", nil }, - Test{ "-1.7976931348623157e308", "-1.7976931348623157e+308", nil }, + AtofTest{ "1.7976931348623157e308", "1.7976931348623157e+308", nil }, + AtofTest{ "-1.7976931348623157e308", "-1.7976931348623157e+308", nil }, // next float64 - too large - Test{ "1.7976931348623159e308", "+Inf", os.ERANGE }, - Test{ "-1.7976931348623159e308", "-Inf", os.ERANGE }, + AtofTest{ "1.7976931348623159e308", "+Inf", os.ERANGE }, + AtofTest{ "-1.7976931348623159e308", "-Inf", os.ERANGE }, // the border is ...158079 // borderline - okay - Test{ "1.7976931348623158e308", "1.7976931348623157e+308", nil }, - Test{ "-1.7976931348623158e308", "-1.7976931348623157e+308", nil }, + AtofTest{ "1.7976931348623158e308", "1.7976931348623157e+308", nil }, + AtofTest{ "-1.7976931348623158e308", "-1.7976931348623157e+308", nil }, // borderline - too large - Test{ "1.797693134862315808e308", "+Inf", os.ERANGE }, - Test{ "-1.797693134862315808e308", "-Inf", os.ERANGE }, + AtofTest{ "1.797693134862315808e308", "+Inf", os.ERANGE }, + AtofTest{ "-1.797693134862315808e308", "-Inf", os.ERANGE }, // a little too large - Test{ "1e308", "1e+308", nil }, - Test{ "2e308", "+Inf", os.ERANGE }, - Test{ "1e309", "+Inf", os.ERANGE }, + AtofTest{ "1e308", "1e+308", nil }, + AtofTest{ "2e308", "+Inf", os.ERANGE }, + AtofTest{ "1e309", "+Inf", os.ERANGE }, // way too large - Test{ "1e310", "+Inf", os.ERANGE }, - Test{ "-1e310", "-Inf", os.ERANGE }, - Test{ "1e400", "+Inf", os.ERANGE }, - Test{ "-1e400", "-Inf", os.ERANGE }, - Test{ "1e400000", "+Inf", os.ERANGE }, - Test{ "-1e400000", "-Inf", os.ERANGE }, + AtofTest{ "1e310", "+Inf", os.ERANGE }, + AtofTest{ "-1e310", "-Inf", os.ERANGE }, + AtofTest{ "1e400", "+Inf", os.ERANGE }, + AtofTest{ "-1e400", "-Inf", os.ERANGE }, + AtofTest{ "1e400000", "+Inf", os.ERANGE }, + AtofTest{ "-1e400000", "-Inf", os.ERANGE }, // denormalized - Test{ "1e-305", "1e-305", nil }, - Test{ "1e-306", "1e-306", nil }, - Test{ "1e-307", "1e-307", nil }, - Test{ "1e-308", "1e-308", nil }, - Test{ "1e-309", "1e-309", nil }, - Test{ "1e-310", "1e-310", nil }, - Test{ "1e-322", "1e-322", nil }, + AtofTest{ "1e-305", "1e-305", nil }, + AtofTest{ "1e-306", "1e-306", nil }, + AtofTest{ "1e-307", "1e-307", nil }, + AtofTest{ "1e-308", "1e-308", nil }, + AtofTest{ "1e-309", "1e-309", nil }, + AtofTest{ "1e-310", "1e-310", nil }, + AtofTest{ "1e-322", "1e-322", nil }, // smallest denormal - Test{ "5e-324", "5e-324", nil }, + AtofTest{ "5e-324", "5e-324", nil }, // too small - Test{ "4e-324", "0", nil }, + AtofTest{ "4e-324", "0", nil }, // way too small - Test{ "1e-350", "0", nil }, - Test{ "1e-400000", "0", nil }, + AtofTest{ "1e-350", "0", nil }, + AtofTest{ "1e-400000", "0", nil }, // try to overflow exponent - Test{ "1e-4294967296", "0", nil }, - Test{ "1e+4294967296", "+Inf", os.ERANGE }, - Test{ "1e-18446744073709551616", "0", nil }, - Test{ "1e+18446744073709551616", "+Inf", os.ERANGE }, + AtofTest{ "1e-4294967296", "0", nil }, + AtofTest{ "1e+4294967296", "+Inf", os.ERANGE }, + AtofTest{ "1e-18446744073709551616", "0", nil }, + AtofTest{ "1e+18446744073709551616", "+Inf", os.ERANGE }, // Parse errors - Test{ "1e", "0", os.EINVAL }, - Test{ "1e-", "0", os.EINVAL }, - Test{ ".e-1", "0", os.EINVAL }, + AtofTest{ "1e", "0", os.EINVAL }, + AtofTest{ "1e-", "0", os.EINVAL }, + AtofTest{ ".e-1", "0", os.EINVAL }, } func XTestAtof(t *testing.T, opt bool) { oldopt := strconv.optimize; strconv.optimize = opt; - for i := 0; i < len(tests); i++ { - test := &tests[i]; + for i := 0; i < len(atoftests); i++ { + test := &atoftests[i]; out, err := strconv.atof64(test.in); outs := strconv.ftoa64(out, 'g', -1); if outs != test.out || err != test.err { @@ -112,7 +112,7 @@ func XTestAtof(t *testing.T, opt bool) { } } - if floatsize == 64 || float64(float32(out)) == out { + if FloatSize == 64 || float64(float32(out)) == out { outf, err := strconv.atof(test.in); outs := strconv.ftoa(outf, 'g', -1); if outs != test.out || err != test.err { |