-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
67 lines (55 loc) · 1.19 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
/* C program to check prime number functionality */
#include <stdio.h>
#include <stdlib.h>
#include "prime.h"
int main(int argc, char *argv[])
{
FILE *inf = NULL, *outf = NULL;
int status = 0, num[5], res[5], ares[5];
if(argc < 2)
{
printf("Usage: %s input.txt expout.txt\n", argv[0]);
}
inf = fopen(argv[1], "r");
if(!inf)
{
printf("Test input missing\n");
}
outf = fopen(argv[2], "r");
if(!inf)
{
printf("Test expected output missing\n");
}
for(int idx = 0; idx < 5; idx++)
{
fscanf(inf, "%d", &num[idx]);
fscanf(outf, "%d", &res[idx]);
ares[idx] = isPrime(num[idx]);
if(ares[idx])
{
printf("%d is a Prime number\n", num[idx]);
}
else
{
printf("%d is not a Prime number\n", num[idx]);
}
if(ares[idx] == res[idx])
{
printf("Test passed\n");
}
else
{
printf("Test failed\n");
status = -1;
}
}
if(inf)
{
fclose(inf);
}
if(outf)
{
fclose(outf);
}
exit(status);
}