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)\
18 must_be_true(n->commit->commit_time <= previous_time);\
19 previous_time = n->commit->commit_time;\
22 memset(&list
, 0x0, sizeof(git_commit_list
));
25 for (t
= 0; t
< 20; ++t
)
27 const int test_size
= rand() % 500 + 500;
29 // Purely random sorting test
30 for (i
= 0; i
< test_size
; ++i
)
32 git_commit
*c
= git__malloc(sizeof(git_commit
));
33 c
->commit_time
= (time_t)rand();
35 git_commit_list_push_back(&list
, c
);
38 git_commit_list_timesort(&list
);
40 git_commit_list_clear(&list
, 1);
43 // Try to sort list with all dates equal.
44 for (i
= 0; i
< 200; ++i
)
46 git_commit
*c
= git__malloc(sizeof(git_commit
));
49 git_commit_list_push_back(&list
, c
);
52 git_commit_list_timesort(&list
);
54 git_commit_list_clear(&list
, 1);
56 // Try to sort empty list
57 git_commit_list_timesort(&list
);