Skip to content

Commit

Permalink
adapt some array construction tests from Julia's test suite (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsajko authored Jan 17, 2025
1 parent a241c48 commit 2d94538
Showing 1 changed file with 12 additions and 0 deletions.
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

0 comments on commit 2d94538

Please sign in to comment.