test subdirectory
This commit is contained in:
parent
b4dbce76cf
commit
bf7f456967
31 changed files with 19 additions and 13 deletions
19
test/old/add.c
Normal file
19
test/old/add.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
int printf(char* format, ...);
|
||||
int scanf(char* format, ...);
|
||||
|
||||
int main() {
|
||||
int a;
|
||||
int b;
|
||||
scanf("%d", &a);
|
||||
scanf("%d", &b);
|
||||
printf("%d+%d=%d\n", a, b, a + b);
|
||||
printf("%d-%d=%d\n", a, b, a - b);
|
||||
printf("%d*%d=%d\n", a, b, a * b);
|
||||
printf("%d/%d=%d\n", a, b, a / b);
|
||||
printf("%d%%%d=%d\n", a, b, a % b);
|
||||
printf("%d&%d=%d\n", a, b, a & b);
|
||||
printf("%d|%d=%d\n", a, b, a | b);
|
||||
printf("%d^%d=%d\n", a, b, a ^ b);
|
||||
printf("%d<<%d=%d\n", a, b, a << b);
|
||||
printf("%d>>%d=%d\n", a, b, a >> b);
|
||||
}
|
1
test/old/add.in
Normal file
1
test/old/add.in
Normal file
|
@ -0,0 +1 @@
|
|||
5 4
|
11
test/old/add.out
Normal file
11
test/old/add.out
Normal file
|
@ -0,0 +1,11 @@
|
|||
5+4=9
|
||||
5-4=1
|
||||
5*4=20
|
||||
5/4=1
|
||||
5%4=1
|
||||
5&4=4
|
||||
5|4=5
|
||||
5^4=1
|
||||
5<<4=80
|
||||
5>>4=0
|
||||
0
|
8
test/old/enum.c
Normal file
8
test/old/enum.c
Normal file
|
@ -0,0 +1,8 @@
|
|||
enum {
|
||||
A, B, C = -B, D, E = +1, F,
|
||||
};
|
||||
|
||||
int main() {
|
||||
return A + B + C + D + E + F;
|
||||
// 0 + 1 + -1 + 0 + 1 + 2 = 3
|
||||
}
|
0
test/old/enum.in
Normal file
0
test/old/enum.in
Normal file
1
test/old/enum.out
Normal file
1
test/old/enum.out
Normal file
|
@ -0,0 +1 @@
|
|||
3
|
34
test/old/escape.c
Normal file
34
test/old/escape.c
Normal file
|
@ -0,0 +1,34 @@
|
|||
int getchar();
|
||||
int putchar(int ch);
|
||||
int fprintf(void* file, char* format, ...);
|
||||
extern void* stdout;
|
||||
|
||||
|
||||
int main() {
|
||||
char ch = 0["\t\r\""];;
|
||||
while ((ch = getchar()) != -1) {
|
||||
if (ch == '\\') {
|
||||
ch = getchar();
|
||||
if (ch == 'n') {
|
||||
ch = '\n';
|
||||
} else if (ch == 't') {
|
||||
ch = '\t';
|
||||
} else if (ch == 'r') {
|
||||
ch = '\r';
|
||||
} else if (ch == '0') {
|
||||
ch = '\0';
|
||||
} else if (ch == '\\') {
|
||||
ch = '\\';
|
||||
} else if (ch == '\'') {
|
||||
ch = '\'';
|
||||
} else if (ch == '\"') {
|
||||
ch = '\"';
|
||||
} else {
|
||||
fprintf(stdout, "unexpected escaped character: '\\%c'\n", ch);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
putchar(ch);
|
||||
}
|
||||
return 0;
|
||||
}
|
1
test/old/escape.in
Normal file
1
test/old/escape.in
Normal file
|
@ -0,0 +1 @@
|
|||
hello\n\tworld\u
|
3
test/old/escape.out
Normal file
3
test/old/escape.out
Normal file
|
@ -0,0 +1,3 @@
|
|||
hello
|
||||
worldunexpected escaped character: '\u'
|
||||
1
|
7
test/old/hello.c
Normal file
7
test/old/hello.c
Normal file
|
@ -0,0 +1,7 @@
|
|||
int printf(char* format, ...);
|
||||
|
||||
int gi = 42;
|
||||
|
||||
int main() {
|
||||
printf("hello world %d\n", gi);
|
||||
}
|
0
test/old/hello.in
Normal file
0
test/old/hello.in
Normal file
2
test/old/hello.out
Normal file
2
test/old/hello.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
hello world 42
|
||||
0
|
14
test/old/inc.c
Normal file
14
test/old/inc.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
int printf(char* format, ...);
|
||||
|
||||
int main() {
|
||||
int a = 4;
|
||||
printf("a = %d\n", a);
|
||||
printf("a++ = %d\n", a++);
|
||||
printf("a = %d\n", a);
|
||||
printf("++a = %d\n", ++a);
|
||||
printf("a = %d\n", a);
|
||||
printf("a-- = %d\n", a--);
|
||||
printf("a = %d\n", a);
|
||||
printf("--a = %d\n", --a);
|
||||
printf("a = %d\n", a);
|
||||
}
|
0
test/old/inc.in
Normal file
0
test/old/inc.in
Normal file
10
test/old/inc.out
Normal file
10
test/old/inc.out
Normal file
|
@ -0,0 +1,10 @@
|
|||
a = 4
|
||||
a++ = 4
|
||||
a = 5
|
||||
++a = 6
|
||||
a = 6
|
||||
a-- = 6
|
||||
a = 5
|
||||
--a = 4
|
||||
a = 4
|
||||
0
|
105
test/old/loop.c
Normal file
105
test/old/loop.c
Normal file
|
@ -0,0 +1,105 @@
|
|||
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();
|
||||
}
|
0
test/old/loop.in
Normal file
0
test/old/loop.in
Normal file
16
test/old/loop.out
Normal file
16
test/old/loop.out
Normal file
|
@ -0,0 +1,16 @@
|
|||
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
|
41
test/old/overflow.c
Normal file
41
test/old/overflow.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
int printf(char* format, ...);
|
||||
|
||||
|
||||
enum {
|
||||
a = 1
|
||||
};
|
||||
|
||||
int get_20() {
|
||||
return (a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(- -0)))))))))))))))))))));
|
||||
}
|
||||
|
||||
void dummy(int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7) {
|
||||
a0 += a1;
|
||||
printf("%d\n", a0);
|
||||
a0 -= a1;
|
||||
printf("%d\n", a0);
|
||||
a0 *= a1;
|
||||
printf("%d\n", a0);
|
||||
a0 /= a1;
|
||||
printf("%d\n", a0);
|
||||
a0 %= a1;
|
||||
printf("%d\n", a0);
|
||||
a0 &= a1;
|
||||
printf("%d\n", a0);
|
||||
a0 |= a1;
|
||||
printf("%d\n", a0);
|
||||
a0 ^= a2;
|
||||
printf("%d\n", a0);
|
||||
a0 <<= a1;
|
||||
printf("%d\n", a0);
|
||||
a0 >>= a1;
|
||||
printf("%d\n", a0);
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
char placeholder[4096];
|
||||
int a = 1;
|
||||
dummy((a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(! !0))))))))))))))))))))), 3, a, a, a, a, a, a);
|
||||
return (a=(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(a+(~ ~0)))))))))))))))))))))), (a = +a);
|
||||
}
|
0
test/old/overflow.in
Normal file
0
test/old/overflow.in
Normal file
11
test/old/overflow.out
Normal file
11
test/old/overflow.out
Normal file
|
@ -0,0 +1,11 @@
|
|||
23
|
||||
20
|
||||
60
|
||||
20
|
||||
2
|
||||
2
|
||||
3
|
||||
2
|
||||
16
|
||||
2
|
||||
20
|
19
test/old/parse.c
Normal file
19
test/old/parse.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
int getchar();
|
||||
|
||||
|
||||
int is_digit(int ch) {
|
||||
return '0' <= ch && ch <= '9';
|
||||
}
|
||||
|
||||
int parse_int(int ch) {
|
||||
int num = ch - '0';
|
||||
while (is_digit(ch = getchar())) {
|
||||
num = num * 10;
|
||||
num = num + ch - '0';
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
int main() {
|
||||
return parse_int(getchar());
|
||||
}
|
1
test/old/parse.in
Normal file
1
test/old/parse.in
Normal file
|
@ -0,0 +1 @@
|
|||
42
|
1
test/old/parse.out
Normal file
1
test/old/parse.out
Normal file
|
@ -0,0 +1 @@
|
|||
42
|
17
test/old/short.c
Normal file
17
test/old/short.c
Normal file
|
@ -0,0 +1,17 @@
|
|||
int printf(char* format, ...);
|
||||
|
||||
int f(int i) {
|
||||
printf("f(%d)\n", i);
|
||||
return i % 2;
|
||||
}
|
||||
|
||||
int main() {
|
||||
1 && f(1);
|
||||
0 && f(2);
|
||||
1 || f(3);
|
||||
0 || f(4);
|
||||
1 ? f(5) : f(6);
|
||||
0 ? f(7) : f(8);
|
||||
1 && f(9) || f(10);
|
||||
0 && f(11) || f(12);
|
||||
}
|
0
test/old/short.in
Normal file
0
test/old/short.in
Normal file
7
test/old/short.out
Normal file
7
test/old/short.out
Normal file
|
@ -0,0 +1,7 @@
|
|||
f(1)
|
||||
f(4)
|
||||
f(5)
|
||||
f(8)
|
||||
f(9)
|
||||
f(12)
|
||||
0
|
47
test/old/sort.c
Normal file
47
test/old/sort.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
int printf(char* format, ...);
|
||||
int scanf(char* format, ...);
|
||||
int exit(int status);
|
||||
|
||||
void assert_eq(int expected, int actual) {
|
||||
if (expected != actual) {
|
||||
printf("expected: %d, actual: %d\n", expected, actual);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void swap(int* a, int* b) {
|
||||
int t = *a;
|
||||
*a = *b;
|
||||
*b = t;
|
||||
}
|
||||
|
||||
void sort(int a[], int n) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = i + 1; j < n; j++) {
|
||||
if (a[i] > a[j]) {
|
||||
swap(&a[i], &a[j]);
|
||||
assert_eq(i - j, &a[i] - &a[j]);
|
||||
assert_eq(j - i, &a[j] - &a[i]);
|
||||
assert_eq(a[i], *(a + i));
|
||||
assert_eq(i[a], *(i + a));
|
||||
assert_eq(a[j - i], *(a + (j - i)));
|
||||
assert_eq(j[a - i], *(j + (a - i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int a[100];
|
||||
int n;
|
||||
|
||||
int main() {
|
||||
scanf("%d", &n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
scanf("%d", &a[i]);
|
||||
}
|
||||
sort(a, n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
printf("%d ", a[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
11
test/old/sort.in
Normal file
11
test/old/sort.in
Normal file
|
@ -0,0 +1,11 @@
|
|||
100
|
||||
13 49 15 58 24 74 80 81 69 23
|
||||
67 88 59 39 1 12 73 50 55 53
|
||||
71 63 9 90 87 89 51 75 40 84
|
||||
25 94 68 47 48 14 99 33 62 79
|
||||
66 85 56 31 38 29 86 46 70 6
|
||||
10 19 64 72 45 4 11 42 78 7
|
||||
95 27 93 57 21 35 5 22 76 54
|
||||
44 98 61 32 17 92 65 36 20 28
|
||||
83 2 18 60 16 41 30 37 100 97
|
||||
77 3 82 8 26 34 91 43 96 52
|
2
test/old/sort.out
Normal file
2
test/old/sort.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
||||
0
|
Loading…
Add table
Add a link
Reference in a new issue