Skip to content

Commit

Permalink
Added tests for checked math functions (#37985)
Browse files Browse the repository at this point in the history
  • Loading branch information
ravibitsgoa authored Oct 20, 2020
1 parent 0a1cbec commit 57e6bea
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/checked.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 57e6bea

Please sign in to comment.