-
Notifications
You must be signed in to change notification settings - Fork 0
/
qapply.c
118 lines (98 loc) · 3.14 KB
/
qapply.c
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
/*
* qapply.c -- tests qapply() function in queue.c
*
*/
#include "queue.h"
#include "queue-objects.h"
#include "car-functions.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
void func0(car_ft *cp) {
char plate[MAXREG];
double price;
int year;
strcpy(plate, "US-8000");
price = 10000;
year = 2016;
change_all(cp, plate, price, year);
}
int32_t main() {
personq_t *person1, *person2, *person3, *result_person;
carq_t *car1, *car2, *car3, *result_car;
int32_t result_int;
queue_t *qp;
char name_person1[] = "Devanshi", name_person2[] = "Robert", name_person3[] = "Edmund";
char plate_car1[] = "US-1000", plate_car2[] = "US-2000", plate_car3[] = "US-3000";
double height_person1 = 6.5, height_person2 = 6.4, height_person3 = 6.1;
double price_car1 = 36000, price_car2 = 38000, price_car3 = 40000;
int age_person1 = 29, age_person2 = 20 , age_person3 = 19;
int year_car1 = 2018, year_car2 = 2019 , year_car3 = 2020;
/*
person1 = make_car(name_person1, age_person1, height_person1);
person2 = make_car(name_person2, age_person2, height_person2);
person3 = make_car(name_person3, age_person3, height_person3);
car1 = make_car(plate_car1, price_car1, year_car1);
car2 = make_car(plate_car2, price_car2, year_car2);
car3 = make_car(plate_car3, price_car3, year_car3);
*/
/*
* Apply function to a non-existing queue
*/
qapply(qp, func0);
/*
* Open a new empty queue
*/
qp = qopen();
/*
* Now, apply function to the existing but empty queue
*/
qapply(qp, func0);
/*
* Put some cars into the queue
*/
qput(qp, car1);
qput(qp, car2);
qput(qp, car3);
/*
* Then, apply function to the existing and non-empty hashtable
*/
qapply(qp, func0);
/*
* Check to see if function application worked on car1 using qsearch() function
*/
result_car = qsearch(qp, compare_plate, plate_car1);
if(result_car) {
fprintf(stderr, "Test Error: Apply function did not work! 'hsearch()' should not be able to find car with the given plate from hashtable\n");
free(car1);
free(car2);
free(car3);
exit(EXIT_FAILURE);
}
/*
* Check to see if function application worked onc car2 using qsearch() function
*/
result_car = qsearch(qp, compare_plate, plate_car2);
if(result_car) {
fprintf(stderr, "Test Error: Apply function did not work! 'qsearch()' should not be able to find car with the given plate from queue\n");
free(car1);
free(car2);
free(car3);
exit(EXIT_FAILURE);
}
/*
* Check to see if function application worked onc car3 using qsearch() function
*/
result_car = qsearch(qp, compare_plate, plate_car3);
if(result_car) {
fprintf(stderr, "Test Error: Apply function did not work! 'qsearch()' should not be able to find car with the given plate from queue\n");
free(car1);
free(car2);
free(car3);
exit(EXIT_FAILURE);
}
free(car1);
free(car2);
free(car3);
exit(EXIT_SUCCESS);
}