2023-11-10 22:24:14 +01:00
|
|
|
#include "include/test.h"
|
|
|
|
|
|
|
|
#include "../src/include/tokenize.h"
|
|
|
|
#include "../src/include/parser.h"
|
|
|
|
#include "../src/include/interpreter.h"
|
|
|
|
|
|
|
|
int execute(string s) {
|
|
|
|
vector<Token> tokens = tokenize(s);
|
|
|
|
Node ast = parse(tokens);
|
|
|
|
EvalResult res = eval(ast);
|
|
|
|
|
|
|
|
return get<int>(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
_TEST_PRESENTATION("Expressions Arithmétiques");
|
|
|
|
|
2023-11-14 17:03:42 +01:00
|
|
|
_TEST_ASSERT(
|
|
|
|
_TEST_NO_EXCEPTION(execute("10 + 3 * (7 - 2);") == 25),
|
2023-11-15 11:59:38 +01:00
|
|
|
"Priorités",
|
|
|
|
true
|
2023-11-14 17:03:42 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
_TEST_ASSERT(
|
|
|
|
_TEST_NO_EXCEPTION(execute("12 - 4 - 20;") == -12),
|
2023-11-15 11:59:38 +01:00
|
|
|
"Ordre de soustraction",
|
|
|
|
true
|
2023-11-14 17:03:42 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
_TEST_ASSERT(
|
|
|
|
_TEST_NO_EXCEPTION(execute("-7 + 13 + -6;") == 0),
|
2023-11-15 11:59:38 +01:00
|
|
|
"Opérateurs unaires",
|
|
|
|
true
|
2023-11-14 17:03:42 +01:00
|
|
|
);
|
2023-11-10 22:24:14 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|