about summary refs log tree commit diff stats
path: root/test_contact_list.c
blob: 598e748553c9d6b182942b9442d60323c277486e (plain) (blame)
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
57
58
#include <head-unit.h>
#include "contact_list.h"

static void beforetest(void)
{
    contact_list_clear();
}

static void empty_list_when_none_added(void)
{
    struct contact_list *list = get_contact_list();
    assert_int_equals(0, list->size);
}

static void contains_one_element(void)
{
    contact_list_add("James");
    struct contact_list *list = get_contact_list();
    assert_int_equals(1, list->size);
}

static void first_element_correct(void)
{
    contact_list_add("James");
    struct contact_list *list = get_contact_list();

    assert_string_equals("James", list->contacts[0]);
}

static void contains_two_elements(void)
{
    contact_list_add("James");
    contact_list_add("Dave");
    struct contact_list *list = get_contact_list();

    assert_int_equals(2, list->size);
}

static void first_and_second_elements_correct(void)
{
    contact_list_add("James");
    contact_list_add("Dave");
    struct contact_list *list = get_contact_list();
    
    assert_string_equals("James", list->contacts[0]);
    assert_string_equals("Dave", list->contacts[1]);
}

void register_contact_list_tests(void)
{
    TEST_MODULE("contact_list tests");
    BEFORETEST(beforetest);
    TEST(empty_list_when_none_added);
    TEST(contains_one_element);
    TEST(first_element_correct);
    TEST(contains_two_elements);
    TEST(first_and_second_elements_correct);
}