aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/test
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2011-10-03 19:08:20 +0200
committerLukas Larsson <[email protected]>2011-10-11 17:19:01 +0200
commit3dc379948b1d7ce6c4f35f56df937603a6013f24 (patch)
tree76dc450ed0f5a01c33d07d7b321a7f911007e5f6 /erts/emulator/test
parent3b62e52f16ef72ce4224a61dc9e6bc7ab53234a1 (diff)
downloadotp-3dc379948b1d7ce6c4f35f56df937603a6013f24.tar.gz
otp-3dc379948b1d7ce6c4f35f56df937603a6013f24.tar.bz2
otp-3dc379948b1d7ce6c4f35f56df937603a6013f24.zip
Add tests for equality checking
Test for checking equality on all float exponents Test in equality for all comparison tests
Diffstat (limited to 'erts/emulator/test')
-rw-r--r--erts/emulator/test/float_SUITE.erl41
1 files changed, 35 insertions, 6 deletions
diff --git a/erts/emulator/test/float_SUITE.erl b/erts/emulator/test/float_SUITE.erl
index bf0fbc70bc..46466427c5 100644
--- a/erts/emulator/test/float_SUITE.erl
+++ b/erts/emulator/test/float_SUITE.erl
@@ -198,13 +198,19 @@ cmp_integer(_Config) ->
cmp_bignum(_Config) ->
span_cmp((1 bsl 58) - 1.0),%% Smallest bignum float
- %% Test I to I+1 bignum segment overflow
+ %% Test when the big num goes from I to I+1 in size
[span_cmp((1 bsl (32*I)) - 1.0) || I <- lists:seq(2,30)],
+ %% Test bignum greater then largest float
cmp((1 bsl (64*16)) - 1, (1 bsl (64*15)) * 1.0),
+ %% Test when num is much larger then float
[cmp((1 bsl (32*I)) - 1, (1 bsl (32*(I-2))) * 1.0) || I <- lists:seq(3,30)],
+ %% Test when float is much larger than num
[cmp((1 bsl (64*15)) * 1.0, (1 bsl (32*(I)))) || I <- lists:seq(1,29)],
- ok.
+
+ %% Test that all int == float works as they should
+ [true = 1 bsl N == (1 bsl N)*1.0 || N <- lists:seq(0, 1023)],
+ [true = (1 bsl N)*-1 == (1 bsl N)*-1.0 || N <- lists:seq(0, 1023)].
span_cmp(Axis) ->
span_cmp(Axis, 25).
@@ -212,6 +218,14 @@ span_cmp(Axis, Length) ->
span_cmp(Axis, round(Axis) bsr 52, Length).
span_cmp(Axis, Incr, Length) ->
[span_cmp(Axis, Incr, Length, 1 bsl (1 bsl I)) || I <- lists:seq(0,6)].
+%% This function creates tests around number axis. Both <, > and == is tested
+%% for both negative and positive numbers.
+%%
+%% Axis: The number around which to do the tests eg. (1 bsl 58) - 1.0
+%% Incr: How much to increment the test numbers inbetween each test.
+%% Length: Length/2 is the number of Incr away from Axis to test on the
+%% negative and positive plane.
+%% Diff: How much the float and int should differ when comparing
span_cmp(Axis, Incr, Length, Diff) ->
[begin
cmp(round(Axis*-1.0)+Diff+I*Incr,Axis*-1.0+I*Incr),
@@ -227,23 +241,34 @@ cmp(Big,Small) when is_float(Big) ->
io_lib:format("~f > ~p",[Big,Small])),
BigLtSmall = lists:flatten(
io_lib:format("~f < ~p",[Big,Small])),
+ BigEqSmall = lists:flatten(
+ io_lib:format("~f == ~p",[Big,Small])),
SmallGtBig = lists:flatten(
io_lib:format("~p > ~f",[Small,Big])),
SmallLtBig = lists:flatten(
io_lib:format("~p < ~f",[Small,Big])),
- cmp(Big,Small,BigGtSmall,BigLtSmall,SmallGtBig,SmallLtBig);
+ SmallEqBig = lists:flatten(
+ io_lib:format("~p == ~f",[Small,Big])),
+ cmp(Big,Small,BigGtSmall,BigLtSmall,SmallGtBig,SmallLtBig,
+ SmallEqBig,BigEqSmall);
cmp(Big,Small) when is_float(Small) ->
BigGtSmall = lists:flatten(
io_lib:format("~p > ~f",[Big,Small])),
BigLtSmall = lists:flatten(
io_lib:format("~p < ~f",[Big,Small])),
+ BigEqSmall = lists:flatten(
+ io_lib:format("~p == ~f",[Big,Small])),
SmallGtBig = lists:flatten(
io_lib:format("~f > ~p",[Small,Big])),
SmallLtBig = lists:flatten(
io_lib:format("~f < ~p",[Small,Big])),
- cmp(Big,Small,BigGtSmall,BigLtSmall,SmallGtBig,SmallLtBig).
+ SmallEqBig = lists:flatten(
+ io_lib:format("~f == ~p",[Small,Big])),
+ cmp(Big,Small,BigGtSmall,BigLtSmall,SmallGtBig,SmallLtBig,
+ SmallEqBig,BigEqSmall).
-cmp(Big,Small,BigGtSmall,BigLtSmall,SmallGtBig,SmallLtBig) ->
+cmp(Big,Small,BigGtSmall,BigLtSmall,SmallGtBig,SmallLtBig,
+ SmallEqBig,BigEqSmall) ->
{_,_,_,true} = {Big,Small,BigGtSmall,
Big > Small},
{_,_,_,false} = {Big,Small,BigLtSmall,
@@ -251,7 +276,11 @@ cmp(Big,Small,BigGtSmall,BigLtSmall,SmallGtBig,SmallLtBig) ->
{_,_,_,false} = {Big,Small,SmallGtBig,
Small > Big},
{_,_,_,true} = {Big,Small,SmallLtBig,
- Small < Big}.
+ Small < Big},
+ {_,_,_,false} = {Big,Small,SmallEqBig,
+ Small == Big},
+ {_,_,_,false} = {Big,Small,BigEqSmall,
+ Big == Small}.
id(I) -> I.