Skip to content

Commit f3d17b2

Browse files
authored
Merge pull request #1 from dance858/adding-tests
Adds tests to begin familiarizing with the diff engine.
2 parents 10fc76b + dd46030 commit f3d17b2

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

tests/all_tests.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ int main(void)
5353

5454
printf("\n--- Jacobian Tests ---\n");
5555
mu_run_test(test_jacobian_log, tests_run);
56+
mu_run_test(test_jacobian_log_matrix, tests_run);
5657
mu_run_test(test_jacobian_composite_log, tests_run);
5758
mu_run_test(test_jacobian_composite_log_add, tests_run);
5859
mu_run_test(test_jacobian_rel_entr_vector_args_1, tests_run);

tests/jacobian_tests/test_log.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,22 @@ const char *test_jacobian_log()
2424
free_expr(u);
2525
return 0;
2626
}
27+
28+
const char *test_jacobian_log_matrix()
29+
{
30+
double u_vals[7] = {0.0, 0.0, 0.0, 1.0, 2.0, 4.0, 5.0};
31+
double expected_Ax[4] = {1.0, 0.5, 0.25, 0.2};
32+
int expected_Ap[5] = {0, 1, 2, 3, 4};
33+
int expected_Ai[4] = {3, 4, 5, 6};
34+
expr *u = new_variable(2, 2, 3, 7);
35+
expr *log_node = new_log(u);
36+
log_node->forward(log_node, u_vals);
37+
log_node->jacobian_init(log_node);
38+
log_node->eval_jacobian(log_node);
39+
mu_assert("vals fail", cmp_double_array(log_node->jacobian->x, expected_Ax, 4));
40+
mu_assert("rows fail", cmp_int_array(log_node->jacobian->p, expected_Ap, 5));
41+
mu_assert("cols fail", cmp_int_array(log_node->jacobian->i, expected_Ai, 4));
42+
free_expr(log_node);
43+
free_expr(u);
44+
return 0;
45+
}

0 commit comments

Comments
 (0)