aboutsummaryrefslogtreecommitdiff
path: root/tests/src/test_gensvm_init.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/test_gensvm_init.c')
-rw-r--r--tests/src/test_gensvm_init.c66
1 files changed, 63 insertions, 3 deletions
diff --git a/tests/src/test_gensvm_init.c b/tests/src/test_gensvm_init.c
index 8cacd9b..16f5dfd 100644
--- a/tests/src/test_gensvm_init.c
+++ b/tests/src/test_gensvm_init.c
@@ -8,7 +8,7 @@
#include "minunit.h"
#include "gensvm_init.h"
-char *test_init_null()
+char *test_init_null_dense()
{
int i;
long n = 5,
@@ -63,9 +63,68 @@ char *test_init_null()
return NULL;
}
-char *test_init_seed()
+char *test_init_null_sparse()
{
+ int i;
+ long n = 5,
+ m = 2,
+ K = 3;
+ double value;
+ struct GenModel *model = gensvm_init_model();
+ struct GenData *data = gensvm_init_data();
+
+ // start test code
+ model->n = n;
+ model->m = m;
+ model->K = K;
+ gensvm_allocate_model(model);
+
+ data->n = n;
+ data->m = m;
+ data->K = K;
+ data->RAW = Calloc(double, n*(m+1));
+ for (i=0; i<n; i++) {
+ matrix_set(data->RAW, m+1, i, 0, 1.0);
+ matrix_set(data->RAW, m+1, i, 1, i);
+ matrix_set(data->RAW, m+1, i, 2, -i);
+ }
+
+ data->Z = data->RAW;
+ data->spZ = gensvm_dense_to_sparse(data->Z, n, m+1);
+ free(data->RAW);
+ data->RAW = NULL;
+ data->Z = NULL;
+
+ gensvm_init_V(NULL, model, data);
+ // first row all ones
+ value = matrix_get(model->V, K-1, 0, 0);
+ mu_assert(value == 1.0, "Incorrect value at 0, 0");
+ value = matrix_get(model->V, K-1, 0, 1);
+ mu_assert(value == 1.0, "Incorrect value at 0, 1");
+
+ // second row between -1 and 0.25
+ value = matrix_get(model->V, K-1, 1, 0);
+ mu_assert(value >= -1.0 && value <= 0.25, "Incorrect value at 1, 0");
+ value = matrix_get(model->V, K-1, 1, 1);
+ mu_assert(value >= -1.0 && value <= 0.25, "Incorrect value at 1, 1");
+
+ // third row between -0.25 and 1
+ value = matrix_get(model->V, K-1, 2, 0);
+ mu_assert(value >= -0.25 && value <= 1.0, "Incorrect value at 2, 0");
+ value = matrix_get(model->V, K-1, 2, 1);
+ mu_assert(value >= -0.25 && value <= 1.0, "Incorrect value at 2, 1");
+
+ // end test code
+
+ gensvm_free_model(model);
+ gensvm_free_data(data);
+
+ return NULL;
+}
+
+char *test_init_seed()
+{
long n = 7,
m = 5,
K = 3;
@@ -203,7 +262,8 @@ char *test_init_weights_wrong()
char *all_tests()
{
mu_suite_start();
- mu_run_test(test_init_null);
+ mu_run_test(test_init_null_dense);
+ mu_run_test(test_init_null_sparse);
mu_run_test(test_init_seed);
mu_run_test(test_init_weights_1);
mu_run_test(test_init_weights_2);