diff options
author | Sebastian <s@porto5.com> | 2021-01-19 14:30:01 +1100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2021-01-19 16:15:24 +0000 |
commit | 400cd752db3e04dcad8bf2a199a4d136ed85cedc (patch) | |
tree | 1b16c022923c2490204d426ee9040ed66d0f881b /test | |
parent | f78f931d642a3515452c8164c71e86670a6d7401 (diff) | |
download | gleam_stdlib-400cd752db3e04dcad8bf2a199a4d136ed85cedc.tar.gz gleam_stdlib-400cd752db3e04dcad8bf2a199a4d136ed85cedc.zip |
Add int.clamp and float.clamp
Diffstat (limited to 'test')
-rw-r--r-- | test/gleam/float_test.gleam | 11 | ||||
-rw-r--r-- | test/gleam/int_test.gleam | 15 |
2 files changed, 26 insertions, 0 deletions
diff --git a/test/gleam/float_test.gleam b/test/gleam/float_test.gleam index 2b3334e..3e0e6f6 100644 --- a/test/gleam/float_test.gleam +++ b/test/gleam/float_test.gleam @@ -38,6 +38,17 @@ pub fn to_string_test() { |> should.equal("-8.1") } +pub fn clamp_test() { + float.clamp(1.4, min: 1.3, max: 1.5) + |> should.equal(1.4) + + float.clamp(1.2, min: 1.3, max: 1.5) + |> should.equal(1.3) + + float.clamp(1.6, min: 1.3, max: 1.5) + |> should.equal(1.5) +} + pub fn compare_test() { float.compare(0., 0.) |> should.equal(order.Eq) diff --git a/test/gleam/int_test.gleam b/test/gleam/int_test.gleam index 11906db..bec9624 100644 --- a/test/gleam/int_test.gleam +++ b/test/gleam/int_test.gleam @@ -12,6 +12,21 @@ pub fn absolute_value_test() { |> should.equal(123) } +pub fn clamp_test() { + int.clamp(40, min: 30, max: 50) + |> should.equal(40) + + int.clamp(20, min: 30, max: 50) + |> should.equal(30) + + int.clamp(60, min: 30, max: 50) + |> should.equal(50) + + // If the bounds are reversed we return the min + int.clamp(100, min: 50, max: 30) + |> should.equal(50) +} + pub fn to_string_test() { 123 |> int.to_string |