diff options
author | inoas <mail@inoas.com> | 2022-04-11 23:54:33 +0200 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2022-04-16 10:23:34 +0100 |
commit | 75802b6408842e4f59521bd52e72237ef31cd64e (patch) | |
tree | bd252fffdd9816fed3e155d27925a8d62b5d1585 /test | |
parent | db20f5a296038fa6ba73172eac5bd5a3818942da (diff) | |
download | gleam_stdlib-75802b6408842e4f59521bd52e72237ef31cd64e.tar.gz gleam_stdlib-75802b6408842e4f59521bd52e72237ef31cd64e.zip |
wip
Diffstat (limited to 'test')
-rw-r--r-- | test/gleam/float_test.gleam | 12 | ||||
-rw-r--r-- | test/gleam/int_test.gleam | 54 |
2 files changed, 60 insertions, 6 deletions
diff --git a/test/gleam/float_test.gleam b/test/gleam/float_test.gleam index 4236bbd..c043741 100644 --- a/test/gleam/float_test.gleam +++ b/test/gleam/float_test.gleam @@ -302,17 +302,17 @@ pub fn product_test() { } pub fn random_lower_boundary_test() { - { float.random() >=. 0. } + { float.random_uniform() >=. 0. } |> should.be_true() - { float.random() <. 0. } + { float.random_uniform() <. 0. } |> should.be_false() } if erlang { pub fn random_upper_boundary_test() { - { float.random() <. 1. } + { float.random_uniform() <. 1. } |> should.be_true() - { float.random() >=. 1. } + { float.random_uniform() >=. 1. } |> should.be_false() } } @@ -321,9 +321,9 @@ if javascript { // Due to IEEE 754 floating point numbers // the ceiling may be rounded to 1.0 even if it should not pub fn random_upper_boundary_test() { - { float.random() <=. 1. } + { float.random_uniform() <=. 1. } |> should.be_true() - { float.random() >. 1. } + { float.random_uniform() >. 1. } |> should.be_false() } } diff --git a/test/gleam/int_test.gleam b/test/gleam/int_test.gleam index 1fbc102..90b573e 100644 --- a/test/gleam/int_test.gleam +++ b/test/gleam/int_test.gleam @@ -1,6 +1,8 @@ import gleam/should import gleam/int import gleam/order +import gleam/list +import gleam/iterator.{repeat} pub fn absolute_value_test() { 123 @@ -316,3 +318,55 @@ pub fn undigits_test() { int.undigits([1, 1, 2], 2) |> should.equal(Error(int.InvalidBase)) } + +pub fn random_below_test() { + let do_random_below_test = fn(_acc, _e) { + int.random_below(0) + |> should.equal(0) + + int.random_below(-1) + |> list.contains([-1], _) + |> should.be_true + + int.random_below(1) + |> list.contains([0], _) + |> should.be_true + + int.random_below(2) + |> list.contains([0, 1], _) + |> should.be_true + + int.random_below(3) + |> list.contains([0, 1, 2], _) + |> should.be_true + + int.random_below(4) + |> list.contains([0, 1, 2, 3], _) + |> should.be_true + } + list.range(0, 100) + |> iterator.from_list + |> iterator.fold(Nil, do_random_below_test) +} + +pub fn random_between_test() { + let do_random_between_test = fn(_acc, _e) { + int.random_between(0, 0) + |> should.equal(0) + + int.random_between(-1, 0) + |> list.contains([-1, 0], _) + |> should.be_true + + int.random_between(-1, 1) + |> list.contains([-1, 0], _) + |> should.be_true + + int.random_between(-1, 2) + |> list.contains([-1, 0, 1], _) + |> should.be_true + } + list.range(0, 100) + |> iterator.from_list + |> iterator.fold(Nil, do_random_between_test) +} |