Update tests

This commit is contained in:
augustin64 2024-01-03 17:51:27 +01:00
parent e9fb7c1e2b
commit 1553df6328
2 changed files with 48 additions and 4 deletions

View File

@ -30,29 +30,73 @@ int main() {
);
_TEST_ASSERT(
_TEST_NO_EXCEPTION(holds_alternative<monostate>(execute("double a(int b, double c, int d) { return b+c+d; };"))),
_TEST_NO_EXCEPTION(holds_alternative<monostate>(execute(R"(
double a(int b, double c, int d) {
return b+c+d;
}
)"))),
"Déclaration de fonction",
true
);
_TEST_ASSERT(
_TEST_IS_EXCEPTION(execute("int a(int b) { int c(int d) {return d;} return c(b); };"), ErrorType::NestedFunction),
_TEST_IS_EXCEPTION(execute(R"(
int a(int b) {
int c(int d) {
return d;
}
return c(b);
};
)"),
ErrorType::NestedFunction
),
"Fonctions imbriquées",
true
);
_TEST_ASSERT(
_TEST_NO_EXCEPTION(get<int>(execute("int sum(int a, int b) {return a+b;}; sum(20, 7);")) == 27),
_TEST_NO_EXCEPTION(get<int>(execute(R"(
int sum(int a, int b) {
return a+b;
}
sum(20, 7);
)")) == 27),
"Exécution de fonction",
true
);
_TEST_ASSERT(
_TEST_NO_EXCEPTION(get<int>(execute("int recurse(int a) {if (a < 27) {return recurse(a+1);} else {return a;}}; recurse(0);")) == 27),
_TEST_NO_EXCEPTION(get<int>(execute(R"(
int recurse(int a) {
if (a < 27)
return recurse(a+1);
else
return a;
};
recurse(0);
)")) == 27),
"Fonction récursive",
true
);
_TEST_ASSERT(
_TEST_NO_EXCEPTION(get<int>(execute(R"(
int x(int a);
int y(int a) {
return x(a);
}
int x(int a) {
if (a < 75) {
return y(a+1);
}
return a;
}
x(0);
)")) == 75),
"Fonctions mutuellement récursives",
true
);
return 0;
}