test coverage

This commit is contained in:
Yaossg 2024-12-08 11:40:47 +08:00
parent 54db58d362
commit 3b95608233
23 changed files with 199 additions and 50 deletions

View file

@ -6,5 +6,14 @@ int main() {
int b;
scanf("%d", &a);
scanf("%d", &b);
printf("%d\n", 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);
printf("%d>>%d=%d\n", a, b, a >> b);
}

View file

@ -1 +1 @@
3 4
5 4

View file

@ -1,2 +1,11 @@
7
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/enum.c Normal file
View file

@ -0,0 +1,8 @@
enum {
A, B, C = 1, D, E = A, F
};
int main() {
return A + B + C + D + E + F;
// 0 + 1 + 1 + 2 + 0 + 1 = 5
}

0
test/enum.in Normal file
View file

1
test/enum.out Normal file
View file

@ -0,0 +1 @@
5

32
test/escape.c Normal file
View file

@ -0,0 +1,32 @@
int getchar();
int putchar(int ch);
int printf(char* format, ...);
int main() {
int ch;
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 {
printf("unexpected escaped character: '\\%c'\n", ch);
return 1;
}
}
putchar(ch);
}
return 0;
}

1
test/escape.in Normal file
View file

@ -0,0 +1 @@
hello\n\tworld\u

3
test/escape.out Normal file
View file

@ -0,0 +1,3 @@
hello
worldunexpected escaped character: '\u'
1

View file

@ -1,5 +1,7 @@
int printf(char* format, ...);
int gi = 42;
int main() {
printf("hello world %d\n", 42);
printf("hello world %d\n", gi);
}

87
test/loop.c Normal file
View file

@ -0,0 +1,87 @@
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");
}
int main() {
test_continue();
test_break();
}

0
test/loop.in Normal file
View file

13
test/loop.out Normal file
View file

@ -0,0 +1,13 @@
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
0

5
test/overflow.c Normal file
View file

@ -0,0 +1,5 @@
int main() {
// int placeholder[1024];
int a = 1;
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/overflow.in Normal file
View file

1
test/overflow.out Normal file
View file

@ -0,0 +1 @@
20