You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/01/17 23:12:13 UTC
[42/50] [abbrv] git commit: Add tests from double-conversion library
Add tests from double-conversion library
I pulled in a lot of tests from the double-conversion test suite to make
sure we don't accidentally break behavior in the future.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/56dfd50c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/56dfd50c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/56dfd50c
Branch: refs/heads/import
Commit: 56dfd50c6a427895bfc35bd2c2486f59c981d578
Parents: 90b28c6
Author: Paul J. Davis <pa...@gmail.com>
Authored: Sun Feb 24 22:11:54 2013 -0600
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Sun Feb 24 22:14:35 2013 -0600
----------------------------------------------------------------------
test/003-numbers.t | 49 +-
test/010-short-doubles.t | 29 +
test/cases/short-doubles.txt | 100000 +++++++++++++++++++++++++++++++++++
3 files changed, 100077 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/56dfd50c/test/003-numbers.t
----------------------------------------------------------------------
diff --git a/test/003-numbers.t b/test/003-numbers.t
index 9196706..2ac2ab4 100755
--- a/test/003-numbers.t
+++ b/test/003-numbers.t
@@ -6,11 +6,22 @@ main([]) ->
code:add_pathz("ebin"),
code:add_pathz("test"),
- etap:plan(59),
+ etap:plan(59 + 2 * length(double_conversion_tests())),
util:test_good(good()),
util:test_errors(errors()),
+ run_double_conversion_tests(),
etap:end_tests().
+
+run_double_conversion_tests() ->
+ lists:foreach(fun(Double) ->
+ Descr = io_lib:format("~f", [Double]),
+ etap:is(jiffy:decode(jiffy:encode(Double)), Double, Descr),
+ NegDouble = -1.0 * Double,
+ NegDescr = io_lib:format("~f", [NegDouble]),
+ etap:is(jiffy:decode(jiffy:encode(NegDouble)), NegDouble, NegDescr)
+ end, double_conversion_tests()).
+
good() ->
[
{<<"0">>, 0},
@@ -55,6 +66,7 @@ good() ->
{<<"-0.325E+2">>, -32.5, <<"-32.5">>}
].
+
errors() ->
[
<<"02">>,
@@ -69,3 +81,38 @@ errors() ->
<<"2E +3">>,
<<"1EA">>
].
+
+
+double_conversion_tests() ->
+ [
+ 0.0,
+ 0.00000001,
+ 0.000000012,
+ 0.0000000123,
+ 0.0000001,
+ 0.00000012,
+ 0.000000123,
+ 0.000001,
+ 0.00001,
+ 0.01,
+ 0.0123,
+ 0.1,
+ 0.3,
+ 1.0,
+ 1.0e20,
+ 1.0e21,
+ 9.0,
+ 10.0,
+ 90.0,
+ 90.12,
+ 10000.0,
+ 12345.0,
+ 12345.0e23,
+ 100000.0,
+ 100000000000000000000.0,
+ 111111111111111111111.0,
+ 1111111111111111111111.0,
+ 11111111111111111111111.0
+ ].
+
+
http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/56dfd50c/test/010-short-doubles.t
----------------------------------------------------------------------
diff --git a/test/010-short-doubles.t b/test/010-short-doubles.t
new file mode 100755
index 0000000..9c4ecd1
--- /dev/null
+++ b/test/010-short-doubles.t
@@ -0,0 +1,29 @@
+#! /usr/bin/env escript
+% This file is part of Jiffy released under the MIT license.
+% See the LICENSE file for more information.
+
+filename() -> "test/cases/short-doubles.txt".
+
+main([]) ->
+ code:add_pathz("ebin"),
+ code:add_pathz("test"),
+
+ etap:plan(100000),
+
+ etap:diag("Loading test cases..."),
+ {ok, Cases} = file:consult(filename()),
+
+ etap:diag("Running tests..."),
+ ok = run_tests(Cases),
+
+ etap:end_tests().
+
+
+run_tests([]) ->
+ ok;
+run_tests([{Double, _, _} | Rest]) ->
+ RoundTrip = jiffy:decode(jiffy:encode(Double)),
+ Desc = lists:flatten(io_lib:format("~e", [Double])),
+ etap:is(RoundTrip, Double, "Roundtrip: " ++ Desc),
+ run_tests(Rest).
+