aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/gleam/float_test.gleam11
-rw-r--r--test/gleam/int_test.gleam15
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