More thorough •HashMap tests
This commit is contained in:
parent
72a9a95819
commit
a22af96b17
@ -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⟩ ≡ ≢𝕩)" % (2‿2‿2⥊1‿2)⊐1‿2
|
!"⊐: Rank of 𝕩 must be at least the cell rank of 𝕨 (2‿2‿2 ≡ ≢𝕨, ⟨2⟩ ≡ ≢𝕩)" % (2‿2‿2⥊1‿2)⊐1‿2
|
||||||
!"⊒: Rank of 𝕩 must be at least the cell rank of 𝕨 (2‿2‿2 ≡ ≢𝕨, ⟨2⟩ ≡ ≢𝕩)" % (2‿2‿2⥊1‿2)⊒1‿2
|
!"⊒: Rank of 𝕩 must be at least the cell rank of 𝕨 (2‿2‿2 ≡ ≢𝕨, ⟨2⟩ ≡ ≢𝕩)" % (2‿2‿2⥊1‿2)⊒1‿2
|
||||||
|
|
||||||
⟨2⟩ %% ("abc"‿"de"‿"fgh" •HashMap ⥊¨↕3).Get "fgh"
|
# hashmap
|
||||||
∞ %% ∞ ("abc"‿"de"‿"fgh" •HashMap ⥊¨↕3).Get "fghi"
|
("abc"‿"de"‿"fgh" •HashMap ⥊¨↕3).Get "fgh" %% ⟨2⟩
|
||||||
3 %% ("abc"‿"de"‿"fgh" •HashMap ⥊¨↕3).Count@
|
∞ ("abc"‿"de"‿"fgh" •HashMap ⥊¨↕3).Get "fghi" %% ∞
|
||||||
"B" %% ("b" ("a"‿"b" •HashMap "A"‿"C").Set "B").Get "b"
|
("abc"‿"de"‿"fgh" •HashMap ⥊¨↕3).Count"xy" %% 3
|
||||||
|
("b" ("a"‿"b" •HashMap "A"‿"C").Set "B").Get "b" %% "B"
|
||||||
|
((•HashMap˜↕4).Set´ 1‿"one").Keys↕2 %% ↕4
|
||||||
|
(((•HashMap˜↕4).Delete 1).Set´ 1‿"one").Keys@ %% 0‿2‿3‿1
|
||||||
|
(((•HashMap˜↕4).Delete 1).Set´ 1‿"one").Values@ %% 0‿2‿3‿"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
42
test/hashmap.bqn
Normal 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<⊣)¨) (R⟜15 R¨ 1-˜1e6⌊∘⋆R⟜0) n
|
||||||
|
# Which keys are currently set, and count
|
||||||
|
c ← +´ mask ← 0 = n R 20+R 10
|
||||||
|
# Value for key if set
|
||||||
|
vals ← ((R⟜≠⊏⊢)⟜⊢‿÷‿⥊‿↕ {𝕎𝕩}¨ R⟜10) 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 ← R∘100
|
||||||
|
ops ← ⟨Cnt, Has, Get, Del, (R∘n⊑vals˙)Set⊢, RandVal⊸Set⟩
|
||||||
|
|
||||||
|
# Larger sets: argument is number of ops (sometimes overridden)
|
||||||
|
FullCheck ← Key∘Val∘Cnt
|
||||||
|
Deletes ← { Del¨ 𝕩 Selection mask }
|
||||||
|
Restores ← { ⊏⟜vals⊸(Set¨) 𝕩 Selection ¬mask }
|
||||||
|
RandomOps ← (R⟜≠⊏⊢)⟜ops {𝕎𝕩}¨ R⟜n
|
||||||
|
RandomSame ← R∘≠⊸⊑∘ops {𝕎𝕩}¨ R⟜n
|
||||||
|
opSets ← FullCheck‿Deletes‿Restores‿RandomOps‿RandomSame
|
||||||
|
((R⟜≠⊏⊢)⟜opSets {𝕎𝕩}¨ R⟜100) iter
|
||||||
|
}
|
||||||
|
|
||||||
|
1e5 Test 1e2
|
||||||
|
1e4 Test 1e4
|
||||||
Loading…
Reference in New Issue
Block a user