aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRobert Attard <robert.attard@mail.mcgill.ca>2022-01-03 18:51:10 -0500
committerGitHub <noreply@github.com>2022-01-03 23:51:10 +0000
commit265c228f4a8f233d863f35df9f8e888918902cdc (patch)
treec7a6a35939625c1096670d927951379f9b625523 /test
parent2c7c5d2a511bd5cb6ed65214790c5a91488dd7e5 (diff)
downloadgleam_stdlib-265c228f4a8f233d863f35df9f8e888918902cdc.tar.gz
gleam_stdlib-265c228f4a8f233d863f35df9f8e888918902cdc.zip
Int.digits & int.undigits
Diffstat (limited to 'test')
-rw-r--r--test/gleam/int_test.gleam34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/gleam/int_test.gleam b/test/gleam/int_test.gleam
index 07832dd..1fbc102 100644
--- a/test/gleam/int_test.gleam
+++ b/test/gleam/int_test.gleam
@@ -282,3 +282,37 @@ pub fn product_test() {
int.product([1, 2, 3])
|> should.equal(6)
}
+
+pub fn digits_test() {
+ int.digits(123, 10)
+ |> should.equal(Ok([1, 2, 3]))
+
+ int.digits(-123, 10)
+ |> should.equal(Ok([-1, -2, -3]))
+
+ int.digits(123, 2)
+ |> should.equal(Ok([1, 1, 1, 1, 0, 1, 1]))
+
+ int.digits(123, 1)
+ |> should.equal(Error(int.InvalidBase))
+}
+
+pub fn undigits_test() {
+ int.undigits([], 10)
+ |> should.equal(Ok(0))
+
+ int.undigits([1, 2, 3], 10)
+ |> should.equal(Ok(123))
+
+ int.undigits([-1, -2, -3], 10)
+ |> should.equal(Ok(-123))
+
+ int.undigits([1, 1, 1, 1, 0, 1, 1], 2)
+ |> should.equal(Ok(123))
+
+ int.undigits([1, 2, 3], 1)
+ |> should.equal(Error(int.InvalidBase))
+
+ int.undigits([1, 1, 2], 2)
+ |> should.equal(Error(int.InvalidBase))
+}