2023-11-22 15:31:30 +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-22 15:31:30 +01:00
|
|
|
|
|
|
|
EvalResult execute(string s) {
|
2024-01-03 16:20:42 +01:00
|
|
|
Memory memory;
|
|
|
|
return execute(split_string(s, '\n'), memory);
|
2023-11-22 15:31:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
_TEST_PRESENTATION("Statements");
|
|
|
|
|
|
|
|
_TEST_ASSERT(
|
|
|
|
_TEST_NO_EXCEPTION(get<int>(execute("int x = 0; if (1) x++; x;")) == 1),
|
|
|
|
"If vérifié",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
_TEST_ASSERT(
|
|
|
|
_TEST_NO_EXCEPTION(get<int>(execute("int x = 0; if (0) x++; x;")) == 0),
|
|
|
|
"If pas vérifié",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
_TEST_ASSERT(
|
|
|
|
_TEST_NO_EXCEPTION(get<int>(execute("int x = 1; if (0) x++; else x--; x;")) == 0),
|
|
|
|
"If else pas vérifié",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2023-12-02 15:49:27 +01:00
|
|
|
_TEST_ASSERT(
|
|
|
|
_TEST_NO_EXCEPTION(get<int>(execute("int i = 0; while (i < 100) i++; i;")) == 100),
|
|
|
|
"While",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
_TEST_ASSERT(
|
|
|
|
_TEST_NO_EXCEPTION(get<int>(execute("int i = 0; for (int j = 0; j < 100; j++) { i++; } i;")) == 100),
|
|
|
|
"For",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2023-12-15 10:38:13 +01:00
|
|
|
_TEST_ASSERT(
|
|
|
|
_TEST_NO_EXCEPTION(get<int>(execute("int x; for (int i=0; i < 30; i++) { x=i; if (i==20) break; }; x;")) == 20),
|
|
|
|
"For break",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
_TEST_ASSERT(
|
|
|
|
_TEST_NO_EXCEPTION(get<int>(execute("int x; int i=0; while (i < 30) { x=i; if (i==20) break; i++; }; x;")) == 20),
|
|
|
|
"While break",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2023-12-15 14:25:39 +01:00
|
|
|
_TEST_ASSERT(
|
|
|
|
_TEST_NO_EXCEPTION(get<int>(execute("int x = 0; for (int i = 0; i < 20; i++) { x++; continue; x++; } x;")) == 20),
|
|
|
|
"For continue",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
_TEST_ASSERT(
|
|
|
|
_TEST_NO_EXCEPTION(get<int>(execute("int x = 0; int i = 0; while (i < 20) { i++; if (i % 2 == 0) continue; x++; } x;")) == 10),
|
|
|
|
"While continue",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
2023-11-22 15:31:30 +01:00
|
|
|
return 0;
|
|
|
|
}
|