Skip to content

Commit

Permalink
Test floating-point arrays using isapprox (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub authored Apr 3, 2024
1 parent f174c7b commit 002f56c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -378,22 +378,22 @@ end
# type, and produce numerically correct results.
as_array(x::AbstractArray) = Array(x)
as_array(x::UniformScaling) = x
equal_or_undef(a::Number, b::Number) = (a == b) || isequal(a, b)
equal_or_undef(a, b) = all(equal_or_undef.(a, b))
isapprox_or_undef(a::Number, b::Number) = (a b) || isequal(a, b)
isapprox_or_undef(a, b) = all(((x,y),) -> isapprox_or_undef(x,y), zip(a, b))
function test_addition_subtraction_dot(As, Bs, Tout::Type)
for A in As, B in Bs
@testset "$(typeof(A)) and $(typeof(B))" begin
@test @inferred(A + B) isa Tout{promote_type(eltype(A), eltype(B))}
@test equal_or_undef(as_array(A + B), as_array(A) + as_array(B))
@test isapprox_or_undef(as_array(A + B), as_array(A) + as_array(B))

@test @inferred(A - B) isa Tout{promote_type(eltype(A), eltype(B))}
@test equal_or_undef(as_array(A - B), as_array(A) - as_array(B))
@test isapprox_or_undef(as_array(A - B), as_array(A) - as_array(B))

@test @inferred(B + A) isa Tout{promote_type(eltype(B), eltype(A))}
@test equal_or_undef(as_array(B + A), as_array(B) + as_array(A))
@test isapprox_or_undef(as_array(B + A), as_array(B) + as_array(A))

@test @inferred(B - A) isa Tout{promote_type(eltype(B), eltype(A))}
@test equal_or_undef(as_array(B - A), as_array(B) - as_array(A))
@test isapprox_or_undef(as_array(B - A), as_array(B) - as_array(A))

# Julia 1.6 doesn't support dot(UniformScaling)
if VERSION < v"1.6.0" || VERSION >= v"1.8.0"
Expand Down

2 comments on commit 002f56c

@jishnub
Copy link
Member Author

@jishnub jishnub commented on 002f56c Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/104143

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.10.0 -m "<description of version>" 002f56c7562badc7c6bce8d58637f02799b537fa
git push origin v1.10.0

Please sign in to comment.