25 lines
597 B
C++
25 lines
597 B
C++
|
#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");
|
||
|
|
||
|
_TEST_ASSERT(execute("10 + 3 * (7 - 2);") == 25, "Priorités");
|
||
|
|
||
|
_TEST_ASSERT(execute("12 - 4 - 20;") == -12, "Ordre de soustraction");
|
||
|
|
||
|
_TEST_ASSERT(execute("-7 + 13 + -6;") == 0, "Opérateurs unaires");
|
||
|
|
||
|
return 0;
|
||
|
}
|