Skip to content

Commit

Permalink
clean up ASSERT_ARRAY_EQUAL output
Browse files Browse the repository at this point in the history
- align columns
- only print '!=' when array elements differ, print '==' otherwise
  • Loading branch information
mmitch committed Oct 10, 2023
1 parent 7ad1b9e commit ebd9737
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion impulsegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ test void test_gen_impulsetab()
};
int32_t *pulsetab = gen_impulsetab(w_shift, n_shift, cutoff);

ASSERT_ARRAY_EQUAL("%d", reference, pulsetab);
ASSERT_ARRAY_EQUAL("%8d", reference, pulsetab);
}
TEST(test_gen_impulsetab);
TEST_EOF;
9 changes: 6 additions & 3 deletions test.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define ASSERT_ARRAY_EQUAL(fmt, a, b) do { \
int pass = 1; \
int i; \
char *cmp; \
for (i=0; i<sizeof(a)/sizeof(*(a)); i++) { \
if ((a)[i] == (b)[i]) \
continue; \
Expand All @@ -31,9 +32,11 @@
return; \
fprintf(stderr, "FAIL\nTest failed at %s:%d\n", __FILE__, __LINE__); \
for (i=0; i<sizeof(a)/sizeof(*(a)); i++) { \
/* if ((a)[i] == (b)[i]) \
continue; */ \
fprintf(stderr, "%d: "fmt" != "fmt"\n", i, (a)[i], (b)[i]); \
if ((a)[i] == (b)[i]) \
cmp = "=="; \
else \
cmp = "!="; \
fprintf(stderr, "%4d: "fmt" %s "fmt"\n", i, (a)[i], cmp, (b)[i]); \
} \
exit(1); \
} while(0)
Expand Down
2 changes: 1 addition & 1 deletion util.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ test void test_spack()

int l = spack(got, "{ }<bwdq{1}>bwdq", b, w, d, q, b, w, d, q);

ASSERT_ARRAY_EQUAL("%d", want, got);
ASSERT_ARRAY_EQUAL("%2d", want, got);
ASSERT_EQUAL("%d", (int)sizeof(want), l);
}
TEST(test_spack);
Expand Down

0 comments on commit ebd9737

Please sign in to comment.