#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 memory = Memory(); vector tokens = tokenize({ s }); Node ast = parse(tokens); EvalResult res = eval(ast, memory); return get(res); } int main() { _TEST_PRESENTATION("Expressions Arithmétiques"); _TEST_ASSERT( _TEST_NO_EXCEPTION(execute("10 + 3 * (7 - 2);") == 25), "Priorités", true ); _TEST_ASSERT( _TEST_NO_EXCEPTION(execute("12 - 4 - 20;") == -12), "Ordre de soustraction", true ); _TEST_ASSERT( _TEST_NO_EXCEPTION(execute("-7 + 13 + -6;") == 0), "Opérateurs unaires", true ); _TEST_ASSERT( _TEST_IS_EXCEPTION(execute("1 / (5 - 5);"), RuntimeError), "Division par 0", true ); _TEST_ASSERT( _TEST_IS_EXCEPTION(execute("1 % (5 - 5);"), RuntimeError), "Modulo par 0", true ); return 0; }