unit test

This commit is contained in:
Yaossg 2024-12-07 14:13:34 +08:00
parent 98d5a1a3bc
commit 54db58d362
18 changed files with 64 additions and 9 deletions

10
test/add.c Normal file
View file

@ -0,0 +1,10 @@
int printf(char* format, ...);
int scanf(char* format, ...);
int main() {
int a;
int b;
scanf("%d", &a);
scanf("%d", &b);
printf("%d\n", a + b);
}

1
test/add.in Normal file
View file

@ -0,0 +1 @@
3 4

2
test/add.out Normal file
View file

@ -0,0 +1,2 @@
7
0

5
test/hello.c Normal file
View file

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

0
test/hello.in Normal file
View file

2
test/hello.out Normal file
View file

@ -0,0 +1,2 @@
hello world 42
0

19
test/parse.c Normal file
View 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/parse.in Normal file
View file

@ -0,0 +1 @@
42

1
test/parse.out Normal file
View file

@ -0,0 +1 @@
42

28
test/sort.c Normal file
View file

@ -0,0 +1,28 @@
int printf(char* format, ...);
int scanf(char* format, ...);
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]) {
int t = a[i];
a[i] = a[j];
a[j] = t;
}
}
}
}
int main() {
int n;
int a[100];
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/sort.in Normal file
View 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/sort.out Normal file
View 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