-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.c
54 lines (44 loc) · 1.36 KB
/
driver.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
#include <stdio.h>
#include "hash.h"
#include <string.h>
#include <assert.h>
int main(int argc, char *argv[])
{
hash_t *ht = newHashTable(1);
add(ht, "Rusty", "Davis");
char *name = lookup(ht, "Rusty");
assert(strcmp(name, "Davis") == 0);
assert(ht->keys == 1);
assert(ht->capacity == 1);
add(ht, "Kanye", "West");
name = lookup(ht, "Kanye");
assert(strcmp(name, "West") == 0);
assert(ht->keys == 2);
assert(ht->capacity == 2);
add(ht, "Taylor", "Swift");
name = lookup(ht, "Taylor");
assert(strcmp(name, "Swift") == 0);
assert(ht->keys == 3);
assert(ht->capacity == 4);
add(ht, "Kendrick", "Lamar");
name = lookup(ht, "Kendrick");
assert(strcmp(name, "Lamar") == 0);
assert(ht->keys == 4);
add(ht, "John", "Coltrane");
name = lookup(ht, "John");
assert(strcmp(name, "Coltrane") == 0);
assert(ht->keys == 5);
assert(ht->capacity == 8);
add(ht, "Miles", "Davis");
name = lookup(ht, "Miles");
assert(strcmp(name, "Davis") == 0);
assert(ht->keys == 6);
add(ht, "Stannis", "Baratheon");
name = lookup(ht, "Stannis");
assert(strcmp(name, "Baratheon") == 0);
assert(ht->keys == 7);
printf("Keys: %d Capacity: %d\n", ht->keys, ht->capacity);
printf("Load %f", (ht->keys*1.0) / ht->capacity);
destroyHashTable(ht);
return 0;
}