CSE 6341 programming projects - simple test cases
In addition to these simple test cases, it is your responsibility to write many test cases yourself, and test your implementation with them
Project 1
Test case:
int x; int y; x = 3; y = 7;
/* should print the value of y */
print y / x * x + y % x ;
Save in file t.sc; run ./simplec t.sc > t.c and examine t.c: this C program should look something like
#include <stdio.h>
void main(void) {
int x;
int y;
(x=3);
(y=7);
printf("%d\n",(((y/x)*x)+(y%x)));
}
Then run gcc -o t t.c; ./t and observe the value 7 being printed. Use a similar process to run the other test cases listed below.
Test case:
int x_11; int y__; x_11 = 1; y__ = 2; print x_11 + y__;
The produced C program, when compiled and executed, should print 3
Test case:
int x; int y; x = 11; y = 22;
if (x - y) { x = x * 3; { print x + y; } } else {y = y - 1; print y - x; }
The produced C program, when compiled and executed, should print 55
Test case:
int x; int y = 2 + 3; x = 0; print x + y;
The produced C program, when compiled and executed, should print 5
Test case:
int x; x = 123xyz;
Should fail with a parser error. The Unix process exit code should be the same as EXIT_PARSING_ERROR in interpreter.Interpreter (i.e., the integer value 1). To check this process code, do echo $? from the Unix command line after the interpreter exits with an error message.
Test case:
int x = 1; int y = 2; x+3 = y;
Should fail with a parser error; Unix process exit code 1
Test case:
int x; x = 01;
Should fail with a parser error; Unix process exit code 1
Project 2
Test case:
int x; int y; int z; x = 8; y = 2; z = (x+8)*y; print z + 1;
Save in a file t.sc. Run with ./simplec t.sc. Should print 33.
Test case:
int x; int y; int z; read x; ; z=y=x+1; print z+y;
Create a file t.sc with this code. Create a file t.data with the value -17. Running ./simplec t.sc < t.data should print -32
Test case:
Use the same t.sc. Create a file t.bad containing only the string xyz. Running ./simplec t.sc < t.bad should exit with an error message, e.g., ERROR: Could not read x from stdin (or something similar, depending on how your implemented error messages). The Unix process exit code should be the same as EXIT_FAILED_STDIN_READ (i.e., the integer value 4). To check this process code, do echo $? from the Unix command line after the interpreter exits with an error message.
Test case:
int x; int y = 7; x = 3; print y / x * x + y % x ;
Should print 7
Test case:
int x; int y; x = 11; y = 22;
if (x - y) { x = x * 3; { print x + y; } } else {y = y - 1; print y - x; }
Should print 55
Test case:
int x = 1-1; int y; y = 7; print y / x * x + y % x ;
Should exit with an error message, e.g., ERROR: Second operand of / is 0. Unix process exit code should be 3 (i.e., EXIT_DIV_BY_ZERO_ERROR)
Test case:
int x; print x;
Should exit with an error message, e.g., ERROR: Read of uninitialized x. Unix process exit code should be 2 (i.e., EXIT_UNINITIALIZED_VAR_ERROR)
Test case:
int x = 8; int y; y = (x = x+1) + x; print y;
Should print 18
Project 3
Test case:
print (1<2) + (1<=2) + (2>1) + (2>=1) + (2==2) + (1!=2);
Should print 6
Test case:
print 1 < 2 + 3;
Should print 1
Test case:
print -(1<2) + (-1<=2) + (2>1) + (2>=1) + (-2==-2) + (1!=2);
Should print 4
Test case:
print ! ( 10 < 20 ) == 10 >= 20;
Should print 1
Test case:
int x = 1; print x <= 1 && x+1 <= 2;
Should print 1
Test case:
int x; print 0 || 5 || x;
Should print 1
Test case:
int x = 0; while (x < 3) { print x; x = x+1; }
Should print
0
1
2
Project 4
Test case: