-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDBHashTableTests.c
executable file
·113 lines (83 loc) · 1.9 KB
/
DBHashTableTests.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
//
// DBHashTableTests.c
//
//
// Created by C.R.Leedham-Green on 25/05/2017.
//
//
#include "DBInputs.h"
void DBHashIOTest(int degree);
void randomDB(DataBase* db_ptr, int degree);
void randomDB(DataBase* db_ptr, int degree)
{
initialiseDataBase(db_ptr, degree);
int a;
int b;
int c;
int d;
int i;
srand(7);
for (i = 0; i < 6; i++)
{
a = rand() % degree;
do
{
b = rand() % degree;
}
while (a == b);
c = rand() % degree;
do
{
d = rand() % degree;
}
while (c == d);
printf("a = %d, b = %d, c = %d, d = %d\n",a,b,c,d);
writeInLocal(a,b,c,d,*db_ptr,degree);
}
printf("a = %d / b = %d / c = %d / d = %d\n"a,b,c,d);
if (! greaterImplies(a,b,c,d,db_ptr,degree))
writeInGlobal(a,b,*db_ptr,degree);
}
void DBHashIOTest(int degree)
{
FILE *fp;
int i;
//PermSet ps;
DataBase db;
DBHashTable* ht_ptr;
DBHashTable* kt_ptr;
initialiseDataBase(&db,degree);
ht_ptr = initialiseDBHashTable(5);
kt_ptr = initialiseDBHashTable(5);
for (i = 0; i < 15; i++)
{
randomDB(&db, degree);
// printf("\nINSERT\n");
ht_ptr = insertDBHashTable(ht_ptr, db, degree);
}
fp = fopen("TestIO", "w");
fprintDBHashTable(ht_ptr,degree,fp);
fclose(fp);
printf("\n Wrote Hash table");
fp = fopen("TestIO", "r");
kt_ptr = freadDBHashTable(kt_ptr, degree, fp);
fclose(fp);
printf("\n Read Hash table");
printDBHashTable(*kt_ptr, degree);
printf("Test complete.\n");
}
void randomTest()
{
int degree = 6;
DataBase db;
randomDB(&db, degree);
writeDataBase(db,degree);
}
int main()
{
DataBase db;
int degree = 6;
// randomDB(&db,degree);
// DBHashIOTest(degree);
randomTest();
}