hash.glisp 638 B

123456789101112131415161718192021222324252627282930313233
  1. (def h {'a 21 2 5 "c" #c})
  2. ; testing hget
  3. (assert (= 21 (hget h 'a)))
  4. (assert (= 5 (hget h 2)))
  5. (assert (= #c (hget h "c")))
  6. ; default value
  7. (assert (= 0 (hget h 22 0)))
  8. ; testing set
  9. (hset! h #a 3)
  10. (assert (= 3 (hget h #a)))
  11. ; testing confict resolution
  12. ; b and its symbol number have same hash value
  13. (hset! h 'b 13)
  14. (hset! h (symnum 'b) 42)
  15. (assert (= 13 (hget h 'b)))
  16. (assert (= 42 (hget h (symnum 'b))))
  17. ; testing delete
  18. (hdel! h 'a)
  19. ; 'a should be gone
  20. (assert (= 0 (hget h 'a 0)))
  21. (hdel! h (symnum 'b))
  22. ; b should still be in there
  23. (assert (= 13 (hget h 'b)))
  24. (assert (hash? h))
  25. (assert (empty? {}))
  26. (assert (not (empty? h)))