From 57e6bead349117417c3b0b0ad4fe1b248197fee5 Mon Sep 17 00:00:00 2001 From: Ravishankar Joshi <21024229+ravibitsgoa@users.noreply.github.com> Date: Tue, 20 Oct 2020 23:06:19 +0530 Subject: [PATCH] Added tests for checked math functions (#37985) --- test/checked.jl | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/checked.jl b/test/checked.jl index bd1467b6425f9..938002cbabcdc 100644 --- a/test/checked.jl +++ b/test/checked.jl @@ -302,6 +302,14 @@ end @test checked_abs(BigInt(1)) == BigInt(1) @test checked_neg(BigInt(-1)) == BigInt(1) @test checked_neg(BigInt(1)) == BigInt(-1) + @test checked_add(BigInt(1), BigInt(1)) == BigInt(2) + @test checked_sub(BigInt(1), BigInt(2)) == BigInt(-1) + @test checked_mul(BigInt(2), BigInt(10)) == BigInt(20) + @test checked_div(BigInt(10), BigInt(2)) == BigInt(5) + @test checked_rem(BigInt(9), BigInt(4)) == BigInt(1) + @test checked_fld(BigInt(10), BigInt(3)) == BigInt(3) + @test checked_mod(BigInt(9), BigInt(4)) == BigInt(1) + @test checked_cld(BigInt(10), BigInt(3)) == BigInt(4) end @testset "Additional tests" begin @@ -334,3 +342,19 @@ end @test_throws OverflowError checked_mul(UInt128(2)^127, UInt128(2)) end + +@testset "Multiple arguments for add, mul" begin + @test checked_add(1, 2, 3) === 6 + @test checked_add(1, 2, 3, 4) === 10 + @test checked_add(1, 2, 3, 4, 5) === 15 + @test checked_add(1, 2, 3, 4, 5, 6) === 21 + @test checked_add(1, 2, 3, 4, 5, 6, 7) === 28 + @test checked_add(1, 2, 3, 4, 5, 6, 7, 8) === 36 + + @test checked_mul(1, 2, 3) === 6 + @test checked_mul(1, 2, 3, 4) === 24 + @test checked_mul(1, 2, 3, 4, 5) === 120 + @test checked_mul(1, 2, 3, 4, 5, 6) === 720 + @test checked_mul(1, 2, 3, 4, 5, 6, 7) === 5040 + @test checked_mul(1, 2, 3, 4, 5, 6, 7, 8) === 40320 +end \ No newline at end of file