c-repl/test/bool_logic.cpp
2023-12-08 10:12:23 +01:00

63 lines
1.2 KiB
C++

#include "include/test.h"
#include "../src/include/memory.h"
#include "../src/include/tokenize.h"
#include "../src/include/parser.h"
#include "../src/include/interpreter.h"
int execute(string s) {
Memory<EvalResult> memory;;
vector<Token> tokens = tokenize({ s });
Node ast = parse(tokens);
EvalResult res = eval(ast, memory);
return get<int>(res);
}
int main() {
_TEST_PRESENTATION("Logique Booléenne");
_TEST_ASSERT(
_TEST_NO_EXCEPTION(execute("1 && 0;") == 0),
"Et",
true
);
_TEST_ASSERT(
_TEST_NO_EXCEPTION(execute("1 || 0;") == 1),
"Ou",
true
);
_TEST_ASSERT(
_TEST_NO_EXCEPTION(execute("!1;") == 0),
"Négation",
true
);
_TEST_ASSERT(
_TEST_NO_EXCEPTION(execute("2 == 2;") == 1),
"Égalité",
true
);
_TEST_ASSERT(
_TEST_NO_EXCEPTION(execute("2 != 2;") == 0),
"Différence",
true
);
_TEST_ASSERT(
_TEST_NO_EXCEPTION(execute("0 == 0 || 1;") == 1),
"Parenthésage",
true
);
_TEST_ASSERT(
_TEST_NO_EXCEPTION(execute("2 == 1 + 1;") == 1),
"Priorités",
true
);
return 0;
}