rename nemu_assert to check

This commit is contained in:
Yanyan Jiang 2020-08-11 17:40:29 +00:00
parent 7e870cb2e4
commit 673f8605ce
33 changed files with 100 additions and 100 deletions

View file

@ -6,7 +6,7 @@
#include <klib-macros.h>
__attribute__((noinline))
void nemu_assert(bool cond) {
void check(bool cond) {
if (!cond) halt(1);
}

View file

@ -14,7 +14,7 @@ int main() {
int i, j, ans_idx = 0;
for(i = 0; i < NR_DATA; i ++) {
for(j = 0; j < NR_DATA; j ++) {
nemu_assert(add(test_data[i], test_data[j]) == ans[ans_idx ++]);
check(add(test_data[i], test_data[j]) == ans[ans_idx ++]);
}
}

View file

@ -14,12 +14,12 @@ int main() {
int i, j, ans_idx = 0;
for(i = 0; i < NR_DATA; i ++) {
for(j = 0; j < NR_DATA; j ++) {
nemu_assert(add(test_data[i], test_data[j]) == ans[ans_idx ++]);
check(add(test_data[i], test_data[j]) == ans[ans_idx ++]);
}
nemu_assert(j == NR_DATA);
check(j == NR_DATA);
}
nemu_assert(i == NR_DATA);
check(i == NR_DATA);
return 0;
}

View file

@ -23,14 +23,14 @@ int main() {
buf[0] = 0xaa;
buf[1] = 0x0;
nemu_assert(getbit(buf, 0) == 0);
nemu_assert(getbit(buf, 1) == 1);
nemu_assert(getbit(buf, 2) == 0);
nemu_assert(getbit(buf, 3) == 1);
nemu_assert(getbit(buf, 4) == 0);
nemu_assert(getbit(buf, 5) == 1);
nemu_assert(getbit(buf, 6) == 0);
nemu_assert(getbit(buf, 7) == 1);
check(getbit(buf, 0) == 0);
check(getbit(buf, 1) == 1);
check(getbit(buf, 2) == 0);
check(getbit(buf, 3) == 1);
check(getbit(buf, 4) == 0);
check(getbit(buf, 5) == 1);
check(getbit(buf, 6) == 0);
check(getbit(buf, 7) == 1);
setbit(buf, 8, 1);
setbit(buf, 9, 0);
@ -40,7 +40,7 @@ int main() {
setbit(buf, 13, 0);
setbit(buf, 14, 1);
setbit(buf, 15, 0);
nemu_assert(buf[1] == 0x55);
check(buf[1] == 0x55);
return 0;
}

View file

@ -22,18 +22,18 @@ int main() {
int i;
for(i = 0; i < N; i ++) {
nemu_assert(a[i] == i);
check(a[i] == i);
}
nemu_assert(i == N);
check(i == N);
bubble_sort();
for(i = 0; i < N; i ++) {
nemu_assert(a[i] == i);
check(a[i] == i);
}
nemu_assert(i == N);
check(i == N);
return 0;
}

View file

@ -15,7 +15,7 @@ int main() {
a[i] /= j;
for(i = 0; i < N; i ++)
nemu_assert(a[i] == i);
check(a[i] == i);
return 0;
}

View file

@ -12,7 +12,7 @@ int main() {
int i;
for(i = 0; i < 13; i ++) {
f[i] = fact(i);
nemu_assert(f[i] == ans[i]);
check(f[i] == ans[i]);
}
return 0;

View file

@ -7,10 +7,10 @@ int main() {
int i;
for(i = 2; i < 40; i ++) {
fib[i] = fib[i - 1] + fib[i - 2];
nemu_assert(fib[i] == ans[i]);
check(fib[i] == ans[i]);
}
nemu_assert(i == 40);
check(i == 40);
return 0;
}

View file

@ -27,7 +27,7 @@ int goldbach(int n) {
int main() {
int n;
for(n = 4; n <= 30; n += 2) {
nemu_assert(goldbach(n) == 1);
check(goldbach(n) == 1);
}
return 0;

View file

@ -4,13 +4,13 @@ char buf[128];
int main() {
sprintf(buf, "%s", "Hello world!\n");
nemu_assert(strcmp(buf, "Hello world!\n") == 0);
check(strcmp(buf, "Hello world!\n") == 0);
sprintf(buf, "%d + %d = %d\n", 1, 1, 2);
nemu_assert(strcmp(buf, "1 + 1 = 2\n") == 0);
check(strcmp(buf, "1 + 1 = 2\n") == 0);
sprintf(buf, "%d + %d = %d\n", 2, 10, 12);
nemu_assert(strcmp(buf, "2 + 10 = 12\n") == 0);
check(strcmp(buf, "2 + 10 = 12\n") == 0);
return 0;
}

View file

@ -19,10 +19,10 @@ int ans[] = {0, 0, 0, 0, 50, 50, 50, 75, 75, 75, 100, 100, 100, 150};
int main() {
int i, ans_idx = 0;
for(i = 0; i < NR_DATA; i ++) {
nemu_assert(if_else(test_data[i]) == ans[ans_idx ++]);
check(if_else(test_data[i]) == ans[ans_idx ++]);
}
nemu_assert(i == NR_DATA);
check(i == NR_DATA);
return 0;
}

View file

@ -9,7 +9,7 @@ int ans[] = {0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1
int main() {
int i;
for(i = 0; i < 125; i ++) {
nemu_assert(is_leap_year(i + 1890) == ans[i]);
check(is_leap_year(i + 1890) == ans[i]);
}
return 0;

View file

@ -24,21 +24,21 @@ int main() {
unsigned i;
for(i = 0; i < LENGTH(mem); i ++) {
nemu_assert((short)mem[i] == lh_ans[i]);
check((short)mem[i] == lh_ans[i]);
}
for(i = 0; i < LENGTH(mem); i ++) {
nemu_assert(mem[i] == lhu_ans[i]);
check(mem[i] == lhu_ans[i]);
}
for(i = 0; i < ((LENGTH(mem) / 2) - 1); i ++) {
unsigned x = ((unsigned*)((void*)mem + 1))[i];
nemu_assert(x == lwlr_ans[i]);
check(x == lwlr_ans[i]);
}
for(i = 0; i < LENGTH(mem); i ++) {
mem[i] = ~(1 << (2 * i + 1));
nemu_assert(mem[i] == sh_ans[i]);
check(mem[i] == sh_ans[i]);
}
return 0;

View file

@ -48,13 +48,13 @@ int main() {
for(k = 0; k < N; k ++) {
c[i][j] += a[i][k] * b[k][j];
}
nemu_assert(c[i][j] == ans[i][j]);
nemu_assert(k == N);
check(c[i][j] == ans[i][j]);
check(k == N);
}
nemu_assert(j == N);
check(j == N);
}
nemu_assert(i == N);
check(i == N);
return 0;
}

View file

@ -16,12 +16,12 @@ int main() {
int i, j, ans_idx = 0;
for(i = 0; i < NR_DATA; i ++) {
for(j = 0; j < NR_DATA; j ++) {
nemu_assert(max(test_data[i], test_data[j]) == ans[ans_idx ++]);
check(max(test_data[i], test_data[j]) == ans[ans_idx ++]);
}
nemu_assert(j == NR_DATA);
check(j == NR_DATA);
}
nemu_assert(i == NR_DATA);
check(i == NR_DATA);
return 0;
}

View file

@ -18,14 +18,14 @@ int main() {
for(i = 0; i < NR_DATA; i ++) {
for(j = 0; j < NR_DATA; j ++) {
for(k = 0; k < NR_DATA; k ++) {
nemu_assert(min3(test_data[i], test_data[j], test_data[k]) == ans[ans_idx ++]);
check(min3(test_data[i], test_data[j], test_data[k]) == ans[ans_idx ++]);
}
nemu_assert(k == NR_DATA);
check(k == NR_DATA);
}
nemu_assert(j == NR_DATA);
check(j == NR_DATA);
}
nemu_assert(i == NR_DATA);
check(i == NR_DATA);
return 0;
}

View file

@ -13,13 +13,13 @@ int main() {
b = A[3];
A[5] = b;
nemu_assert(A[0] == 0);
nemu_assert(A[1] == 1);
nemu_assert(A[2] == 2);
nemu_assert(A[3] == 3);
nemu_assert(A[4] == 4);
nemu_assert(b == 3);
nemu_assert(A[5] == 3);
check(A[0] == 0);
check(A[1] == 1);
check(A[2] == 2);
check(A[3] == 3);
check(A[4] == 4);
check(b == 3);
check(A[5] == 3);
return 0;
}

View file

@ -13,21 +13,21 @@ int main() {
b = A[3];
A[5] = b;
C[0] = 'a';
nemu_assert(C[0] == 'a');
check(C[0] == 'a');
C[1] = C[0];
nemu_assert(C[1] == 'a');
check(C[1] == 'a');
A[0] = (int)C[0];
nemu_assert(A[0] == 'a');
check(A[0] == 'a');
C[1] = 0x80;
A[0] = (int)C[1];
nemu_assert(A[1] == 1);
nemu_assert(A[2] == 2);
nemu_assert(A[3] == 3);
nemu_assert(A[4] == 4);
nemu_assert(b == 3);
nemu_assert(A[5] == 3);
nemu_assert(C[1] == 0xffffff80);
nemu_assert(A[0] == 0xffffff80);
check(A[1] == 1);
check(A[2] == 2);
check(A[3] == 3);
check(A[4] == 4);
check(b == 3);
check(A[5] == 3);
check(C[1] == 0xffffff80);
check(A[0] == 0xffffff80);
return 0;
}

View file

@ -14,12 +14,12 @@ int main() {
int i,j,ans_idx = 0;
for (i = 0;i < NR_DATA;i++) {
for (j = i;j < NR_DATA;j++) {
nemu_assert(ans[ans_idx++] == mul(test_data[i],test_data[j]));
check(ans[ans_idx++] == mul(test_data[i],test_data[j]));
}
nemu_assert(j == NR_DATA);
check(j == NR_DATA);
}
nemu_assert(i == NR_DATA);
check(i == NR_DATA);
return 0;
}

View file

@ -21,10 +21,10 @@ int main() {
}
for(j = 0; j < N; j ++) {
nemu_assert(a[j] == ans[j]);
check(a[j] == ans[j]);
}
nemu_assert(j == N);
check(j == N);
return 0;
}

View file

@ -14,12 +14,12 @@ int main() {
}
}
if(prime) {
nemu_assert(i == ans[n]);
check(i == ans[n]);
n ++;
}
}
nemu_assert(n == 10);
check(n == 10);
return 0;
}

View file

@ -32,18 +32,18 @@ int main() {
int i;
for(i = 0; i < N; i ++) {
nemu_assert(a[i] == i);
check(a[i] == i);
}
nemu_assert(i == N);
check(i == N);
quick_sort(a, 0, N - 1);
for(i = 0; i < N; i ++) {
nemu_assert(a[i] == i);
check(a[i] == i);
}
nemu_assert(i == N);
check(i == N);
return 0;
}

View file

@ -39,8 +39,8 @@ int ans[] = {38270, 218, 20};
int main() {
int x = func[0](14371, 0);
nemu_assert(x == ans[0]); // answer
nemu_assert(rec == ans[1]); // # recursions
nemu_assert(lvl == ans[2]); // max depth
check(x == ans[0]); // answer
check(rec == ans[1]); // # recursions
check(lvl == ans[2]); // max depth
return 0;
}

View file

@ -25,18 +25,18 @@ int main() {
int i;
for(i = 0; i < N; i ++) {
nemu_assert(a[i] == i);
check(a[i] == i);
}
nemu_assert(i == N);
check(i == N);
select_sort();
for(i = 0; i < N; i ++) {
nemu_assert(a[i] == i);
check(a[i] == i);
}
nemu_assert(i == N);
check(i == N);
return 0;
}

View file

@ -21,15 +21,15 @@ int main() {
unsigned i;
for(i = 0; i < LENGTH(test); i ++) {
nemu_assert((test[i] >> 7) == srl_ans[i]);
check((test[i] >> 7) == srl_ans[i]);
}
for(i = 0; i < LENGTH(test); i ++) {
nemu_assert((unsigned)((int)test[i] >> (i + 4)) == srav_ans[i]);
check((unsigned)((int)test[i] >> (i + 4)) == srav_ans[i]);
}
for(i = 0; i < LENGTH(test); i ++) {
nemu_assert((test[i] >> (i + 4)) == srlv_ans[i]);
check((test[i] >> (i + 4)) == srlv_ans[i]);
}
return 0;

View file

@ -15,12 +15,12 @@ int main() {
n0 = n % 10;
if(n == cube(n2) + cube(n1) + cube(n0)) {
nemu_assert(n == ans[k]);
check(n == ans[k]);
k ++;
}
}
nemu_assert(k == 4);
check(k == 4);
return 0;
}

View file

@ -13,15 +13,15 @@ char str1[] = "Hello";
char str[20];
int main() {
nemu_assert(strcmp(s[0], s[2]) == 0);
nemu_assert(strcmp(s[0], s[1]) == -1);
nemu_assert(strcmp(s[0] + 1, s[1] + 1) == -1);
nemu_assert(strcmp(s[0] + 2, s[1] + 2) == -1);
nemu_assert(strcmp(s[0] + 3, s[1] + 3) == -1);
check(strcmp(s[0], s[2]) == 0);
check(strcmp(s[0], s[1]) == -1);
check(strcmp(s[0] + 1, s[1] + 1) == -1);
check(strcmp(s[0] + 2, s[1] + 2) == -1);
check(strcmp(s[0] + 3, s[1] + 3) == -1);
nemu_assert(strcmp( strcat(strcpy(str, str1), s[3]), s[4]) == 0);
check(strcmp( strcat(strcpy(str, str1), s[3]), s[4]) == 0);
nemu_assert(memcmp(memset(str, '#', 5), s[5], 5) == 0);
check(memcmp(memset(str, '#', 5), s[5], 5) == 0);
return 0;
}

View file

@ -14,7 +14,7 @@ int main() {
int i, j, ans_idx = 0;
for(i = 0; i < NR_DATA; i ++) {
for(j = 0; j < NR_DATA; j ++) {
nemu_assert(sub(test_data[i], test_data[j]) == ans[ans_idx ++]);
check(sub(test_data[i], test_data[j]) == ans[ans_idx ++]);
}
}

View file

@ -8,7 +8,7 @@ int main() {
i ++;
}
nemu_assert(sum == 5050);
check(sum == 5050);
return 0;
}

View file

@ -20,10 +20,10 @@ int ans[] = {-1, 0, 2, 5, 5, 8, 8, 8, 8, 10, 10, 10, 10, 15, -1};
int main() {
int i;
for(i = 0; i < 15; i ++) {
nemu_assert(switch_case(i - 1) == ans[i]);
check(switch_case(i - 1) == ans[i]);
}
nemu_assert(i == 15);
check(i == 15);
return 0;
}

View file

@ -11,7 +11,7 @@ volatile char ans [] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
int main() {
int i;
for(i = 0; i < 128; i ++) {
nemu_assert(to_lower_case(i) == ans[i]);
check(to_lower_case(i) == ans[i]);
}
return 0;

View file

@ -9,7 +9,7 @@ int main() {
*((volatile unsigned*)(buf + 3)) = 0xaabbccdd;
x = *((volatile unsigned*)(buf + 3));
nemu_assert(x == 0xaabbccdd);
check(x == 0xaabbccdd);
buf[0] = buf[1] = 0;
}

View file

@ -13,12 +13,12 @@ int main() {
}
if(sum == n) {
nemu_assert(n == ans[k]);
check(n == ans[k]);
k ++;
}
}
nemu_assert(k == 2);
check(k == 2);
return 0;
}