summaryrefslogtreecommitdiff
path: root/test/test-list.c
blob: 7871286ae008871edd496df50704bf5cb4fb178f (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdbool.h>
#include <stdio.h>
#include <string.h>

#include "testutils.h"

void test_add_remove(void);
void test_contains_all_true(void);

void test_add_remove(void)
{
	struct list* list = list_new();
	
	char s[] = "hello"; 
	
	/* add element */
	list_add(list, s);
	assert(strcmp(list->head->data, "hello") == 0);
	assert(list->size == 1);
	
	/* remove element */
	bool found = list_remove(list, s);
	assert(found == true);
	assert(list->size == 0);
	assert(list->head == NULL);
	
	list_destroy(list);
}

void test_contains_all_true(void)
{
	struct list* superList = list_new();
	struct list* subList = list_new();
	
	list_add(superList, (void*) "hello");
	list_add(superList, (void*) "world");
	
	list_add(subList,   (void*) "hello");
	
	bool b = list_contains_all(superList, subList, (comparator) strcmp);
	assert(b == true);
	assert(superList->size == 2);
	assert(superList->head->next->next == NULL);
		
	list_destroy(superList);
	list_destroy(subList);
}

int main(void)
{
	test_add_remove();
	test_contains_all_true();
	//test_different_size_lists();
	
	printf("PASS\n");
}