Skip to content

Commit

Permalink
Test floating-point arrays using isapprox
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Dec 5, 2023
1 parent 6c3d030 commit 923c046
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 @@ -380,22 +380,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

0 comments on commit 923c046

Please sign in to comment.