diff options
Diffstat (limited to 'test/gleam/int_test.gleam')
-rw-r--r-- | test/gleam/int_test.gleam | 338 |
1 files changed, 170 insertions, 168 deletions
diff --git a/test/gleam/int_test.gleam b/test/gleam/int_test.gleam index bec9624..31d06de 100644 --- a/test/gleam/int_test.gleam +++ b/test/gleam/int_test.gleam @@ -1,228 +1,230 @@ -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) -} +if erlang { + import gleam/should + import gleam/int + import gleam/order + + pub fn absolute_value_test() { + 123 + |> int.absolute_value + |> should.equal(123) -pub fn clamp_test() { - int.clamp(40, min: 30, max: 50) - |> should.equal(40) + -123 + |> int.absolute_value + |> should.equal(123) + } - int.clamp(20, min: 30, max: 50) - |> should.equal(30) + pub fn clamp_test() { + int.clamp(40, min: 30, max: 50) + |> should.equal(40) - int.clamp(60, min: 30, max: 50) - |> should.equal(50) + int.clamp(20, min: 30, max: 50) + |> should.equal(30) - // If the bounds are reversed we return the min - int.clamp(100, min: 50, max: 30) - |> should.equal(50) -} + int.clamp(60, min: 30, max: 50) + |> should.equal(50) -pub fn to_string_test() { - 123 - |> int.to_string - |> should.equal("123") + // If the bounds are reversed we return the min + int.clamp(100, min: 50, max: 30) + |> should.equal(50) + } - -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") -pub fn parse_test() { - "123" - |> int.parse - |> should.equal(Ok(123)) + 123 + |> int.to_string + |> should.equal("123") + } - "-123" - |> int.parse - |> should.equal(Ok(-123)) + pub fn parse_test() { + "123" + |> int.parse + |> should.equal(Ok(123)) - "0123" - |> int.parse - |> should.equal(Ok(123)) + "-123" + |> int.parse + |> should.equal(Ok(-123)) - "" - |> int.parse - |> should.equal(Error(Nil)) + "0123" + |> int.parse + |> should.equal(Ok(123)) - "what" - |> int.parse - |> should.equal(Error(Nil)) + "" + |> int.parse + |> should.equal(Error(Nil)) - "1.23" - |> int.parse - |> should.equal(Error(Nil)) -} + "what" + |> int.parse + |> should.equal(Error(Nil)) -pub fn to_base_string_test() { - 100 - |> int.to_base_string(16) - |> should.equal("64") + "1.23" + |> int.parse + |> should.equal(Error(Nil)) + } - -100 - |> int.to_base_string(16) - |> should.equal("-64") -} + pub fn to_base_string_test() { + 100 + |> int.to_base_string(16) + |> should.equal("64") -pub fn to_float_test() { - int.to_float(1) - |> should.equal(1.) + -100 + |> int.to_base_string(16) + |> should.equal("-64") + } - int.to_float(5) - |> should.equal(5.) + pub fn to_float_test() { + int.to_float(1) + |> should.equal(1.) - int.to_float(0) - |> should.equal(0.) + int.to_float(5) + |> should.equal(5.) - int.to_float(-5) - |> should.equal(-5.) -} + int.to_float(0) + |> should.equal(0.) -pub fn compare_test() { - int.compare(0, 0) - |> should.equal(order.Eq) + int.to_float(-5) + |> should.equal(-5.) + } - int.compare(1, 1) - |> should.equal(order.Eq) + pub fn compare_test() { + int.compare(0, 0) + |> should.equal(order.Eq) - int.compare(0, 1) - |> should.equal(order.Lt) + int.compare(1, 1) + |> should.equal(order.Eq) - int.compare(-2, -1) - |> should.equal(order.Lt) + int.compare(0, 1) + |> should.equal(order.Lt) - int.compare(2, 1) - |> should.equal(order.Gt) + int.compare(-2, -1) + |> should.equal(order.Lt) - int.compare(-1, -2) - |> should.equal(order.Gt) -} + int.compare(2, 1) + |> should.equal(order.Gt) -pub fn min_test() { - int.min(0, 0) - |> should.equal(0) + int.compare(-1, -2) + |> should.equal(order.Gt) + } - int.min(0, 1) - |> should.equal(0) + pub fn min_test() { + int.min(0, 0) + |> should.equal(0) - int.min(1, 0) - |> should.equal(0) + int.min(0, 1) + |> should.equal(0) - int.min(-1, 2) - |> should.equal(-1) + int.min(1, 0) + |> should.equal(0) - int.min(2, -2) - |> should.equal(-2) + int.min(-1, 2) + |> should.equal(-1) - int.min(-1, -1) - |> should.equal(-1) -} + int.min(2, -2) + |> should.equal(-2) -pub fn max_test() { - int.max(0, 0) - |> should.equal(0) + int.min(-1, -1) + |> should.equal(-1) + } - int.max(0, 1) - |> should.equal(1) + pub fn max_test() { + int.max(0, 0) + |> should.equal(0) - int.max(1, 0) - |> should.equal(1) + int.max(0, 1) + |> should.equal(1) - int.max(-1, 2) - |> should.equal(2) + int.max(1, 0) + |> should.equal(1) - int.max(2, -2) - |> should.equal(2) + int.max(-1, 2) + |> should.equal(2) - int.max(-1, -1) - |> should.equal(-1) -} + int.max(2, -2) + |> should.equal(2) -pub fn is_even_test() { - int.is_even(0) - |> should.be_true + int.max(-1, -1) + |> should.equal(-1) + } - int.is_even(2) - |> 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(10006) - |> should.be_true + int.is_even(-2) + |> should.be_true - int.is_even(1) - |> should.be_false + int.is_even(10006) + |> should.be_true - int.is_even(-3) - |> should.be_false + int.is_even(1) + |> should.be_false - int.is_even(10005) - |> should.be_false -} + int.is_even(-3) + |> should.be_false -pub fn is_odd_test() { - int.is_odd(0) - |> should.be_false + int.is_even(10005) + |> should.be_false + } - int.is_odd(2) - |> 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(10006) - |> should.be_false + int.is_odd(-2) + |> should.be_false - int.is_odd(1) - |> should.be_true + int.is_odd(10006) + |> should.be_false - int.is_odd(-3) - |> should.be_true + int.is_odd(1) + |> should.be_true - int.is_odd(10005) - |> should.be_true -} + int.is_odd(-3) + |> should.be_true -pub fn negate_test() { - int.negate(-1) - |> should.equal(1) + int.is_odd(10005) + |> should.be_true + } - int.negate(2) - |> should.equal(-2) + pub fn negate_test() { + int.negate(-1) + |> should.equal(1) - int.negate(0) - |> should.equal(0) -} + int.negate(2) + |> should.equal(-2) -pub fn sum_test() { - int.sum([]) - |> should.equal(0) + int.negate(0) + |> should.equal(0) + } - int.sum([1, 2, 3]) - |> should.equal(6) -} + pub fn sum_test() { + int.sum([]) + |> should.equal(0) + + 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) + } } |