File: test_misc.c

package info (click to toggle)
bart-cuda 0.8.00-2
  • links: PTS, VCS
  • area: contrib
  • in suites: bookworm, sid
  • size: 7,752 kB
  • sloc: ansic: 100,267; python: 717; makefile: 576; sh: 564; cpp: 104
file content (65 lines) | stat: -rw-r--r-- 961 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* Copyright 2019. Martin Uecker.
 * All rights reserved. Use of this source code is governed by
 * a BSD-style license which can be found in the LICENSE file.
 *
 * Authors:
 * 2019 Martin Uecker <martin.uecker@med.uni-goettingen.de>
 */

#include "misc/misc.h"

#include "utest.h"




static bool test_quicksort(void)
{
	int x[5] = { 0, 3, 2, 1, 4 };

	NESTED(int, cmp, (int a, int b))
	{
		return a - b;
	};

	quicksort(5, x, cmp);

	for (int i = 0; i < 5; i++)
		if (i != x[i])
			return false;

	return true;
}

UT_REGISTER_TEST(test_quicksort);




static bool test_quicksort2(void)
{
	int x[6] = { 0, 1, 2, 3, 4, 5 };
	int d[6] = { 0, 4, 2, 2, 4, 2 };
	int g[6] = { 0, 2, 2, 2, 4, 4 };

	__block const int* dp = d; // clang workaround

	NESTED(int, cmp2, (int a, int b))
	{
		return dp[a] - dp[b];
	};

	quicksort(6, x, cmp2);

	for (int i = 0; i < 6; i++)
		if (g[i] != d[x[i]])
			return false;

	return true;
}


UT_REGISTER_TEST(test_quicksort2);