diff options
author | Peter Saxton <peterhsaxton@gmail.com> | 2021-07-20 11:54:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-20 11:54:19 +0100 |
commit | 363d0a0c95fc1f3c91fe5c1101cac9d848c66fde (patch) | |
tree | e620eac17243e268ade54206aa7bd1995ede5732 /test | |
parent | d2ff5bec0c60fc748aa8c5c7ef7793430e1b1db2 (diff) | |
download | gleam_stdlib-363d0a0c95fc1f3c91fe5c1101cac9d848c66fde.tar.gz gleam_stdlib-363d0a0c95fc1f3c91fe5c1101cac9d848c66fde.zip |
Port int module to JS (#219)
Diffstat (limited to 'test')
-rw-r--r-- | test/gleam/int_test.gleam | 338 |
1 files changed, 168 insertions, 170 deletions
diff --git a/test/gleam/int_test.gleam b/test/gleam/int_test.gleam index 31d06de..bec9624 100644 --- a/test/gleam/int_test.gleam +++ b/test/gleam/int_test.gleam @@ -1,230 +1,228 @@ -if erlang { - import gleam/should - import gleam/int - import gleam/order - - pub fn absolute_value_test() { - 123 - |> int.absolute_value - |> should.equal(123) - - -123 - |> int.absolute_value - |> should.equal(123) - } +import gleam/should +import gleam/int +import gleam/order + +pub fn absolute_value_test() { + 123 + |> int.absolute_value + |> should.equal(123) + + -123 + |> int.absolute_value + |> should.equal(123) +} - pub fn clamp_test() { - int.clamp(40, min: 30, max: 50) - |> should.equal(40) +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(20, min: 30, max: 50) + |> should.equal(30) - int.clamp(60, min: 30, max: 50) - |> should.equal(50) + 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) - } + // 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 - |> should.equal("123") +pub fn to_string_test() { + 123 + |> int.to_string + |> should.equal("123") - -123 - |> int.to_string - |> should.equal("-123") + -123 + |> int.to_string + |> should.equal("-123") - 123 - |> int.to_string - |> should.equal("123") - } + 123 + |> int.to_string + |> should.equal("123") +} - pub fn parse_test() { - "123" - |> int.parse - |> should.equal(Ok(123)) +pub fn parse_test() { + "123" + |> int.parse + |> should.equal(Ok(123)) - "-123" - |> int.parse - |> should.equal(Ok(-123)) + "-123" + |> int.parse + |> should.equal(Ok(-123)) - "0123" - |> int.parse - |> should.equal(Ok(123)) + "0123" + |> int.parse + |> should.equal(Ok(123)) - "" - |> int.parse - |> should.equal(Error(Nil)) + "" + |> int.parse + |> should.equal(Error(Nil)) - "what" - |> int.parse - |> should.equal(Error(Nil)) + "what" + |> int.parse + |> should.equal(Error(Nil)) - "1.23" - |> int.parse - |> should.equal(Error(Nil)) - } + "1.23" + |> int.parse + |> should.equal(Error(Nil)) +} - pub fn to_base_string_test() { - 100 - |> int.to_base_string(16) - |> should.equal("64") +pub fn to_base_string_test() { + 100 + |> int.to_base_string(16) + |> should.equal("64") - -100 - |> int.to_base_string(16) - |> should.equal("-64") - } + -100 + |> int.to_base_string(16) + |> should.equal("-64") +} - pub fn to_float_test() { - int.to_float(1) - |> should.equal(1.) +pub fn to_float_test() { + int.to_float(1) + |> should.equal(1.) - int.to_float(5) - |> should.equal(5.) + int.to_float(5) + |> should.equal(5.) - int.to_float(0) - |> should.equal(0.) + int.to_float(0) + |> should.equal(0.) - int.to_float(-5) - |> should.equal(-5.) - } + int.to_float(-5) + |> should.equal(-5.) +} - pub fn compare_test() { - int.compare(0, 0) - |> should.equal(order.Eq) +pub fn compare_test() { + int.compare(0, 0) + |> should.equal(order.Eq) - int.compare(1, 1) - |> should.equal(order.Eq) + int.compare(1, 1) + |> should.equal(order.Eq) - int.compare(0, 1) - |> should.equal(order.Lt) + int.compare(0, 1) + |> should.equal(order.Lt) - int.compare(-2, -1) - |> should.equal(order.Lt) + int.compare(-2, -1) + |> should.equal(order.Lt) - int.compare(2, 1) - |> should.equal(order.Gt) + int.compare(2, 1) + |> should.equal(order.Gt) - int.compare(-1, -2) - |> should.equal(order.Gt) - } + int.compare(-1, -2) + |> should.equal(order.Gt) +} - pub fn min_test() { - int.min(0, 0) - |> should.equal(0) +pub fn min_test() { + int.min(0, 0) + |> should.equal(0) - int.min(0, 1) - |> should.equal(0) + int.min(0, 1) + |> should.equal(0) - int.min(1, 0) - |> should.equal(0) + int.min(1, 0) + |> should.equal(0) - int.min(-1, 2) - |> should.equal(-1) + int.min(-1, 2) + |> should.equal(-1) - int.min(2, -2) - |> should.equal(-2) + int.min(2, -2) + |> should.equal(-2) - int.min(-1, -1) - |> should.equal(-1) - } + int.min(-1, -1) + |> should.equal(-1) +} - pub fn max_test() { - int.max(0, 0) - |> should.equal(0) +pub fn max_test() { + int.max(0, 0) + |> should.equal(0) - int.max(0, 1) - |> should.equal(1) + int.max(0, 1) + |> should.equal(1) - int.max(1, 0) - |> should.equal(1) + int.max(1, 0) + |> should.equal(1) - int.max(-1, 2) - |> should.equal(2) + int.max(-1, 2) + |> should.equal(2) - int.max(2, -2) - |> should.equal(2) + int.max(2, -2) + |> should.equal(2) - int.max(-1, -1) - |> should.equal(-1) - } + int.max(-1, -1) + |> should.equal(-1) +} - pub fn is_even_test() { - int.is_even(0) - |> should.be_true +pub fn is_even_test() { + int.is_even(0) + |> should.be_true - int.is_even(2) - |> should.be_true + int.is_even(2) + |> should.be_true - int.is_even(-2) - |> should.be_true + int.is_even(-2) + |> should.be_true - int.is_even(10006) - |> should.be_true + int.is_even(10006) + |> should.be_true - int.is_even(1) - |> should.be_false + int.is_even(1) + |> should.be_false - int.is_even(-3) - |> should.be_false + int.is_even(-3) + |> should.be_false - int.is_even(10005) - |> should.be_false - } + int.is_even(10005) + |> should.be_false +} - pub fn is_odd_test() { - int.is_odd(0) - |> should.be_false +pub fn is_odd_test() { + int.is_odd(0) + |> should.be_false - int.is_odd(2) - |> should.be_false + int.is_odd(2) + |> should.be_false - int.is_odd(-2) - |> should.be_false + int.is_odd(-2) + |> should.be_false - int.is_odd(10006) - |> should.be_false + int.is_odd(10006) + |> should.be_false - int.is_odd(1) - |> should.be_true + int.is_odd(1) + |> should.be_true - int.is_odd(-3) - |> should.be_true + int.is_odd(-3) + |> should.be_true - int.is_odd(10005) - |> should.be_true - } + int.is_odd(10005) + |> should.be_true +} - pub fn negate_test() { - int.negate(-1) - |> should.equal(1) +pub fn negate_test() { + int.negate(-1) + |> should.equal(1) - int.negate(2) - |> should.equal(-2) + int.negate(2) + |> should.equal(-2) - int.negate(0) - |> should.equal(0) - } + int.negate(0) + |> should.equal(0) +} - pub fn sum_test() { - int.sum([]) - |> should.equal(0) +pub fn sum_test() { + int.sum([]) + |> should.equal(0) - int.sum([1, 2, 3]) - |> should.equal(6) - } + int.sum([1, 2, 3]) + |> should.equal(6) +} - pub fn product_test() { - int.product([]) - |> should.equal(0) +pub fn product_test() { + int.product([]) + |> should.equal(0) - int.product([4]) - |> should.equal(4) + int.product([4]) + |> should.equal(4) - int.product([1, 2, 3]) - |> should.equal(6) - } + int.product([1, 2, 3]) + |> should.equal(6) } |