Research portable Memory game | Исследовать портируемую игру Память
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.9KB

  1. #include <assert.h>
  2. #include <stddef.h> /* size_t, NULL */
  3. #include "utstack.h"
  4. typedef struct el {
  5. int id, score;
  6. struct el *next;
  7. struct el *next2;
  8. } el;
  9. int main()
  10. {
  11. el alpha = {1, 100, NULL, NULL};
  12. el beta = {2, 100, NULL, NULL};
  13. el gamma = {3, 100, NULL, NULL};
  14. el delta = {4, 100, NULL, NULL};
  15. el *stack1 = NULL;
  16. el *stack2 = NULL;
  17. el *dummy;
  18. int size1;
  19. size_t size2;
  20. STACK_COUNT(stack1, dummy, size1); assert(size1 == 0);
  21. STACK_COUNT(stack2, dummy, size2); assert(size2 == 0);
  22. assert(STACK_EMPTY(stack1));
  23. assert(STACK_EMPTY(stack2));
  24. STACK_PUSH(stack1, &alpha);
  25. STACK_COUNT(stack1, dummy, size1); assert(size1 == 1);
  26. STACK_PUSH(stack1, &beta);
  27. STACK_COUNT(stack1, dummy, size1); assert(size1 == 2);
  28. STACK_PUSH(stack1, &gamma);
  29. STACK_PUSH2(stack1, &delta, next);
  30. STACK_COUNT(stack1, dummy, size1); assert(size1 == 4);
  31. assert(stack1 == &delta);
  32. STACK_PUSH2(stack2, &alpha, next2);
  33. assert(stack2 == &alpha);
  34. assert(alpha.next2 == NULL);
  35. STACK_PUSH2(stack2, &delta, next2);
  36. assert(stack2 == &delta);
  37. assert(delta.next2 == &alpha);
  38. STACK_COUNT2(stack2, dummy, size2, next2); assert(size2 == 2);
  39. assert(!STACK_EMPTY(stack2));
  40. assert(stack2 == &delta);
  41. assert(!STACK_EMPTY(stack1));
  42. assert(!STACK_EMPTY(stack2));
  43. STACK_POP(stack1, dummy); assert(stack1 == &gamma); assert(dummy == &delta);
  44. STACK_POP(stack1, dummy); assert(stack1 == &beta); assert(dummy == &gamma);
  45. STACK_POP(stack1, dummy); assert(stack1 == &alpha); assert(dummy == &beta);
  46. STACK_COUNT(stack1, dummy, size1); assert(size1 == 1);
  47. STACK_POP(stack1, dummy); assert(stack1 == NULL); assert(dummy == &alpha);
  48. assert(STACK_TOP(stack2) == &delta);
  49. while (!STACK_EMPTY(stack2)) {
  50. STACK_POP2(stack2, dummy, next2);
  51. }
  52. assert(STACK_EMPTY(stack1));
  53. assert(STACK_EMPTY(stack2));
  54. return 0;
  55. }