2023-11-10 22:24:14 +01:00
|
|
|
#include "include/test.h"
|
|
|
|
|
2024-01-03 16:20:42 +01:00
|
|
|
#include "../src/include/execute.h"
|
|
|
|
#include "../src/include/utils.h"
|
2023-11-10 22:24:14 +01:00
|
|
|
|
|
|
|
int execute(string s) {
|
2024-01-03 16:20:42 +01:00
|
|
|
Memory memory;
|
|
|
|
return get<int>(execute(split_string(s, '\n'), memory));
|
2023-11-10 22:24:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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-27 21:16:39 +01:00
|
|
|
"Parenthésage",
|
2023-11-15 11:59:38 +01:00
|
|
|
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
|
|
|
|
2023-11-15 16:10:36 +01:00
|
|
|
_TEST_ASSERT(
|
2023-12-15 15:10:05 +01:00
|
|
|
_TEST_IS_EXCEPTION(execute("1 / 0;"), ErrorType::DivisionByZero),
|
2023-11-15 16:10:36 +01:00
|
|
|
"Division par 0",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
_TEST_ASSERT(
|
2023-12-15 15:10:05 +01:00
|
|
|
_TEST_IS_EXCEPTION(execute("1 % 0;"), ErrorType::ModuloByZero),
|
2023-11-15 16:10:36 +01:00
|
|
|
"Modulo par 0",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2023-11-22 15:31:30 +01:00
|
|
|
_TEST_ASSERT(
|
|
|
|
_TEST_NO_EXCEPTION(execute("int a = 27; ++a;") == 28),
|
|
|
|
"Incrémentation par la gauche",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
_TEST_ASSERT(
|
|
|
|
_TEST_NO_EXCEPTION(execute("int a = 27; a--;") == 27),
|
|
|
|
"Décrémentation par la droite",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
_TEST_ASSERT(
|
|
|
|
_TEST_NO_EXCEPTION(execute("int a = 27; -(+-++a);") == 28),
|
|
|
|
"Incrémentation et opérations unaires",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2023-11-27 21:16:39 +01:00
|
|
|
_TEST_ASSERT(
|
|
|
|
_TEST_NO_EXCEPTION(execute("1 < 2;") == 1),
|
|
|
|
"Inférieur strict",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
_TEST_ASSERT(
|
|
|
|
_TEST_NO_EXCEPTION(execute("2 > 3;") == 0),
|
|
|
|
"Supérieur strict",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
_TEST_ASSERT(
|
|
|
|
_TEST_NO_EXCEPTION(execute("2 <= 1;") == 0),
|
|
|
|
"Inférieur ou égal",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
_TEST_ASSERT(
|
|
|
|
_TEST_NO_EXCEPTION(execute("2 >= 1;") == 1),
|
|
|
|
"Supérieur ou égal",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2023-11-10 22:24:14 +01:00
|
|
|
return 0;
|
|
|
|
}
|