MCPcopy Create free account
hub / github.com/git/git / test

Function test

t/helper/test-mergesort.c:303–357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

301}
302
303static int test(const struct dist *dist, const struct mode *mode, int n, int m)
304{
305 int *arr;
306 size_t i;
307 struct number *curr, *list, **tail;
308 int is_sorted = 1;
309 int is_stable = 1;
310 const char *verdict;
311 int result = -1;
312
313 ALLOC_ARRAY(arr, n);
314 dist->fn(arr, n, m);
315 mode->fn(arr, n);
316 for (i = 0, tail = &list; i < n; i++) {
317 curr = xmalloc(sizeof(*curr));
318 curr->value = arr[i];
319 curr->rank = i;
320 *tail = curr;
321 tail = &curr->next;
322 }
323 *tail = NULL;
324
325 stats.get_next = stats.set_next = stats.compare = 0;
326 sort_numbers(&list, compare_numbers);
327
328 QSORT(arr, n, compare_ints);
329 for (i = 0, curr = list; i < n && curr; i++, curr = curr->next) {
330 if (arr[i] != curr->value)
331 is_sorted = 0;
332 if (curr->next && curr->value == curr->next->value &&
333 curr->rank >= curr->next->rank)
334 is_stable = 0;
335 }
336 if (i < n) {
337 verdict = "too short";
338 } else if (curr) {
339 verdict = "too long";
340 } else if (!is_sorted) {
341 verdict = "not sorted";
342 } else if (!is_stable) {
343 verdict = "unstable";
344 } else {
345 verdict = "OK";
346 result = 0;
347 }
348
349 printf("%-9s %-16s %8d %8d %8d %8d %8d %s\n",
350 dist->name, mode->name, n, m, stats.get_next, stats.set_next,
351 stats.compare, verdict);
352
353 clear_numbers(list);
354 free(arr);
355
356 return result;
357}
358
359/*
360 * A version of the qsort certification program from "Engineering a Sort

Callers 1

run_testsFunction · 0.85

Calls 2

clear_numbersFunction · 0.85
xmallocFunction · 0.50

Tested by

no test coverage detected