aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorinoas <mail@inoas.com>2022-10-14 10:08:18 +0000
committerGitHub <noreply@github.com>2022-10-14 11:08:18 +0100
commit64b810dfd8cc0b9d9dcbbc6919e9f8a5f12a8cef (patch)
tree45960022ef31c8e02cd9060446dc71ecf8dfdb1c /test
parentfe6271001fe8d7458a284bfb5cc8ac2cdf6d93b3 (diff)
downloadgleam_stdlib-64b810dfd8cc0b9d9dcbbc6919e9f8a5f12a8cef.tar.gz
gleam_stdlib-64b810dfd8cc0b9d9dcbbc6919e9f8a5f12a8cef.zip
Add `int.{remainder, modulo}` (#342)
Diffstat (limited to 'test')
-rw-r--r--test/gleam/int_test.gleam54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/gleam/int_test.gleam b/test/gleam/int_test.gleam
index 26e36ba..87de970 100644
--- a/test/gleam/int_test.gleam
+++ b/test/gleam/int_test.gleam
@@ -415,13 +415,67 @@ pub fn random_test() {
pub fn divide_test() {
int.divide(1, 1)
|> should.equal(Ok(1))
+
int.divide(1, 0)
|> should.equal(Error(Nil))
int.divide(0, by: 1)
|> should.equal(Ok(0))
+
int.divide(1, by: 0)
|> should.equal(Error(Nil))
+
+ int.divide(5, by: 2)
+ |> should.equal(Ok(2))
+
+ int.divide(-99, by: 2)
+ |> should.equal(Ok(-49))
+}
+
+pub fn remainder_test() {
+ int.remainder(3, 2)
+ |> should.equal(Ok(1))
+
+ int.remainder(1, 0)
+ |> should.equal(Error(Nil))
+
+ int.remainder(10, -1)
+ |> should.equal(Ok(0))
+
+ int.remainder(13, by: 3)
+ |> should.equal(Ok(1))
+
+ int.remainder(-13, by: 3)
+ |> should.equal(Ok(-1))
+
+ int.remainder(13, by: -3)
+ |> should.equal(Ok(1))
+
+ int.remainder(-13, by: -3)
+ |> should.equal(Ok(-1))
+}
+
+pub fn modulo_test() {
+ int.modulo(3, 2)
+ |> should.equal(Ok(1))
+
+ int.modulo(1, 0)
+ |> should.equal(Error(Nil))
+
+ int.modulo(10, -1)
+ |> should.equal(Ok(0))
+
+ int.modulo(13, by: 3)
+ |> should.equal(Ok(1))
+
+ int.modulo(-13, by: 3)
+ |> should.equal(Ok(2))
+
+ int.modulo(13, by: -3)
+ |> should.equal(Ok(-2))
+
+ int.modulo(-13, by: -3)
+ |> should.equal(Ok(-1))
}
pub fn floor_divide_test() {