sp1d3o

test_set.c

Feb 25th, 2022 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.19 KB | None | 0 0
  1. #include "Test_set.h"
  2.  
  3. int iterate(list_t *list)
  4. {
  5.     if(NULL == list) {
  6.         fprintf(stderr, "You fucked up!\n");
  7.         fflush(stderr);
  8.         return -1;
  9.     }
  10.  
  11.     node_t *temp = list->b_node;
  12.  
  13.     int i = 0;
  14.     while(temp != NULL) {
  15.         temp = temp->next;
  16.         i++;
  17.     }
  18.  
  19.     return i;
  20. }
  21.  
  22. int *convert_array(list_t *list, int *count)
  23. {
  24.     *count = iterate(list);
  25.     if(*count <= 0) {
  26.         fprintf(stderr, "Problem\n");
  27.         fflush(stderr);
  28.         exit(0);
  29.     }
  30.  
  31.     node_t *temp = list->b_node;
  32.  
  33.     int *ret = malloc(sizeof(int) * (*count));
  34.     if(!ret) {
  35.         fprintf(stderr, "Not enough memory or else problem\n");
  36.         fflush(stderr);
  37.         return 0;
  38.     }
  39.  
  40.     for(int i = 0; i < *count; i++) {
  41.         ret[i] = temp->data;
  42.         temp = temp->next;
  43.     }
  44.  
  45.     return ret;
  46. }
  47.  
  48.  
  49. void print_array(int *array, int count)
  50. {
  51.     int i = 0;
  52.     while(i < count) {
  53.         printf("%d\n", array[i++]);
  54.     }
  55. }
  56.  
  57.  
  58.  
  59.  
  60. bool test(list_t *list, int *template, size_t n)
  61. {
  62.     int help;
  63.  
  64.     int *tested = convert_array(list, &help);
  65.  
  66.     print_array(tested, help);
  67.  
  68.     return (memcmp(tested, template, 4 * n) == 0);
  69. }
Add Comment
Please, Sign In to add comment