More thorough •HashMap tests

This commit is contained in:
Marshall Lochbaum 2023-11-28 20:25:17 -05:00
parent 72a9a95819
commit a22af96b17
2 changed files with 56 additions and 4 deletions

View File

@ -45,7 +45,17 @@ a←(•ParseFloat¨ "1.2"‿"-0"‿"0")∾-⊸⋈0÷0 ⋄ ! (0‿3‿3‿3⊏a)
!"⊐: Rank of 𝕩 must be at least the cell rank of 𝕨 (2‿2‿2 ≡ ≢𝕨, ⟨2⟩ ≡ ≢𝕩)" % (22212)12
!"⊒: Rank of 𝕩 must be at least the cell rank of 𝕨 (2‿2‿2 ≡ ≢𝕨, ⟨2⟩ ≡ ≢𝕩)" % (22212)12
2 %% ("abc""de""fgh" •HashMap ¨3).Get "fgh"
%% ("abc""de""fgh" •HashMap ¨3).Get "fghi"
3 %% ("abc""de""fgh" •HashMap ¨3).Count@
"B" %% ("b" ("a""b" •HashMap "A""C").Set "B").Get "b"
# hashmap
("abc""de""fgh" •HashMap ¨3).Get "fgh" %% 2
("abc""de""fgh" •HashMap ¨3).Get "fghi" %%
("abc""de""fgh" •HashMap ¨3).Count"xy" %% 3
("b" ("a""b" •HashMap "A""C").Set "B").Get "b" %% "B"
((•HashMap˜4).Set´ 1"one").Keys2 %% 4
(((•HashMap˜4).Delete 1).Set´ 1"one").Keys@ %% 0231
(((•HashMap˜4).Delete 1).Set´ 1"one").Values@ %% 023"one"
({𝕩.Set´"xy"}4•HashMap˜0).Count@ %% 1
!"•HashMap: Arguments must be lists (⟨⟩≡≢𝕨, ⟨3⟩≡≢𝕩)" % 'a' •HashMap "str"
!"•HashMap: 𝕨 and 𝕩 must have the same length (4≡≠𝕨, 3≡≠𝕩)" % "stri" •HashMap "str"
!"•HashMap: 𝕨 contained duplicate keys" % "strs" •HashMap "stri"
!"(hashmap).Get: key not found" % ("abc""de""fgh" •HashMap ¨3).Get "fg"
!"(hashmap).Delete: key not found" % ("abc""de""fgh" •HashMap ¨3).Delete 'a'

42
test/hashmap.bqn Normal file
View File

@ -0,0 +1,42 @@
u 100×(•UnixTime+1|100וMonoTime)@
ro •MakeRand •Show u
R ro.Range
err 1 # Run operations that should error
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