Skip to content

Commit 2223432

Browse files
committed
add tests for structual_hash, structural_eq, structural_isequal
1 parent e165867 commit 2223432

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/runtests.jl

+19
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,22 @@ SH.@batteries HashEqAsTS2 typesalt = 2
216216
@test hash(HashEqAsTS1(identity, 1)) === 0x486b072c90d60e64
217217
@test hash(HashEqAsTS2(x->5x, 1)) === 0xa4360acf486c15a4
218218
end
219+
220+
mutable struct HashEqErr
221+
a
222+
b
223+
end
224+
Base.hash(::HashEqErr, h::UInt) = error()
225+
Base.isequal(::HashEqErr, ::HashEqErr) = error()
226+
Base.:(==)(::HashEqErr, ::HashEqErr) = error()
227+
228+
@testset "structural hash eq" begin
229+
S = HashEqErr
230+
@test SH.structural_eq(S(1,3), S(1,3))
231+
@test !SH.structural_eq(S(1,NaN), S(1,NaN))
232+
@test SH.structural_isequal(S(1,NaN), S(1,NaN))
233+
@test !SH.structural_isequal(S(2,NaN), S(1,NaN))
234+
@test SH.structural_hash(S(2,NaN), UInt(0)) != SH.structural_hash(S(1,NaN), UInt(0))
235+
@test SH.structural_hash(S(2,NaN), UInt(0)) == SH.structural_hash(S(2,NaN), UInt(0))
236+
@test SH.structural_hash(S(2,NaN), UInt(0)) != SH.structural_hash(S(2,NaN), UInt(1))
237+
end

0 commit comments

Comments
 (0)