aboutsummaryrefslogtreecommitdiff
path: root/tests/src/test_gensvm_checks.c
blob: 9b163be0f938e6f6b627b410caafafd12991bc53 (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/**
 * @file test_gensvm_checks.c
 * @author G.J.J. van den Burg
 * @date 2016-12-07
 * @brief Unit tests for gensvm_checks.c functions
 *
 * @copyright
 Copyright 2016, G.J.J. van den Burg.

 This file is part of GenSVM.

 GenSVM is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 GenSVM is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with GenSVM. If not, see <http://www.gnu.org/licenses/>.

 */

#include "minunit.h"
#include "gensvm_checks.h"

char *test_check_outcome_contiguous_correct()
{
	struct GenData *data = gensvm_init_data();
	data->n = 10;
	data->y = Calloc(long, data->n);
	data->y[0] = 1;
	data->y[1] = 2;
	data->y[2] = 3;
	data->y[3] = 4;
	data->y[4] = 1;
	data->y[5] = 1;
	data->y[6] = 2;
	data->y[7] = 2;
	data->y[8] = 4;
	data->y[9] = 3;

	// start test code //
	mu_assert(gensvm_check_outcome_contiguous(data) == true, 
			"Incorrect check outcome for correct");
	// end test code //

	gensvm_free_data(data);

	return NULL;
}

char *test_check_outcome_contiguous_gap()
{
	struct GenData *data = gensvm_init_data();
	data->n = 10;
	data->y = Calloc(long, data->n);
	data->y[0] = 1;
	data->y[1] = 2;
	data->y[2] = 4;
	data->y[3] = 4;
	data->y[4] = 1;
	data->y[5] = 1;
	data->y[6] = 2;
	data->y[7] = 2;
	data->y[8] = 4;
	data->y[9] = 4;

	// start test code //
	mu_assert(gensvm_check_outcome_contiguous(data) == false, 
			"Incorrect check outcome for gap");
	// end test code //

	gensvm_free_data(data);

	return NULL;
}

char *test_check_outcome_contiguous_gaps()
{
	struct GenData *data = gensvm_init_data();
	data->n = 10;
	data->y = Calloc(long, data->n);
	data->y[0] = 1;
	data->y[1] = 6;
	data->y[2] = 4;
	data->y[3] = 4;
	data->y[4] = 1;
	data->y[5] = 1;
	data->y[6] = 6;
	data->y[7] = 6;
	data->y[8] = 4;
	data->y[9] = 4;

	// start test code //
	mu_assert(gensvm_check_outcome_contiguous(data) == false, 
			"Incorrect check outcome for gaps");
	// end test code //

	gensvm_free_data(data);

	return NULL;
}

char *test_check_outcome_contiguous_shift()
{
	struct GenData *data = gensvm_init_data();
	data->n = 10;
	data->y = Calloc(long, data->n);
	data->y[0] = 2;
	data->y[1] = 3;
	data->y[2] = 4;
	data->y[3] = 5;
	data->y[4] = 2;
	data->y[5] = 3;
	data->y[6] = 3;
	data->y[7] = 4;
	data->y[8] = 5;
	data->y[9] = 5;

	// start test code //
	mu_assert(gensvm_check_outcome_contiguous(data) == false, 
			"Incorrect check outcome for shift");
	// end test code //

	gensvm_free_data(data);

	return NULL;
}

char *all_tests()
{
	mu_suite_start();

	mu_run_test(test_check_outcome_contiguous_correct);
	mu_run_test(test_check_outcome_contiguous_gap);
	mu_run_test(test_check_outcome_contiguous_gaps);
	mu_run_test(test_check_outcome_contiguous_shift);

	return NULL;
}

RUN_TESTS(all_tests);