-
Notifications
You must be signed in to change notification settings - Fork 0
/
hput.c
96 lines (82 loc) · 2.85 KB
/
hput.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
/*
* hput.c -- tests hput() function in hash.c
*/
#include "hash.h"
#include "queue-objects.h"
#include "car-functions.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define HASHSIZE 20
int32_t main() {
personq_t *person1, *person2, *person3, *result_person;
carq_t *car1, *car2, *car3, *result_car;
int32_t result_int;
hashtable_t *htp;
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);
*/
/*
* Hash an object into a non-existing hashtable
*/
result_int = hput(htp, car1, car1->plate, sizeof(car1->plate));
if(!result_car) {
fprintf(stderr, "Test Error: 'hput()' should not be able to hash object into a non-existing hashtable\n");
free(car1);
free(car2);
free(car3);
exit(EXIT_FAILURE);
}
/*
* Open a new empty hashtable
*/
htp = hopen(HASHSIZE);
/*
* Now, hash an object into the existing but empty hashtable
*/
result_int = hput(htp, car1, car1->plate, sizeof(car1->plate));
if(result_car) {
fprintf(stderr, "Test Error: 'hput()' should be able to hash object into an existing but empty hashtable\n");
free(car1);
free(car2);
free(car3);
exit(EXIT_FAILURE);
}
/*
* Now, hash another object into the existing and non-empty hashtable
*/
result_int = hput(htp, car2, car2->plate, sizeof(car2->plate));
if(result_car) {
fprintf(stderr, "Test Error: 'hput()' should be able to hash object into an existing and non-empty hashtable\n");
free(car1);
free(car2);
free(car3);
exit(EXIT_FAILURE);
}
/*
* Now, hash a third object into the existing and non-empty hashtable
*/
result_int = hput(htp, car3, car3->plate, sizeof(car3->plate));
if(result_car) {
fprintf(stderr, "Test Error: 'hput()' should be able to hash object into an existing and non-empty hashtable\n");
free(car1);
free(car2);
free(car3);
exit(EXIT_FAILURE);
}
free(car1);
free(car2);
free(car3);
exit(EXIT_SUCCESS);
}