test_vec.c 552 B

1234567891011121314151617181920212223242526
  1. #include <assert.h>
  2. #include <stdio.h>
  3. #include "vec.h"
  4. #include "gc_prelude.h"
  5. int main() {
  6. void *v = new_vec();
  7. double *n = malloc(sizeof(double));
  8. *n = 42.42;
  9. vec_push_back(v, n);
  10. assert(*(double*)vec_get(v, 0) == 42.42);
  11. v = new_vec();
  12. for (int i = 0; i < 10000; i++) {
  13. int *x = malloc(sizeof(int));
  14. *x = i;
  15. vec_push_back(v, x);
  16. assert(vec_size(v) == i + 1);
  17. }
  18. for (int i = 0; i < 10000; i++) {
  19. assert(*(int*)vec_get(v, i) == i);
  20. }
  21. printf("[PASSED] vec\n");
  22. }