aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlex Rothuis <alex.rothuis@gmail.com>2022-11-01 01:03:48 +0100
committerLouis Pilfold <louis@lpil.uk>2022-11-06 16:45:54 +0000
commit610b56061c0687d3590a079639cbaee6ee9d746a (patch)
tree2864002c8c2a29c419f6df90cad1d90637595814 /test
parent7dc27b39843c31b1ac35845b83ec5c1ca7b15c1f (diff)
downloadgleam_stdlib-610b56061c0687d3590a079639cbaee6ee9d746a.tar.gz
gleam_stdlib-610b56061c0687d3590a079639cbaee6ee9d746a.zip
Add operator functions
Allows using operators as functions. Useful in higher order functions or pipes.
Diffstat (limited to 'test')
-rw-r--r--test/gleam/bool_test.gleam28
-rw-r--r--test/gleam/float_test.gleam42
-rw-r--r--test/gleam/int_test.gleam42
3 files changed, 112 insertions, 0 deletions
diff --git a/test/gleam/bool_test.gleam b/test/gleam/bool_test.gleam
index 24607fb..e4dddd9 100644
--- a/test/gleam/bool_test.gleam
+++ b/test/gleam/bool_test.gleam
@@ -2,6 +2,34 @@ import gleam/bool
import gleam/order
import gleam/should
+pub fn and_test() {
+ bool.and(True, True)
+ |> should.be_true
+
+ bool.and(False, True)
+ |> should.be_false
+
+ True |> bool.and(_, True)
+ |> should.be_true
+
+ False |> bool.and(True, _)
+ |> should.be_false
+}
+
+pub fn or_test() {
+ bool.or(True, True)
+ |> should.be_true
+
+ bool.or(False, True)
+ |> should.be_true
+
+ True |> bool.or(_, False)
+ |> should.be_true
+
+ False |> bool.or(True, _)
+ |> should.be_true
+}
+
pub fn negate_test() {
bool.negate(True)
|> should.be_false
diff --git a/test/gleam/float_test.gleam b/test/gleam/float_test.gleam
index e952908..ff11dff 100644
--- a/test/gleam/float_test.gleam
+++ b/test/gleam/float_test.gleam
@@ -390,3 +390,45 @@ pub fn divide_test() {
float.divide(1.0, by: 0.0)
|> should.equal(Error(Nil))
}
+
+pub fn add_test() {
+ float.add(1.0, 2.0)
+ |> should.equal(3.0)
+
+ list.fold([1.0, 2.0, 3.0], 0.0, float.add)
+ |> should.equal(6.0)
+
+ 3.0 |> float.add(2.0)
+ |> should.equal(5.0)
+}
+
+pub fn multiply_test() {
+ float.multiply(2.0, 4.0)
+ |> should.equal(8.0)
+
+ list.fold([2.0, 3.0, 4.0], 1.0, float.multiply)
+ |> should.equal(24.0)
+
+ 3.0 |> float.multiply(2.0)
+ |> should.equal(6.0)
+}
+
+pub fn subtract_test() {
+ float.subtract(3.0, 1.0)
+ |> should.equal(2.0)
+
+ list.fold([1.0, 2.0, 3.0], 10.0, float.subtract)
+ |> should.equal(4.0)
+
+ 3.0 |> float.subtract(_, 2.0)
+ |> should.equal(1.0)
+
+ 3.0 |> float.subtract(2.0, _)
+ |> should.equal(-1.0)
+
+ 3.0 |> float.subtract(subtrahend: 2.0)
+ |> should.equal(1.0)
+
+ 3.0 |> float.subtract(minuend: 2.0)
+ |> should.equal(-1.0)
+}
diff --git a/test/gleam/int_test.gleam b/test/gleam/int_test.gleam
index 87de970..90f7e8d 100644
--- a/test/gleam/int_test.gleam
+++ b/test/gleam/int_test.gleam
@@ -500,3 +500,45 @@ pub fn floor_divide_test() {
int.floor_divide(-99, by: 2)
|> should.equal(Ok(-50))
}
+
+pub fn add_test() {
+ int.add(1, 2)
+ |> should.equal(3)
+
+ list.fold([1, 2, 3], 0, int.add)
+ |> should.equal(6)
+
+ 3 |> int.add(2)
+ |> should.equal(5)
+}
+
+pub fn multiply_test() {
+ int.multiply(2, 4)
+ |> should.equal(8)
+
+ list.fold([2, 3, 4], 1, int.multiply)
+ |> should.equal(24)
+
+ 3 |> int.multiply(2)
+ |> should.equal(6)
+}
+
+pub fn subtract_test() {
+ int.subtract(3, 1)
+ |> should.equal(2)
+
+ list.fold([1, 2, 3], 10, int.subtract)
+ |> should.equal(4)
+
+ 3 |> int.subtract(_, 2)
+ |> should.equal(1)
+
+ 3 |> int.subtract(2, _)
+ |> should.equal(-1)
+
+ 3 |> int.subtract(subtrahend: 2)
+ |> should.equal(1)
+
+ 3 |> int.subtract(minuend: 2)
+ |> should.equal(-1)
+}