Added tests for self-altering expressions
This commit is contained in:
@@ -21,6 +21,10 @@ int cNeg(int x) {
|
|||||||
int cId(int x) {
|
int cId(int x) {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
int cSelfMinus(int x) {
|
||||||
|
x = x - 1;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
void printSuccess(char* name, int x, int y, int expected, int result) {
|
void printSuccess(char* name, int x, int y, int expected, int result) {
|
||||||
printf("SUCCESS:\t%s(%d, %d)\tGOT: %d\tExpected: %d\n", name, x, y, result, expected);
|
printf("SUCCESS:\t%s(%d, %d)\tGOT: %d\tExpected: %d\n", name, x, y, result, expected);
|
||||||
@@ -105,6 +109,12 @@ int main(){
|
|||||||
failed += testOneArg("id", cId, id, -1);
|
failed += testOneArg("id", cId, id, -1);
|
||||||
failed += testOneArg("id", cId, id, 15);
|
failed += testOneArg("id", cId, id, 15);
|
||||||
|
|
||||||
|
printf("\nMisc Tests\n");
|
||||||
|
failed += testOneArg("selfMinus", cSelfMinus, selfMinus, 5);
|
||||||
|
failed += testOneArg("selfMinus", cSelfMinus, selfMinus, 0);
|
||||||
|
failed += testOneArg("selfMinus", cSelfMinus, selfMinus, 100);
|
||||||
|
failed += testOneArg("selfMinus", cSelfMinus, selfMinus, -50);
|
||||||
|
|
||||||
// Tests for passing arguments to functions
|
// Tests for passing arguments to functions
|
||||||
failed += runFunctionCallTests();
|
failed += runFunctionCallTests();
|
||||||
|
|
||||||
|
|||||||
@@ -7,4 +7,5 @@ int sub(int x, int y);
|
|||||||
int mul(int x, int y);
|
int mul(int x, int y);
|
||||||
int modulo(int x, int y);
|
int modulo(int x, int y);
|
||||||
int neg(int x);
|
int neg(int x);
|
||||||
int id(int x);
|
int id(int x);
|
||||||
|
int selfMinus(int x);
|
||||||
@@ -133,6 +133,11 @@ function gte(x, y) {
|
|||||||
return (x >= y);
|
return (x >= y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function selfMinus(x) {
|
||||||
|
x = (x - 1);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
function myWhile(end) {
|
function myWhile(end) {
|
||||||
let cond = 0;
|
let cond = 0;
|
||||||
while ((cond < end)) {
|
while ((cond < end)) {
|
||||||
@@ -141,4 +146,4 @@ function myWhile(end) {
|
|||||||
return cond;
|
return cond;
|
||||||
}
|
}
|
||||||
|
|
||||||
add(1, 1);
|
add(1, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user