test_map.c 665 B

123456789101112131415161718192021222324252627282930313233
  1. #include "map.h"
  2. #include <assert.h>
  3. #include <stdio.h>
  4. #include "gc_prelude.h"
  5. int main() {
  6. void *dict = new_dict();
  7. int *i = malloc(sizeof(int));
  8. *i = 1;
  9. dict_set(dict, "1", i);
  10. i = malloc(sizeof(int));
  11. *i = 2;
  12. dict_set(dict, "2", i);
  13. i = malloc(sizeof(int));
  14. *i = 3;
  15. dict_set(dict, "3", i);
  16. i = malloc(sizeof(int));
  17. *i = 4;
  18. dict_set(dict, "4", i);
  19. assert(*(int*)dict_get(dict, "3") == 3);
  20. void *iter = dict_begin(dict);
  21. for (int i = 1; i <= 4; i++) {
  22. assert(*(int*)dict_iter_value(iter) == i);
  23. iter = dict_next(dict, iter);
  24. }
  25. printf("[PASSED] map\n");
  26. return 0;
  27. }