Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
antony-frolov committed Mar 3, 2022
1 parent 1bad79b commit 2d869af
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/add1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char *argv[]){
int a;
scanf("%d", &a);
int n = atoi(argv[1]);
n = n + 1 + a;
printf("%d\n",n);
return 0;
}
6 changes: 6 additions & 0 deletions tests/error_prog.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <stdlib.h>

int main() {
exit(1);
return 0;
}
6 changes: 6 additions & 0 deletions tests/ok_prog.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <stdlib.h>

int main() {
exit(0);
return 0;
}
19 changes: 19 additions & 0 deletions tests/test1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#define MAX_STR_LEN 100
int main(int argc, char *argv[]) {
// FILE *my_file = fopen("output1.txt", "w");
int console_arg = atoi(argv[1]);
char input_str[MAX_STR_LEN];
read(0, input_str, MAX_STR_LEN);
fprintf(my_file, "%s\n", input_str);
int input_arg = atoi(input_str);
input_arg += 1;
input_arg += console_arg;
char output_str[MAX_STR_LEN];
sprintf(output_str, "%d\n", input_arg);
write(1, output_str, strlen(output_str));
return 0;
}
22 changes: 22 additions & 0 deletions tests/test2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#define MAX_STR_LEN 100
int main(int argc, char *argv[]) {
FILE *my_file = fopen("output2.txt", "w");
int console_arg = atoi(argv[1]);
char input_str[MAX_STR_LEN];
read(0, input_str, MAX_STR_LEN);
int input_arg = atoi(input_str);
input_arg += 2;
input_arg += console_arg;
char output_str[MAX_STR_LEN];
sprintf(output_str, "%d\n", input_arg);
// printf("%d", input_arg);
fprintf(my_file, "%s\n", output_str);
write(1, output_str, strlen(output_str));
// char my_eof = EOF;
// write(1, &my_eof, 1);
return 0;
}

0 comments on commit 2d869af

Please sign in to comment.