aboutsummaryrefslogtreecommitdiff
path: root/list/test/list_test.c
blob: a11c713eaa072dea90cfe305660ccdf0b8683579 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "list.h"

#include "test.h"

#define TEST_LIST_SIZE 10

// Create an empty list.
TEST_CASE(list_create_empty) { list_make(0, 0); }

// Create a list of a given size.
TEST_CASE(list_create) {
  struct list list[TEST_LIST_SIZE];
  list_make(list, TEST_LIST_SIZE);
}

// Iterate over a list.
TEST_CASE(list_traverse) {
  int numbers[TEST_LIST_SIZE] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

  struct list list[TEST_LIST_SIZE];
  list_make(list, TEST_LIST_SIZE);

  int count = 0;
  int sum = 0;
  list_foreach(list, item) {
    count++;
    sum += numbers[item - list];
  }

  TEST_EQUAL(count, TEST_LIST_SIZE);
  TEST_EQUAL(sum, TEST_LIST_SIZE * (TEST_LIST_SIZE + 1) / 2);
}

int main() { return 0; }