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
|
/**
* @file test_gensvm_debug.c
* @author Gertjan van den Burg
* @date September, 2016
* @brief Unit tests for gensvm_io.c functions
*/
#include "minunit.h"
#include "gensvm_debug.h"
extern FILE *GENSVM_OUTPUT_FILE;
char *test_print_matrix()
{
FILE *fid = NULL;
GENSVM_OUTPUT_FILE = fopen("./data/test_debug_print.txt", "w");
double *mat = Calloc(double, 3*2);
matrix_set(mat, 2, 0, 0, -0.241053050258449);
matrix_set(mat, 2, 0, 1, -0.599809408260836);
matrix_set(mat, 2, 1, 0, 0.893318163305108);
matrix_set(mat, 2, 1, 1, -0.344057630469285);
matrix_set(mat, 2, 2, 0, 0.933948479216127);
matrix_set(mat, 2, 2, 1, -0.474352026604967);
// start test code //
gensvm_print_matrix(mat, 3, 2);
fclose(GENSVM_OUTPUT_FILE);
char buffer[MAX_LINE_LENGTH];
fid = fopen("./data/test_debug_print.txt", "r");
fgets(buffer, MAX_LINE_LENGTH, fid);
mu_assert(strcmp(buffer, "-0.241053 -0.599809\n") == 0,
"Line doesn't contain expected content (0).\n");
fgets(buffer, MAX_LINE_LENGTH, fid);
mu_assert(strcmp(buffer, "+0.893318 -0.344058\n") == 0,
"Line doesn't contain expected content (1).\n");
fgets(buffer, MAX_LINE_LENGTH, fid);
mu_assert(strcmp(buffer, "+0.933948 -0.474352\n") == 0,
"Line doesn't contain expected content (2).\n");
fclose(fid);
// end test code //
free(mat);
return NULL;
}
char *all_tests()
{
mu_suite_start();
mu_run_test(test_print_matrix);
return NULL;
}
RUN_TESTS(all_tests);
|