-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
81 lines (59 loc) · 1.95 KB
/
test.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
#include <stdio.h>
#include "pager.h"
#include "test.h"
#include "table_operations.h"
#include "sequential_index_file.h"
int test_binary_search() {
/* Write something to page 1 and close the file */
char *filename = "db";
int fd = open_file(filename);
page_t p = get_page(filename, 0);
page_set_pos_beg(p);
char *field_names[3] = {"ID", "Age"};
int field_types[2] = {0, 0};
int field_sizes[2] = {4, 4};
table_t tbl = create_table(filename, field_names, field_types, field_sizes, 2);
tbl->current_page = p;
int i;
int n_records = 1000;
int search_val = 700;
for (i = 0; i < n_records; i++) {
int vals[2] = {i, 432};
if (i == search_val)
insert_record(vals, tbl);
insert_record(vals, tbl);
}
write_page(filename, tbl->current_page);
int found = table_search(tbl, "ID", search_val);
if (found == 1) {
printf("FOUND\n");
}
}
int test_index_file() {
/* Write something to page 1 and close the file */
char *filename = "index_test_table";
delete_file(filename);
int fd = open_file(filename);
page_t p = get_page(filename, 0);
page_set_pos_beg(p);
char *field_names[3] = {"ID", "number", "age"};
int field_types[3] = {0, 0, 0};
int field_sizes[3] = {4, 4, 4};
table_t tbl = create_table(filename, field_names, field_types, field_sizes, 3);
tbl->current_page = p;
int i;
int n_records = 100;
for (i = 0; i < n_records; i++) {
int vals[3] = {i, 432, i};
insert_record(vals, tbl);
}
printf("Records inserted\n");
write_page(filename, tbl->current_page);
printf("Creating index table\n");
delete_file("index_table");
table_t idx_table = create_index_file("index_table", "ID", 0);
//write_page("index_table", idx_table->current_page);
printf("Populating index table\n");
populate_index_file(idx_table, tbl);
print_db(idx_table);
}