fb11e647
vrobic
reseau statique a...
|
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
/*
* Copyright (C) 2014 Martine Lenders <mlenders@inf.fu-berlin.de>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
#include <string.h>
#include "embUnit.h"
#include "priority_queue.h"
#include "tests-core.h"
#define Q_LEN (4)
static priority_queue_t q = PRIORITY_QUEUE_INIT;
static priority_queue_node_t qe[Q_LEN];
static void set_up(void)
{
priority_queue_init(&q);
for (unsigned i = 0; i < sizeof(qe)/sizeof(priority_queue_node_t); ++i) {
priority_queue_node_init(&(qe[i]));
}
}
static void test_priority_queue_remove_head_empty(void)
{
priority_queue_t *root = &q;
priority_queue_node_t *res;
res = priority_queue_remove_head(root);
TEST_ASSERT_NULL(res);
}
static void test_priority_queue_remove_head_one(void)
{
priority_queue_t *root = &q;
priority_queue_node_t *elem = &(qe[1]), *res;
elem->data = 62801;
priority_queue_add(root, elem);
res = priority_queue_remove_head(root);
TEST_ASSERT(res == elem);
TEST_ASSERT_EQUAL_INT(62801, res->data);
res = priority_queue_remove_head(root);
TEST_ASSERT_NULL(res);
}
static void test_priority_queue_add_one(void)
{
priority_queue_t *root = &q;
priority_queue_node_t *elem = &(qe[1]);
elem->data = 7317;
elem->priority = 713643658;
priority_queue_add(root, elem);
TEST_ASSERT(root->first == elem);
TEST_ASSERT_EQUAL_INT(7317, root->first->data);
TEST_ASSERT_EQUAL_INT(713643658, root->first->priority);
TEST_ASSERT_NULL(root->first->next);
}
static void test_priority_queue_add_two_equal(void)
{
priority_queue_t *root = &q;
priority_queue_node_t *elem1 = &(qe[1]), *elem2 = &(qe[2]);
elem1->data = 27088;
elem1->priority = 14202;
elem2->data = 4356;
elem2->priority = 14202;
priority_queue_add(root, elem1);
priority_queue_add(root, elem2);
TEST_ASSERT(root->first == elem1);
TEST_ASSERT_EQUAL_INT(27088, root->first->data);
TEST_ASSERT_EQUAL_INT(14202, root->first->priority);
TEST_ASSERT(root->first->next == elem2);
TEST_ASSERT_EQUAL_INT(4356, root->first->next->data);
TEST_ASSERT_EQUAL_INT(14202, root->first->next->priority);
TEST_ASSERT_NULL(root->first->next->next);
}
static void test_priority_queue_add_two_distinct(void)
{
priority_queue_t *root = &q;
priority_queue_node_t *elem1 = &(qe[1]), *elem2 = &(qe[2]);
elem1->data = 46421;
elem1->priority = 4567;
elem2->data = 43088;
elem2->priority = 1234;
priority_queue_add(root, elem1);
priority_queue_add(root, elem2);
TEST_ASSERT(root->first == elem2);
TEST_ASSERT_EQUAL_INT(43088, root->first->data);
TEST_ASSERT_EQUAL_INT(1234, root->first->priority);
TEST_ASSERT(root->first->next == elem1);
TEST_ASSERT_EQUAL_INT(46421, root->first->next->data);
TEST_ASSERT_EQUAL_INT(4567, root->first->next->priority);
TEST_ASSERT_NULL(root->first->next->next);
}
static void test_priority_queue_remove_one(void)
{
priority_queue_t *root = &q;
priority_queue_node_t *elem1 = &(qe[1]), *elem2 = &(qe[2]), *elem3 = &(qe[3]);
priority_queue_add(root, elem1);
priority_queue_add(root, elem2);
priority_queue_add(root, elem3);
priority_queue_remove(root, elem2);
TEST_ASSERT(root->first == elem1);
TEST_ASSERT(root->first->next == elem3);
TEST_ASSERT_NULL(root->first->next->next);
}
Test *tests_core_priority_queue_tests(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(test_priority_queue_remove_head_empty),
new_TestFixture(test_priority_queue_remove_head_one),
new_TestFixture(test_priority_queue_add_one),
new_TestFixture(test_priority_queue_add_two_equal),
new_TestFixture(test_priority_queue_add_two_distinct),
new_TestFixture(test_priority_queue_remove_one),
};
EMB_UNIT_TESTCALLER(core_priority_queue_tests, set_up, NULL,
fixtures);
return (Test *)&core_priority_queue_tests;
}
|