-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue-test.c
More file actions
59 lines (42 loc) · 964 Bytes
/
queue-test.c
File metadata and controls
59 lines (42 loc) · 964 Bytes
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
#include "queue.h"
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
void add_values(Queue *que);
bool verify_values(Queue *que);
int main()
{
// Creates Queue.
Queue *que = queue_create();
// Add values A-Z
add_values(que);
bool ok = false;
//Checks that values are correct.
ok = verify_values(que);
printf("Test the functioning of the queue ... %s\n", ok? "PASS" : "FAIL");
// Destroys Queue.
queue_destroy(que);
return 0;
}
void add_values(Queue *que)
{
unsigned char string[2] = "A";
for (char c = 'A'; c <= 'Z'; c++) {
string[0] = c;
queue_enqueue(que, (unsigned char *) string);
printf("%d\n",queue_size(que));
}
}
bool verify_values(Queue *que)
{
for (char ch = 'A'; ch <= 'Z'; ch++) {
unsigned char *str = queue_dequeue(que);
printf("%d\n",queue_size(que));
if ( *str != ch){
free(str);
return false;
}
free(str);
}
return true;
}