t-prio-queue: simplify using compound literals

Test names like "basic" are mentioned seven times in the code (ignoring case): Twice when defining the input and result macros, thrice when defining the test function, and twice again when calling it. Reduce that to a single time by using compound literals to pass the input and result arrays via TEST_INPUT to test_prio_queue(). Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Apr 2, 2024 at 20:30 UTC 543b2a1083f0fca2eaae86bf8d359aa565981b97
1 file changed +17 -34
t/unit-tests/t-prio-queue.c
+17 -34
@@ -66,43 +66,26 @@ static void test_prio_queue(int *input, size_t input_size,
66 clear_prio_queue(&pq);
67 }
68
69 -#define BASIC_INPUT 2, 6, 3, 10, 9, 5, 7, 4, 5, 8, 1, DUMP
70 -#define BASIC_RESULT 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10
71 -
72 -#define MIXED_PUT_GET_INPUT 6, 2, 4, GET, 5, 3, GET, GET, 1, DUMP
73 -#define MIXED_PUT_GET_RESULT 2, 3, 4, 1, 5, 6
74 -
75 -#define EMPTY_QUEUE_INPUT 1, 2, GET, GET, GET, 1, 2, GET, GET, GET
76 -#define EMPTY_QUEUE_RESULT 1, 2, MISSING, 1, 2, MISSING
77 -
78 -#define STACK_INPUT STACK, 8, 1, 5, 4, 6, 2, 3, DUMP
79 -#define STACK_RESULT 3, 2, 6, 4, 5, 1, 8
80 -
81 -#define REVERSE_STACK_INPUT STACK, 1, 2, 3, 4, 5, 6, REVERSE, DUMP
82 -#define REVERSE_STACK_RESULT 1, 2, 3, 4, 5, 6
83 -
84 -#define TEST_INPUT(INPUT, RESULT, name) \
85 - static void test_##name(void) \
86 -{ \
87 - int input[] = {INPUT}; \
88 - int result[] = {RESULT}; \
89 - test_prio_queue(input, ARRAY_SIZE(input), \
90 - result, ARRAY_SIZE(result)); \
91 -}
92 -
93 -TEST_INPUT(BASIC_INPUT, BASIC_RESULT, basic)
94 -TEST_INPUT(MIXED_PUT_GET_INPUT, MIXED_PUT_GET_RESULT, mixed)
95 -TEST_INPUT(EMPTY_QUEUE_INPUT, EMPTY_QUEUE_RESULT, empty)
96 -TEST_INPUT(STACK_INPUT, STACK_RESULT, stack)
97 -TEST_INPUT(REVERSE_STACK_INPUT, REVERSE_STACK_RESULT, reverse)
69 +#define TEST_INPUT(input, result) \
70 + test_prio_queue(input, ARRAY_SIZE(input), result, ARRAY_SIZE(result))
71
72 int cmd_main(int argc, const char **argv)
73 {
101 - TEST(test_basic(), "prio-queue works for basic input");
102 - TEST(test_mixed(), "prio-queue works for mixed put & get commands");
103 - TEST(test_empty(), "prio-queue works when queue is empty");
104 - TEST(test_stack(), "prio-queue works when used as a LIFO stack");
105 - TEST(test_reverse(), "prio-queue works when LIFO stack is reversed");
74 + TEST(TEST_INPUT(((int []){ 2, 6, 3, 10, 9, 5, 7, 4, 5, 8, 1, DUMP }),
75 + ((int []){ 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10 })),
76 + "prio-queue works for basic input");
77 + TEST(TEST_INPUT(((int []){ 6, 2, 4, GET, 5, 3, GET, GET, 1, DUMP }),
78 + ((int []){ 2, 3, 4, 1, 5, 6 })),
79 + "prio-queue works for mixed put & get commands");
80 + TEST(TEST_INPUT(((int []){ 1, 2, GET, GET, GET, 1, 2, GET, GET, GET }),
81 + ((int []){ 1, 2, MISSING, 1, 2, MISSING })),
82 + "prio-queue works when queue is empty");
83 + TEST(TEST_INPUT(((int []){ STACK, 8, 1, 5, 4, 6, 2, 3, DUMP }),
84 + ((int []){ 3, 2, 6, 4, 5, 1, 8 })),
85 + "prio-queue works when used as a LIFO stack");
86 + TEST(TEST_INPUT(((int []){ STACK, 1, 2, 3, 4, 5, 6, REVERSE, DUMP }),
87 + ((int []){ 1, 2, 3, 4, 5, 6 })),
88 + "prio-queue works when LIFO stack is reversed");
89
90 return test_done();
91 }