1
0

map_test.g 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # This file is part of asmc, a bootstrapping OS with minimal seed
  2. # Copyright (C) 2018 Giovanni Mascellani <gio@debian.org>
  3. # https://gitlab.com/giomasce/asmc
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. fun map_test_print_closure 3 {
  15. $ctx
  16. $key
  17. $value
  18. @ctx 2 param = ;
  19. @key 1 param = ;
  20. @value 0 param = ;
  21. ctx key map_has ! "map_test_print_closure: value already seen" assert_msg ;
  22. ctx key value map_set ;
  23. }
  24. fun map_test_print_closure2 3 {
  25. $ctx
  26. $key
  27. $value
  28. @ctx 2 param = ;
  29. @key 1 param = ;
  30. @value 0 param = ;
  31. ctx key map_has "map_test_print_closure2: value not seen" assert_msg ;
  32. }
  33. fun map_test 0 {
  34. $map
  35. @map map_init = ;
  36. $elem_num
  37. @elem_num 1000 = ;
  38. $i
  39. @i 0 = ;
  40. while i elem_num < {
  41. map i itoa i map_set ;
  42. @i i 1 + = ;
  43. }
  44. $check_map
  45. @check_map map_init = ;
  46. map @map_test_print_closure check_map map_foreach ;
  47. map @map_test_print_closure2 check_map map_foreach ;
  48. map map_size elem_num == "map_test: size unexpected after inserting" assert_msg ;
  49. check_map map_size elem_num == "map_test: check size unexpected after inserting" assert_msg ;
  50. check_map map_destroy ;
  51. @check_map map_init = ;
  52. @i 0 = ;
  53. while i elem_num < {
  54. map i itoa i map_set ;
  55. @i i 1 + = ;
  56. }
  57. map @map_test_print_closure check_map map_foreach ;
  58. map @map_test_print_closure2 check_map map_foreach ;
  59. map map_size elem_num == "map_test: size unexpected after reinserting" assert_msg ;
  60. check_map map_size elem_num == "map_test: check size unexpected after reinserting" assert_msg ;
  61. check_map map_destroy ;
  62. @check_map map_init = ;
  63. @i 1 = ;
  64. while i elem_num < {
  65. map i itoa map_erase ;
  66. @i i 2 + = ;
  67. }
  68. map @map_test_print_closure check_map map_foreach ;
  69. map @map_test_print_closure2 check_map map_foreach ;
  70. map map_size elem_num 2 / == "map_test: size unexpected after removing" assert_msg ;
  71. check_map map_size elem_num 2 / == "map_test: check size unexpected after removing" assert_msg ;
  72. check_map map_destroy ;
  73. map map_destroy ;
  74. "Map tests successfully passed!\n" log ;
  75. }