diff --git a/test/basic/comment.c b/test/basic/comment.c new file mode 100644 index 0000000..ac46d2d --- /dev/null +++ b/test/basic/comment.c @@ -0,0 +1,4 @@ +// hello +/* world */ + +int main() {} \ No newline at end of file diff --git a/test/basic/comment.out b/test/basic/comment.out new file mode 100644 index 0000000..573541a --- /dev/null +++ b/test/basic/comment.out @@ -0,0 +1 @@ +0 diff --git a/test/loop/break.c b/test/loop/break.c new file mode 100644 index 0000000..bfa4699 --- /dev/null +++ b/test/loop/break.c @@ -0,0 +1,39 @@ +int printf(char* format, ...); + +int main() { + int i; + + // For loop + printf("For loop:\n"); + for (i = 0; i < 5; i++) { + if (i == 3) { + break; // Exit the loop when i is 3 + } + printf("%d ", i); + } + printf("\n"); + + // While loop + printf("While loop:\n"); + i = 0; + while (i < 5) { + if (i == 3) { + break; // Exit the loop when i is 3 + } + printf("%d ", i); + i++; + } + printf("\n"); + + // Do-while loop + printf("Do-while loop:\n"); + i = 0; + do { + if (i == 3) { + break; // Exit the loop when i is 3 + } + printf("%d ", i); + i++; + } while (i < 5); + printf("\n"); +} diff --git a/test/loop/break.out b/test/loop/break.out new file mode 100644 index 0000000..e8ad5e7 --- /dev/null +++ b/test/loop/break.out @@ -0,0 +1,7 @@ +For loop: +0 1 2 +While loop: +0 1 2 +Do-while loop: +0 1 2 +0 diff --git a/test/loop/continue.c b/test/loop/continue.c new file mode 100644 index 0000000..214a62d --- /dev/null +++ b/test/loop/continue.c @@ -0,0 +1,41 @@ +int printf(char* format, ...); + +int main() { + int i; + + // For loop + printf("For loop:\n"); + for (i = 0; i < 5; i++) { + if (i == 3) { + continue; // Skip the rest of the loop when i is 3 + } + printf("%d ", i); + } + printf("\n"); + + // While loop + printf("While loop:\n"); + i = 0; + while (i < 5) { + if (i == 3) { + i++; + continue; // Skip the rest of the loop when i is 3 + } + printf("%d ", i); + i++; + } + printf("\n"); + + // Do-while loop + printf("Do-while loop:\n"); + i = 0; + do { + if (i == 3) { + i++; + continue; // Skip the rest of the loop when i is 3 + } + printf("%d ", i); + i++; + } while (i < 5); + printf("\n"); +} \ No newline at end of file diff --git a/test/loop/continue.out b/test/loop/continue.out new file mode 100644 index 0000000..a59c441 --- /dev/null +++ b/test/loop/continue.out @@ -0,0 +1,7 @@ +For loop: +0 1 2 4 +While loop: +0 1 2 4 +Do-while loop: +0 1 2 4 +0 diff --git a/test/loop/loop.c b/test/loop/loop.c deleted file mode 100644 index 6ef9347..0000000 --- a/test/loop/loop.c +++ /dev/null @@ -1,105 +0,0 @@ -int printf(char* format, ...); -int scanf(char* format, ...); - -/* **dummy** loop test generated by copilot */ - -void test_continue() { - int i; - - // For loop - printf("For loop:\n"); - for (i = 0; i < 5; i++) { - if (i == 3) { - continue; // Skip the rest of the loop when i is 3 - } - printf("%d ", i); - } - printf("\n"); - - // While loop - printf("While loop:\n"); - i = 0; - while (i < 5) { - if (i == 3) { - i++; - continue; // Skip the rest of the loop when i is 3 - } - printf("%d ", i); - i++; - } - printf("\n"); - - // Do-while loop - printf("Do-while loop:\n"); - i = 0; - do { - if (i == 3) { - i++; - continue; // Skip the rest of the loop when i is 3 - } - printf("%d ", i); - i++; - } while (i < 5); - printf("\n"); -} - -void test_break() { - int i; - - // For loop - printf("For loop:\n"); - for (i = 0; i < 5; i++) { - if (i == 3) { - break; // Exit the loop when i is 3 - } - printf("%d ", i); - } - printf("\n"); - - // While loop - printf("While loop:\n"); - i = 0; - while (i < 5) { - if (i == 3) { - break; // Exit the loop when i is 3 - } - printf("%d ", i); - i++; - } - printf("\n"); - - // Do-while loop - printf("Do-while loop:\n"); - i = 0; - do { - if (i == 3) { - break; // Exit the loop when i is 3 - } - printf("%d ", i); - i++; - } while (i < 5); - printf("\n"); -} - -void test_nested() { - int i; - int j; - - // For loop - printf("For loop:\n"); - for (i = 0; i < 5; i++) { - for (j = 0; j < 5; j++) { - if (i >= 2 && j >= 2 && i + j >= 5) { - return; // Exit nested loop via return - } - printf("(%d, %d) ", i, j); - } - printf("\n"); - } -} - -int main() { - test_continue(); - test_break(); - test_nested(); -} \ No newline at end of file diff --git a/test/loop/loop.out b/test/loop/loop.out deleted file mode 100644 index 1c18926..0000000 --- a/test/loop/loop.out +++ /dev/null @@ -1,16 +0,0 @@ -For loop: -0 1 2 4 -While loop: -0 1 2 4 -Do-while loop: -0 1 2 4 -For loop: -0 1 2 -While loop: -0 1 2 -Do-while loop: -0 1 2 -For loop: -(0, 0) (0, 1) (0, 2) (0, 3) (0, 4) -(1, 0) (1, 1) (1, 2) (1, 3) (1, 4) -(2, 0) (2, 1) (2, 2) 0 diff --git a/test/loop/nested.c b/test/loop/nested.c new file mode 100644 index 0000000..6232e27 --- /dev/null +++ b/test/loop/nested.c @@ -0,0 +1,20 @@ +int printf(char* format, ...); + +void test() { + int i; + int j; + + for (i = 0; i < 5; i++) { + for (j = 0; j < 5; j++) { + if (i >= 2 && j >= 2 && i + j >= 5) { + return; // Exit nested loop via return + } + printf("(%d, %d)%c", i, j, " \n"[j == 4]); + } + } +} + +int main() { + test(); + printf("\n"); +} \ No newline at end of file diff --git a/test/loop/nested.out b/test/loop/nested.out new file mode 100644 index 0000000..bea6ce1 --- /dev/null +++ b/test/loop/nested.out @@ -0,0 +1,4 @@ +(0, 0) (0, 1) (0, 2) (0, 3) (0, 4) +(1, 0) (1, 1) (1, 2) (1, 3) (1, 4) +(2, 0) (2, 1) (2, 2) +0 diff --git a/test/operator/unary.c b/test/operator/unary.c new file mode 100644 index 0000000..4d138db --- /dev/null +++ b/test/operator/unary.c @@ -0,0 +1,9 @@ +int printf(char* format, ...); + +int main() { + int a = 5; + printf("+a=%d\n", +a); + printf("-a=%d\n", -a); + printf("!a=%d\n", !a); + printf("~a=%d\n", ~a); +} \ No newline at end of file diff --git a/test/operator/unary.out b/test/operator/unary.out new file mode 100644 index 0000000..69a46e7 --- /dev/null +++ b/test/operator/unary.out @@ -0,0 +1,5 @@ ++a=5 +-a=-5 +!a=0 +~a=-6 +0