#!/bin/sh
set -e

WORKDIR=$(mktemp -d)
trap 'rm -rf "$WORKDIR"' EXIT

cat << 'EOF' > "$WORKDIR/test.c"
#include <stdio.h>
#include <lrcalc/alloc.h>
#include <lrcalc/ivector.h>
#include <lrcalc/ivlincomb.h>
#include <lrcalc/schur.h>

int main(void) {
    ivector *x = iv_new(2);
    x->array[0] = 2;
    x->array[1] = 1;
    ivector *y = iv_new(2);
    y->array[0] = 2;
    y->array[1] = 1;
    ivlincomb *res = schur_mult(x, y, 2, 2, 2);
    if (!res) {
        fprintf(stderr, "schur_mult returned NULL\n");
        return 1;
    }
    printf("schur_mult C test passed.\n");
    iv_free(x);
    iv_free(y);
    ivlc_free_all(res);
    return 0;
}
EOF

gcc -Wall -Wextra "$WORKDIR/test.c" -llrcalc -o "$WORKDIR/test"
"$WORKDIR/test"
echo "C library compilation test passed successfully."
