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 = 1; int y; y = x; should pass type checking and should exit with exit code 0 (i.e., Interpreter.EXIT_SUCCESS)

Test case: int x = 3.14; should fail type checking and should exit with exit code 2 (i.e., Interpreter.EXIT_STATIC_CHECKING_ERROR)

Test case: int x = 1; int y = 2; int z = 1 + (x + y); print z + 5; should pass type checking (exit code 0)

Test case: int x; int y = 1; int z = x + y; should pass type checking (exit code 0)

Test case: int x = y + 2; int y = 1; should fail type checking (exit code 2)

Test case: int x = 1; y = x; int y; should fail type checking (exit code 2)

Project 2

Test case: int x = 1; { int y; y = x + 1; } should pass type checking (exit code 0)

Test case: { { int x = 1; float y; y = 2+x; } } should fail type checking (exit code 2)

Test case: int x = readint; float y = 5.; if (x==0) { int y = x + 1; { int z = y + 2; } { int w = x + 3; } } should pass type checking (exit code 0)

Test case: int x = readint; float y = 5.; if (x==0) { int y = x + 1; { int z = y + 2; } { int w = z + 3; } } should fail type checking (exit code 2)

Test case: int x = 1; { float x = 2.3; { int x = 4; } { float y = x + 5.6; } } should pass type checking (exit code 0)

Test case: int x = 1; { float x = 2.3; } { float y = x + 3.4; } should fail type checking (exit code 2)

Project 3

Test case: int x = 1; int y; y = 2; print x + y + x + 2 * y; should print 8 and then exit with code 0

Test case: int x; print x+1; should print an error message about uninitialized variable and then exit with code 3

Test case: float x = 1.0; float y = 2.0; if (x<y) print x+y; else print x-y; should print 3.0 and then exit with code 0

Test case: int x; x = readint; print x*2; Put this test case in a file named prog and create a text file named data containing the number 123. 

Execute ./plan prog < data which should print 246 and exit with code 0

Test case: int x; x = readint; print x+readint; Use the same file data as in the previous test case. 

Execute ./plan prog < data which should print an error message about a failed readint and then exit with code 5

Test case: int x = 1; while (x<4) x=x+2; print x; should print 5 and then exit with code 0

Project 4

Test case: int x = readint; print x; should print AnyInt and then exit with code 0; do not attempt to read from stdin

Test case: float x = -3.14; print x; should print NegFloat and then exit with code 0

Test case: int x = 1; int y = 2; print x+y; should print PosInt and then exit with code 0

Test case: int x = -1; int y = 2; int z; if (x<y) z=x; else z=y; print z; should print AnyInt and then exit with code 0

Test case: int x; print x+1; should print an error message about uninitialized variable and then exit with code 3

Test case: print 2.78/(readfloat+3.14);  should print an error message about division by zero and then exit with code 4

Test case: int x = 0; int y = 1; int z; if (x < y) z = 2; print z; should print an error message about uninitialized variable and then exit with code 3

Test case: float x = 1.2; float y = 3.4; float z; if (x < y) z = 5.6; print z; should print an error message about uninitialized variable and then exit with code 3