2 #include "test_helpers.h"
5 #include <git/commit.h>
7 BEGIN_TEST(list_timesort_test
)
14 #define TEST_SORTED() \
15 previous_time = INT_MAX;\
16 for (n = list.head; n != NULL; n = n->next) {\
17 must_be_true(n->commit->commit_time <= previous_time);\
18 previous_time = n->commit->commit_time;\
21 memset(&list
, 0x0, sizeof(git_commit_list
));
22 srand((unsigned int)time(NULL
));
24 for (t
= 0; t
< 20; ++t
) {
25 const int test_size
= rand() % 500 + 500;
27 /* Purely random sorting test */
28 for (i
= 0; i
< test_size
; ++i
) {
29 git_commit
*c
= git__malloc(sizeof(git_commit
));
30 c
->commit_time
= (time_t)rand();
32 git_commit_list_push_back(&list
, c
);
35 git_commit_list_timesort(&list
);
37 git_commit_list_clear(&list
, 1);
40 /* Try to sort list with all dates equal. */
41 for (i
= 0; i
< 200; ++i
) {
42 git_commit
*c
= git__malloc(sizeof(git_commit
));
45 git_commit_list_push_back(&list
, c
);
48 git_commit_list_timesort(&list
);
50 git_commit_list_clear(&list
, 1);
52 /* Try to sort empty list */
53 git_commit_list_timesort(&list
);