Skip to content

Commit

Permalink
Delete for now the low-level implementation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Nov 20, 2023
1 parent 3166eca commit 4581d0d
Showing 1 changed file with 0 additions and 56 deletions.
56 changes: 0 additions & 56 deletions test/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1084,15 +1084,6 @@ Dict(1 => rand(2,3), 'c' => "asdf") # just make sure this does not trigger a dep
GC.@preserve A B C D nothing
end

mutable struct CollidingHash
end
Base.hash(::CollidingHash, h::UInt) = hash(UInt(0), h)

struct PredictableHash
x::UInt
end
Base.hash(x::PredictableHash, h::UInt) = x.x

import Base.PersistentDict
@testset "PersistentDict" begin
@testset "basics" begin
Expand Down Expand Up @@ -1179,53 +1170,6 @@ import Base.PersistentDict
end
@test isempty(dict)
end

@testset "CollidingHash" begin
dict = PersistentDict{CollidingHash, Nothing}()
dict = PersistentDict(dict, CollidingHash(), nothing)
@test_throws ErrorException PersistentDict(dict, CollidingHash(), nothing)
end

# Test the internal implementation
@testset "PredictableHash" begin
dict = PersistentDict{PredictableHash, Nothing}()
for i in 1:Base.HashArrayMappedTries.ENTRY_COUNT
key = PredictableHash(UInt(i-1)) # Level 0
dict = PersistentDict(dict, key, nothing)
end
@test length(dict.trie.data) == Base.HashArrayMappedTries.ENTRY_COUNT
@test dict.trie.bitmap == typemax(Base.HashArrayMappedTries.BITMAP)
for entry in dict.trie.data
@test entry isa Base.HashArrayMappedTries.Leaf
end

dict = PersistentDict{PredictableHash, Nothing}()
for i in 1:Base.HashArrayMappedTries.ENTRY_COUNT
key = PredictableHash(UInt(i-1) << Base.HashArrayMappedTries.BITS_PER_LEVEL) # Level 1
dict = PersistentDict(dict, key, nothing)
end
@test length(dict.trie.data) == 1
@test length(dict.trie.data[1].data) == 32

max_level = (Base.HashArrayMappedTries.NBITS ÷ Base.HashArrayMappedTries.BITS_PER_LEVEL)
dict = PersistentDict{PredictableHash, Nothing}()
for i in 1:Base.Base.HashArrayMappedTries.ENTRY_COUNT
key = PredictableHash(UInt(i-1) << (max_level * Base.HashArrayMappedTries.BITS_PER_LEVEL)) # Level 12
dict = PersistentDict(dict, key, nothing)
end
data = dict.trie.data
for level in 1:max_level
@test length(data) == 1
data = only(data).data
end
last_level_nbits = Base.HashArrayMappedTries.NBITS - (max_level * Base.HashArrayMappedTries.BITS_PER_LEVEL)
if Base.HashArrayMappedTries.NBITS == 64
@test last_level_nbits == 4
elseif Base.HashArrayMappedTries.NBITS == 32
@test last_level_nbits == 2
end
@test length(data) == 2^last_level_nbits
end
end

@testset "issue #19995, hash of dicts" begin
Expand Down

0 comments on commit 4581d0d

Please sign in to comment.