uCBQN/test/cases/fuzz/hashmap.bqn

45 lines
1.8 KiB
BQN
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

### WHOLE-FILE-TEST
# •HashMap fuzzing
helpers •args
ro helpers.GetRand@
R ro.Range
err ¬helpers.shouldNotError # %ALLOW_CATCH
Test {iter 𝕊 n:
# Global set of keys that might be used
keys (-(0<)¨) (R15 R¨ 1-˜1e6R0) n
# Which keys are currently set, and count
c +´ mask 0 = n R 20+R 10
# Value for key if set
vals ((R)÷ {𝕎𝕩}¨ R10) n
map keys •HashMap(mask/) vals
# Single operations and checks
_er { err ? ! 0𝔽1 𝕩keys ; 1 }
Cnt {𝕊: ! c map.Count@ }
Key {𝕊: ! (mask/keys) map.Keys@ }
Val {𝕊: ! (mask/vals) map.Values@ }
Has { ! (𝕩mask) map.Has 𝕩keys }
Get { 𝕩mask ? ! (𝕩vals) map.Get 𝕩keys ; map.Get _er 𝕩 }
Set { 𝕨 map.Set˜ 𝕩keys vals 𝕨˙(𝕩) mask {c+¬𝕩1}(𝕩) @ }
Del { 𝕩mask ? map.Delete 𝕩keys mask 0(𝕩) c-1 ; map.Delete _er 𝕩 }
Selection { (𝕨1)R·1.5×,𝕨ro.Deal 𝕩 }
RandVal R100
ops Cnt, Has, Get, Del, (Rnvals˙)Set, RandValSet
# Larger sets: argument is number of ops (sometimes overridden)
FullCheck KeyValCnt
Deletes { Del¨ 𝕩 Selection mask }
Restores { vals(Set¨) 𝕩 Selection ¬mask }
RandomOps (R)ops {𝕎𝕩}¨ Rn
RandomSame Rops {𝕎𝕩}¨ Rn
opSets FullCheckDeletesRestoresRandomOpsRandomSame
((R)opSets {𝕎𝕩}¨ R100) iter
}
1e5 Test 1e2
1e4 Test 1e4