From 8e8d5ac2a44b33ba3497a4f4b3e2719376ae01dc Mon Sep 17 00:00:00 2001 From: inoas Date: Mon, 10 Oct 2022 11:55:21 +0200 Subject: port elixir's Integer.floor_div --- test/gleam/int_test.gleam | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/gleam/int_test.gleam b/test/gleam/int_test.gleam index 71c526b..26e36ba 100644 --- a/test/gleam/int_test.gleam +++ b/test/gleam/int_test.gleam @@ -273,7 +273,7 @@ pub fn power_test() { // int.power(-1, 0.5) is equivalent to int.square_root(-1) and should // return an error as an imaginary number would otherwise have to be - // returned + // returned int.power(-1, 0.5) |> should.equal(Error(Nil)) @@ -286,7 +286,7 @@ pub fn power_test() { int.power(0, -1.0) |> should.equal(Error(Nil)) - // Check that a negative base and exponent is fine as long as the + // Check that a negative base and exponent is fine as long as the // exponent is not fractional int.power(-2, -1.0) |> should.equal(Ok(-0.5)) @@ -423,3 +423,26 @@ pub fn divide_test() { int.divide(1, by: 0) |> should.equal(Error(Nil)) } + +pub fn floor_divide_test() { + int.floor_divide(1, 1) + |> should.equal(Ok(1)) + + int.floor_divide(1, 0) + |> should.equal(Error(Nil)) + + int.floor_divide(0, by: 1) + |> should.equal(Ok(0)) + + int.floor_divide(1, by: 0) + |> should.equal(Error(Nil)) + + int.floor_divide(5, by: 2) + |> should.equal(Ok(2)) + + int.floor_divide(6, by: -4) + |> should.equal(Ok(-2)) + + int.floor_divide(-99, by: 2) + |> should.equal(Ok(-50)) +} -- cgit v1.2.3