Map.k 680 B

12345678910111213141516171819202122232425262728293031
  1. invoke {
  2. import Map from Std
  3. let m = Map<Int,String>()
  4. assert m -> size() == 0
  5. set m[1] = 'one'
  6. set m[2] = 'two'
  7. assert m -> size() == 2
  8. assert m[1] == 'one'
  9. assert m[2] == 'two'
  10. for { i: v } in m {
  11. assert when {
  12. i == 1: v == 'one',
  13. i == 2: v == 'two'
  14. }
  15. }
  16. m -> remove(1)
  17. assert m -> size() == 1
  18. assert m[1]? is Nil
  19. assert not (m -> has(1))
  20. assert m -> has(2)
  21. m -> clear()
  22. assert m -> size() == 0
  23. assert m[2]? is Nil
  24. let m1 = copy(m)
  25. assert m1 is Map<Int,String>
  26. set m1[9] = '9'
  27. assert m1[9] == '9'
  28. assert m[9]? is Nil
  29. assert m -> size() == 0
  30. }