YAC 3.13.0
Yet Another Coupler
Loading...
Searching...
No Matches
test_quicksort.c
Go to the documentation of this file.
1// Copyright (c) 2024 The YAC Authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#include <stdlib.h>
6#include <stdio.h>
7#include "utils_core.h"
8#include "tests.h"
9
15int main (void) {
16
17 { // descending order
18#define LEN 128
19 int a[LEN];
20 int idx[LEN];
21
22
23 for (int i = 0; i < LEN; ++i) {
24 a[i] = LEN-i-1;
25 idx[i] = i;
26 }
27
28 for (int i = 0; i < LEN; ++i) {
29 printf ("Unsorted list is i=%i a[i]=%i idx[i]=%i\n ", i, a[i], idx[i]);
30 }
31
32 yac_quicksort_index ( a, (size_t)LEN, idx );
33
34 for (int i = 0; i < LEN; ++i) {
35
36 if ((i != a[i]) || (idx[i] != LEN-i-1)) INC_ERR;
37
38 printf ("Sorted list is i=%i a[i]=%i idx[i]=%i\n ", i, a[i], idx[i]);
39 }
40#undef LEN
41 }
42
43 { // ascending order
44#define LEN 128
45 int a[LEN];
46 int idx[LEN];
47
48 for (int i = 0; i < LEN; ++i) {
49 a[i] = i;
50 idx[i] = i;
51 }
52
53 for (int i = 0; i < LEN; ++i) {
54 printf ("Unsorted list is i=%i a[i]=%i idx[i]=%i\n ", i, a[i], idx[i]);
55 }
56
57 yac_quicksort_index ( a, (size_t)LEN, idx );
58
59 for (int i = 0; i < LEN; ++i) {
60
61 if ((i != a[i]) || (idx[i] != i)) INC_ERR;
62
63 printf ("Sorted list is i=%i a[i]=%i idx[i]=%i\n ", i, a[i], idx[i]);
64 }
65#undef LEN
66 }
67
68 return TEST_EXIT_CODE;
69}
#define LEN
#define TEST_EXIT_CODE
Definition tests.h:14
#define INC_ERR
Definition tests.h:12
void yac_quicksort_index(int *a, size_t n, int *idx)