-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting_the_tests
73 lines (60 loc) · 2.07 KB
/
testing_the_tests
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
/* This program takes an output file that is based on some tests that have
been run on an imaginary program. The imaginary program takes an integer
input and a string and then based on the integer either reverses the string
(input of 0) or capitalizes the string (input of 1). Our job is to write
a program which evaluates the test data being given the initial input
integer, the original string, and the output generated by the imaginary
program*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAXLEN 15
int str_reverse(char original_string[], char output_string[]);
int str_capital(char original_string[], char output_string[]);
int main(int argc, char *argv[])
{
FILE *fp;
int test_num, test_case, i;
char original_string[MAXLEN], output_string[MAXLEN];
/*Opens the file specified by the command line argument */
fp = fopen(argv[1], "r");
fscanf(fp, "%d", &test_num);
for(i = 0; i < test_num; i++){
fscanf(fp, "%d %s %s\n", &test_case, original_string
,output_string);
if(test_case == 0){
if(!str_reverse(original_string,output_string)){
printf("Data is good\n");
continue;
}
}
if(test_case == 1){
if(!str_capital(original_string, output_string)){
printf("Data is good\n");
continue;
}
}
printf("Data doesn't match!\n");
}
return 0;
}
int str_reverse(char original_string[], char output_string[])
{
int j, iter_rev = strlen(original_string);
char new_string[MAXLEN];
for(j = 0; j < iter_rev; j++)
{
new_string[j] = original_string[iter_rev - (j+1)];
}
new_string[j] = '\0';
return strcmp(new_string, output_string);
}
int str_capital(char original_string[], char output_string[])
{
int k, iter_cap = strlen(original_string);
for(k = 0; k < iter_cap; k++){
original_string[k] = toupper(original_string[k]);
}
return strcmp(original_string, output_string);
}