Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,21 @@ using .ExampleInts: ExampleInt
for t ∈ (
(-1,), (-1, 1), (1, -1), (0, -1), (-1, 0), (-1, -1),
(-1, typemax(Int)), (typemax(Int), -1),
(0, -4, -4), (-4, 1, 0), (-4, -4, 1),
)
@test (checked_size_product(t)).any_is_negative
s = map(ExampleInt, t)
@test (checked_size_product(s)).any_is_negative
end
end
@testset "input includes `typemax(T)`" begin
# Why is `typemax(T)` even disallowed:
#
# > Yes, I specifically wanted maxdim+1 to be representable, since
# > otherwise other off-by-one math representations become much harder,
# > and that makes boundschecking slower.
#
# https://github.com/JuliaLang/julia/pull/54255#pullrequestreview-2024051188
m = typemax(Int)
for t ∈ (
(m,), (m, m), (1, m), (m, 1), (0, m), (m, 0), (-1, m), (m, -1),
Expand All @@ -93,8 +101,10 @@ using .ExampleInts: ExampleInt
end
@testset "overflows" begin
m = typemax(Int) ÷ 13
b = (Int == Int64) ? 2^32 : 2^16
for t ∈ (
(m, m), (15, m), (m, 15), (m, m, m), (1, m, m), (m, 1, m), (m, m, 1),
(b, b), (1, b, b),
)
@test !(checked_size_product(t)).any_is_negative
@test !(checked_size_product(t)).any_is_typemax
Expand All @@ -105,8 +115,10 @@ using .ExampleInts: ExampleInt
end
@testset "overflows, but OK because of multiplication with zero" begin
m = typemax(Int) ÷ 13
b = (Int == Int64) ? 2^32 : 2^16
for t ∈ (
(m, m, 0), (m, 0, m), (0, m, m),
(0, b, b), (b, b, 0), (b, b, 0, b, b),
)
@test 0 === checked_size_product(t)
s = map(ExampleInt, t)
Expand Down
Loading