-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_queue_qremove.c
More file actions
77 lines (69 loc) · 1.82 KB
/
test_queue_qremove.c
File metadata and controls
77 lines (69 loc) · 1.82 KB
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
/*
* tests takong stuff out of the queue
* - puts 5 person into the queue
* - searches for one of them by age
* - also tests the case where only one person is in the queue
* module 3
*/
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include "time.h"
#include "queue.h"
#define MAXNM 128
typedef struct person {
char name[MAXNM];
int age;
double rate;
} person_t;
bool search_fun(void *element, const void* search){
person_t *e = (person_t *)element;
person_t *s = (person_t *)search;
if (e->age == s->age){
return true;
}
return false;
}
int main(void) {
queue_t *qp2 = qopen();
queue_t *qp = qopen();
person_t person1 = {"stjepan", 21, 5};
person_t person2 = {"allen", 22, 5};
person_t person3 = {"joe", 23, 5};
person_t person4 = {"selim", 24, 5};
person_t person5 = {"musab", 25, 5};
if (qput(qp, (void *)&person1) != 0){
exit(EXIT_FAILURE);
}
if (qput(qp2, (void *)&person1) != 0){
exit(EXIT_FAILURE);
}
if (qput(qp, (void *)&person2) != 0){
exit(EXIT_FAILURE);
}
if (qput(qp, (void *)&person3) != 0){
exit(EXIT_FAILURE);
}
if (qput(qp, (void *)&person4) != 0){
exit(EXIT_FAILURE);
}
if (qput(qp, (void *)&person5) != 0){
exit(EXIT_FAILURE);
}
person_t search2 = {"aaaa", 21, 5};
person_t *stjepan = (person_t *)qremove(qp2, &search_fun, &search2);
if (stjepan != NULL && stjepan->age != 21){
exit(EXIT_FAILURE);
}
person_t search = {"aaaa", 23, 5};
person_t *joe = (person_t *)qremove(qp, &search_fun, &search);
if (joe != NULL && joe->age != 23){
exit(EXIT_FAILURE);
}
printf("success");
qclose(qp2);
qclose(qp);
exit(EXIT_SUCCESS);
}