@@ -19,28 +19,36 @@ static int show(int *v)
19
19
return v ? * v : MISSING ;
20
20
}
21
21
22
- static void test_prio_queue (int * input , int * result , size_t input_size )
22
+ static void test_prio_queue (int * input , size_t input_size ,
23
+ int * result , size_t result_size )
23
24
{
24
25
struct prio_queue pq = { intcmp };
26
+ int j = 0 ;
25
27
26
- for (int i = 0 , j = 0 ; i < input_size ; i ++ ) {
28
+ for (int i = 0 ; i < input_size ; i ++ ) {
27
29
void * peek , * get ;
28
30
switch (input [i ]) {
29
31
case GET :
30
32
peek = prio_queue_peek (& pq );
31
33
get = prio_queue_get (& pq );
32
34
if (!check (peek == get ))
33
35
return ;
34
- if (!check_int (result [j ++ ], = = , show (get )))
35
- test_msg ("failed at result[] index %d" , j - 1 );
36
+ if (!check_uint (j , < , result_size ))
37
+ break ;
38
+ if (!check_int (result [j ], = = , show (get )))
39
+ test_msg (" j: %d" , j );
40
+ j ++ ;
36
41
break ;
37
42
case DUMP :
38
43
while ((peek = prio_queue_peek (& pq ))) {
39
44
get = prio_queue_get (& pq );
40
45
if (!check (peek == get ))
41
46
return ;
42
- if (!check_int (result [j ++ ], = = , show (get )))
43
- test_msg ("failed at result[] index %d" , j - 1 );
47
+ if (!check_uint (j , < , result_size ))
48
+ break ;
49
+ if (!check_int (result [j ], = = , show (get )))
50
+ test_msg (" j: %d" , j );
51
+ j ++ ;
44
52
}
45
53
break ;
46
54
case STACK :
@@ -54,6 +62,7 @@ static void test_prio_queue(int *input, int *result, size_t input_size)
54
62
break ;
55
63
}
56
64
}
65
+ check_uint (j , = = , result_size );
57
66
clear_prio_queue (& pq );
58
67
}
59
68
@@ -77,7 +86,8 @@ static void test_prio_queue(int *input, int *result, size_t input_size)
77
86
{ \
78
87
int input[] = {INPUT}; \
79
88
int result[] = {RESULT}; \
80
- test_prio_queue(input, result, ARRAY_SIZE(input)); \
89
+ test_prio_queue(input, ARRAY_SIZE(input), \
90
+ result, ARRAY_SIZE(result)); \
81
91
}
82
92
83
93
TEST_INPUT (BASIC_INPUT , BASIC_RESULT , basic )
0 commit comments