-
Notifications
You must be signed in to change notification settings - Fork 0
/
testVerificator.c
111 lines (100 loc) · 2.04 KB
/
testVerificator.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
#include<stdio.h>
#include<stdlib.h>
#define OUTPUT "output"
#define TEST_OUPUT1 "test/open_tests/output_1"
#define TEST_OUPUT2 "test/open_tests/output_2"
#define TEST_OUPUT3 "test/open_tests/output_3"
#define TEST_OUPUT4 "test/open_tests/output_4"
#define TEST_OUPUT5 "test/open_tests/output_5"
#define TEST_OUPUT6 "test/open_tests/output_6"
typedef struct _list{
int val;
struct _list *next;
}list;
list *append(list *head, int val){
list *new;
if((new = (list *)malloc(sizeof(list)))){
new -> val = val;
new ->next = NULL;
if(head==NULL){
head = new;
}
else{
list *ptr;
for(ptr = head; ptr->next; ptr = ptr ->next);
ptr->next = new;
}
}
else{
printf("MEMORY ERROR: ABORT\n");
return NULL;
}
return head;
}
list *findAndRemove(list *head, int val){
list *prev = NULL;
for(list *ptr = head; ptr; ptr= ptr->next){
if(ptr->val == val){
if(prev == NULL)
head = head->next;
else{
prev->next = ptr->next;
free(ptr);
}
return head;
}
prev = ptr;
}
printf("TEST NOT SUCCESSFULL\n");
return NULL;
}
list *getTestOutput(char *fileName){
FILE *output;
list *head = NULL;
int val;
int tmp;
if((output = fopen(fileName, "r"))){
tmp = fscanf(output, "%d", &val);
while(!feof(output)){
head = append(head, val);
tmp = fscanf(output, "%d", &val);
}
fclose(output);
if(tmp)
;
}
else
printf("ERROR OPENING %s\n", fileName);
//for(list *ptr = head; ptr; ptr=ptr->next)
// printf("%d ", ptr->val);
//printf("\n");
return head;
}
int main(int argc, char *argv[])
{
FILE *output;
int val;
list *test = getTestOutput(argv[1]);
int tmp;
printf("START TESTER\n");
if((output = fopen(OUTPUT, "r"))){
tmp=fscanf(output, "%d", &val);
while(!feof(output)){
//printf("%d ", val);
test = findAndRemove(test, val);
tmp=fscanf(output, "%d", &val);
if(test==NULL && !feof(output)){
printf("TEST FAILED\n");
return 0;
}
}
fclose(output);
printf("TEST SUCCESSFULLY PASSED\n");
if(tmp)
;
}
else{
printf("ERROR OPENING %s\n", OUTPUT);
}
return 0;
}