diff --git a/src/Spaces/DiracSpace.jl b/src/Spaces/DiracSpace.jl index e0e10f54..41fdcbe3 100644 --- a/src/Spaces/DiracSpace.jl +++ b/src/Spaces/DiracSpace.jl @@ -30,6 +30,8 @@ for TYP in (:DiracSpace,:PointSpace) spacescompatible(a::$TYP,b::$TYP) = a.points == b.points canonicalspace(a::$TYP) = a + Base.hash(a::$TYP, h::UInt) = hash(a.points, hash($TYP, h)) + union_rule(a::$TYP,b::$TYP) = $TYP(sort(union(a.points,b.points))) function coefficients(cfs::AbstractVector,fromspace::$TYP,tospace::$TYP) diff --git a/test/SpacesTest.jl b/test/SpacesTest.jl index 6c520c1c..e2db7f81 100644 --- a/test/SpacesTest.jl +++ b/test/SpacesTest.jl @@ -213,6 +213,24 @@ using Test f = Fun(PointSpace(1:4), ones(4)) @test ApproxFunBase.isconstantfun(f) end + + @testset "hash" begin + DS = ApproxFunBase.DiracSpace + for T in (PointSpace, DS) + a, b = T(1:2), T(1:2) + @test a == b + @test hash(a) == hash(b) + @test isequal(a, b) + @test length(Set([a, b])) == 1 + @test Dict(a => 1)[b] == 1 + @test Set([T(1:2), T(3:4)]) == Set([T(3:4), T(1:2)]) + @test hash(T(1:2)) != hash(T(3:4)) + @test T([1, 2]) == T([1.0, 2.0]) + @test hash(T([1, 2])) == hash(T([1.0, 2.0])) + end + @test PointSpace(1:2) != DS(1:2) + @test hash(PointSpace(1:2)) != hash(DS(1:2)) + end end @testset "DiracSpace" begin