summaryrefslogtreecommitdiff
path: root/tests.c
blob: 416abcdc1bc2df7a0074b8f2e5d2721a6d0ead7b (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
#include "tests.h"

#include "matrix.h"

#include <assert.h>

void test_LR()
{
    Matrix *A = matrix_from_str("[2 3 1;4 1 -5;-1 2 3]");
    Matrix *b = matrix_from_str("[-1;2;3]");

    Matrix **LR = matrix_LR(A, b);
    Matrix *L = LR[0];
    Matrix *R = LR[1];
    Matrix *y = matrix_forwardel(L, b);
    Matrix *x = matrix_backsubst(R, y);

    assert(matrix_eq(matrix_mult(A, x), b, 0.01));
}

void run_tests()
{
    test_LR();
}