Skip to content

Commit

Permalink
Merge pull request #42 from aplavin/master
Browse files Browse the repository at this point in the history
  • Loading branch information
mileslucas authored Aug 31, 2022
2 parents d41d3b1 + cd50384 commit f2fc6ca
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,6 @@ function Base.convert(::Type{T}, c::S) where {T<:AbstractSkyCoords,S<:AbstractSk
end

Base.:(==)(a::T, b::T) where {T<:AbstractSkyCoords} = lon(a) == lon(b) && lat(a) == lat(b)
Base.isapprox(a::ICRSCoords, b::ICRSCoords; kwargs...) = isapprox(SVector(lon(a), lat(a)), SVector(lon(b), lat(b)); kwargs...)
Base.isapprox(a::GalCoords, b::GalCoords; kwargs...) = isapprox(SVector(lon(a), lat(a)), SVector(lon(b), lat(b)); kwargs...)
Base.isapprox(a::FK5Coords{e}, b::FK5Coords{e}; kwargs...) where {e} = isapprox(SVector(lon(a), lat(a)), SVector(lon(b), lat(b)); kwargs...)
29 changes: 23 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ end
@test typeof(c2) === T{Float32}
@test typeof(c3) === T{Float64}
@test typeof(c4) === T{BigFloat}
@test isapprox(lat(c2), lat(c3), rtol = sqrt(eps(Float32)))
@test isapprox(lat(c3), lat(c4), rtol = sqrt(eps(Float64)))
@test isapprox(lon(c2), lon(c3), rtol = sqrt(eps(Float32)))
@test isapprox(lon(c3), lon(c4), rtol = sqrt(eps(Float64)))
@test isapprox(c2, c3, rtol = sqrt(eps(Float32)))
@test isapprox(c3, c4, rtol = sqrt(eps(Float64)))
c6 = convert(T, c5)
@test separation(c3, c6) separation(c6, c3) 1
end
Expand Down Expand Up @@ -145,8 +143,7 @@ end
test_c2 = @inferred offset(c1, sep, pa)
@test test_c2 isa T1
test_c2 = T2(test_c2)
@test lon(test_c2) lon(c2)
@test lat(test_c2) lat(c2)
@test test_c2 c2
end

# specific cases to cover special cases.
Expand Down Expand Up @@ -186,3 +183,23 @@ end
@test setproperties(GalCoords(1, 2), l=3) == GalCoords(3, 2)
@test setproperties(FK5Coords{2000}(1, 2), ra=3) == FK5Coords{2000}(3, 2)
end

@testset "equality" begin
@testset for T in [ICRSCoords, GalCoords, FK5Coords{2000}]
c1 = T(1., 2.)
c2 = T(1., 2.001)
c3 = T{Float32}(1., 2.)
c4 = T{Float32}(1., 2.001)
@test c1 == c1
@test_broken c1 == c3
@test c1 c1
@test c1 c3
@test !(c1 c2)
@test !(c1 c4)
@test c1 c2 rtol=1e-3
@test c1 c4 rtol=1e-3
end

@test_broken (!(ICRSCoords(1, 2) FK5Coords{2000}(1, 2)); true)
@test_broken (!(FK5Coords{2000}(1, 2) FK5Coords{1950}(1, 2)); true)
end

0 comments on commit f2fc6ca

Please sign in to comment.