smarter and error test
This commit is contained in:
		
							parent
							
								
									bf7f456967
								
							
						
					
					
						commit
						49ed7c5df5
					
				
					 37 changed files with 83 additions and 36 deletions
				
			
		
							
								
								
									
										39
									
								
								test/array/arith.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								test/array/arith.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,39 @@
 | 
			
		|||
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 check(int a[], int i, int 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)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void check_all(int a[], int n) {
 | 
			
		||||
    for (int i = 0; i < n; i++) {
 | 
			
		||||
        for (int j = i + 1; j < n; j++) {
 | 
			
		||||
            if (a[i] > a[j]) {
 | 
			
		||||
                check(a, i, j);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int global[100];
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    int local[100];
 | 
			
		||||
    check_all(global, 100);
 | 
			
		||||
    check_all(local, 100);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										1
									
								
								test/array/arith.out
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								test/array/arith.out
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
0
 | 
			
		||||
							
								
								
									
										34
									
								
								test/array/sort.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								test/array/sort.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,34 @@
 | 
			
		|||
int printf(char* format, ...);
 | 
			
		||||
int scanf(char* format, ...);
 | 
			
		||||
int exit(int status);
 | 
			
		||||
 | 
			
		||||
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]);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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/array/sort.in
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								test/array/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/array/sort.out
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								test/array/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