// Simplifica varias fórmulas y cuenta cuántos nodos quedan.
#include <stdio.h>

#include "logic.h"

static int show_simplified(Logic *e) {
    if (e == NULL) {
        fprintf(stderr, "no hay memoria\n");
        return 0;
    }
    int before = logic_count(e);
    logic_print(e, stdout);
    e = logic_simplify(e);
    printf("  ->  ");
    logic_print(e, stdout);
    printf("  (nodos: de %d a %d)\n", before, logic_count(e));
    logic_free(e);
    return 1;
}

int main(void) {
    int ok = show_simplified(logic_and(logic_input('a'), logic_constant(1)));
    ok = show_simplified(logic_and(logic_or(logic_input('a'), logic_input('b')), logic_constant(0))) && ok;
    ok = show_simplified(logic_not(logic_not(logic_input('a')))) && ok;
    ok = show_simplified(logic_or(logic_and(logic_constant(1), logic_input('a')), logic_not(logic_constant(1)))) && ok;
    ok = show_simplified(logic_and(logic_input('a'), logic_or(logic_input('b'), logic_input('c')))) && ok;
    return ok ? 0 : 1;
}
