GenSVM
test_gensvm_consistency.c
Go to the documentation of this file.
1 
27 #include "minunit.h"
28 #include "gensvm_consistency.h"
29 
31 {
32  double a = 1.0;
33  double b = 2.0;
34 
35  mu_assert(gensvm_dsort(&b, &a) == true, "Incorrect doublesort (1)");
36  mu_assert(gensvm_dsort(&a, &b) == false, "Incorrect doublesort (2)");
37  mu_assert(gensvm_dsort(&a, &a) == false, "Incorrect doublesort (3)");
38 
39  return NULL;
40 }
41 
43 {
44  double *values = Malloc(double, 1);
45  values[0] = 0.1368311165400936;
46 
47  // start test code //
48  mu_assert(fabs(gensvm_percentile(values, 1, 25.0) -
49  0.1368311165400936) < 1e-16,
50  "Incorrect percentile");
51  // end test code //
52  free(values);
53 
54  return NULL;
55 }
56 
58 {
59  double *values = Malloc(double, 10);
60  values[0] = 0.1368311165400936;
61  values[1] = 0.0864373686918369;
62  values[2] = 0.9959483430066688;
63  values[3] = 0.2946638351338509;
64  values[4] = 0.3535927892606028;
65  values[5] = 0.5898175818278500;
66  values[6] = 0.1769525979717794;
67  values[7] = 0.3114487168265636;
68  values[8] = 0.3895012665017124;
69  values[9] = 0.3229492282960943;
70 
71  // start test code //
72  mu_assert(fabs(gensvm_percentile(values, 10, 25.0) -
73  0.176952597971779) < 1e-14,
74  "Incorrect 25th percentile");
75  mu_assert(fabs(gensvm_percentile(values, 10, 50.0) -
76  0.317198972561329) < 1e-14,
77  "Incorrect 50th percentile");
78  mu_assert(fabs(gensvm_percentile(values, 10, 75.0) -
79  0.389501266501712) < 1e-14,
80  "Incorrect 75th percentile");
81  mu_assert(fabs(gensvm_percentile(values, 10, 90.0) -
82  0.792882962417259) < 1e-14,
83  "Incorrect 90th percentile");
84  // end test code //
85  free(values);
86 
87  return NULL;
88 }
89 
91 {
92  int i, N = 10;
93  struct GenQueue *q = gensvm_init_queue();
94  q->tasks = Malloc(struct GenTask *, N);
95  q->N = N;
96  for (i=0; i<N; i++) {
97  q->tasks[i] = gensvm_init_task();
98  q->tasks[i]->ID = i+1;
99  }
100 
101  q->tasks[0]->performance = 0.1368311165400936;
102  q->tasks[1]->performance = 0.0864373686918369;
103  q->tasks[2]->performance = 0.9959483430066688; //
104  q->tasks[3]->performance = 0.2946638351338509;
105  q->tasks[4]->performance = 0.3535927892606028;
106  q->tasks[5]->performance = 0.5898175818278500; //
107  q->tasks[6]->performance = 0.1769525979717794;
108  q->tasks[7]->performance = 0.3114487168265636;
109  q->tasks[8]->performance = 0.3895012665017124; //
110  q->tasks[9]->performance = 0.3229492282960943;
111 
112  // start test code //
113 
114  // boundary should be determined at: 0.389501266501712
115  struct GenQueue *nq = gensvm_top_queue(q, 75.0);
116  mu_assert(nq->N == 3, "Incorrect size of top queue");
117 
118  // end test code //
120  gensvm_free_queue(nq);
121 
122  return NULL;
123 }
124 
126 {
127  mu_test_missing();
128 
129  return NULL;
130 }
131 
132 char *all_tests()
133 {
134  mu_suite_start();
140 
141  return NULL;
142 }
143 
Minimal unit testing framework for C.
struct GenQueue * gensvm_init_queue(void)
Initialize a GenQueue structure.
Definition: gensvm_queue.c:38
long ID
numeric id of the task in the queue
Definition: gensvm_task.h:62
#define mu_assert(test, message)
Definition: minunit.h:29
char * test_percentile()
char * all_tests()
struct GenTask * gensvm_init_task(void)
Initialize a GenTask structure.
Definition: gensvm_task.c:38
long N
size of task array
Definition: gensvm_queue.h:50
long i
index used for keeping track of the queue
Definition: gensvm_queue.h:52
double gensvm_percentile(double *values, long N, double p)
Calculate the percentile of an array of doubles.
char * test_doublesort()
double performance
performance after cross validation
Definition: gensvm_task.h:84
struct GenQueue * gensvm_top_queue(struct GenQueue *q, double percentile)
Create GenQueue of tasks with performance above a given percentile.
#define Malloc(type, size)
Definition: gensvm_memory.h:48
#define mu_run_test(test)
Definition: minunit.h:35
Simple task queue.
Definition: gensvm_queue.h:47
char * test_consistency_repeats()
#define mu_test_missing()
Definition: minunit.h:60
char * test_percentile_1()
int gensvm_dsort(const void *elem1, const void *elem2)
Comparison function for doubl.
void gensvm_free_queue(struct GenQueue *q)
Free the GenQueue struct.
Definition: gensvm_queue.c:59
A structure for a single task in the queue.
Definition: gensvm_task.h:55
Header file for gensvm_consistency.c.
char * test_top_queue()
struct GenTask ** tasks
array of pointers to Task structs
Definition: gensvm_queue.h:48
RUN_TESTS(all_tests)
#define mu_suite_start()
Definition: minunit.h:24