-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
executable file
·57 lines (46 loc) · 1.61 KB
/
main.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
// main.c
/*
* This is a simple program for your custom malloc. Only the most basic cases are tested,
* you are encouraged to add more test cases to ensure your functions work correctly.
* Having everything in this file working does not indicate that you have fully
* completed the assignment. You need to implement everything specified in the brief.
*
* A result of 'done' does NOT indicate that the function works entirely correctly, only that
* the operation did not create fatal errors.
*/
#include "allocator.h"
#include <stdio.h>
#include <unistd.h>
#include <stdbool.h>
int main(int argc, char **argv)
{
int *data,i;
double *ddata;
bool done;
printf("Starting tests...\n");
printf("Basic malloc....");
ddata = (double*) custom_malloc(sizeof(double));
*ddata = 12345.6789;
printf("%s\n",(*ddata)==12345.6789?"'done'":"failed!");
printf("Array malloc....");
data = (int*) custom_malloc(1028*sizeof(int));
for(i = 0; i < 1028; i++) data[i] = i;
done = true;
for(i = 0; i < 1028; i++) done &= (data[i]==i);
printf("%s\n",done?"'done'":"failed!");
printf("Basic free......");
custom_free(ddata);
printf("'done'\n");
printf("Array free......");
custom_free(data);
printf("'done'\n");
printf("Basic realloc...");
ddata = (double*) custom_malloc(sizeof(double));
*ddata = 12345.6789;
double* old = ddata;
ddata = (double*) custom_realloc(ddata,1000*sizeof(double));
done = ((old<ddata)&&((*ddata)==12345.6789));
custom_free(ddata);
printf("%s\n",done?"'done'":"failed!");
return 0;
}