#include "../../../gen/l1/geom.h"

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

float random_float(float a, float b){
    int r = rand();
    return a + (b - a) * ((float)r / (float)RAND_MAX);
}

float random_float100(){
    return random_float(-100, 100);
}

mat4 random_big_matrix(){
    return mat4_new(random_float100(), random_float100(), random_float100(), random_float100(),
        random_float100(), random_float100(), random_float100(), random_float100(),
        random_float100(), random_float100(), random_float100(), random_float100(),
        random_float100(), random_float100(), random_float100(), random_float100());
}

mat2 random_smol_matrix(){
    return mat2_new(random_float100(), random_float100(), random_float100(), random_float100());
}

#define flPr "%02.05f"

void test_mat4(mat4 A){
    mat4 iA = mat4_inverse(A);
    mat4 product = mat4_mul_mat4(iA, A);
    printf(flPr " " flPr " " flPr " " flPr "\n"
           flPr " " flPr " " flPr " " flPr "\n"
           flPr " " flPr " " flPr " " flPr "\n"
           flPr " " flPr " " flPr " " flPr "\n",
        product.x.x, product.y.x, product.z.x, product.w.x,
        product.x.y, product.y.y, product.z.y, product.w.y,
        product.x.z, product.y.z, product.z.z, product.w.z,
        product.x.w, product.y.w, product.z.w, product.w.w);
}

void test_mat2(mat2 A){
    mat2 iA = mat2_inverse(A);
    mat2 product = mat2_mul_mat2(iA, A);
    printf(flPr " " flPr "\n"
           flPr " " flPr "\n",
        product.x.x, product.y.x,
        product.x.y, product.y.y);
}

void test(){
    mat2x3 A = (mat2x3){.x = {1, 2, 3}, .y = {4, 5, 6}};
    mat3x2 At = mat2x3_transpose(A);
    assert(At.x.x == 1);
    assert(At.x.y == 4);
    assert(At.y.x == 2);
    assert(At.y.y == 5);
    assert(At.z.x == 3);
    assert(At.z.y == 6);
}

int main() {
    test();
    test_mat4(random_big_matrix());
    test_mat4(random_big_matrix());
    test_mat4(random_big_matrix());
    test_mat4(random_big_matrix());
    test_mat4(random_big_matrix());
    test_mat4(random_big_matrix());
    test_mat4(random_big_matrix());
    test_mat2(random_smol_matrix());
    test_mat2(random_smol_matrix());
    test_mat2(random_smol_matrix());
    test_mat2(random_smol_matrix());
}
