Skip to content
Snippets Groups Projects
Commit 0e2bc83c authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add tests for tuple -> R^d conversion as function arguments

parent 72b3ce3d
No related branches found
No related tags found
1 merge request!37Feature/language
......@@ -584,6 +584,51 @@ f(0);
CHECK_AST(data, result);
}
SECTION("Arguments tuple -> R^d")
{
std::string_view data = R"(
let f: R^3 -> R, x -> x[0]+x[1]+x[2];
f((1,2,3));
)";
std::string_view result = R"(
(root:ASTNodeListProcessor)
`-(language::function_evaluation:FunctionProcessor)
+-(language::name:f:NameProcessor)
`-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor, 3ul>)
+-(language::integer:1:ValueProcessor)
+-(language::integer:2:ValueProcessor)
`-(language::integer:3:ValueProcessor)
)";
CHECK_AST(data, result);
}
SECTION("Arguments compound with tuple")
{
std::string_view data = R"(
let f: R*R^3*R^2->R, (t,x,y) -> t*(x[0]+x[1]+x[2])*y[0]+y[1];
f(2,(1,2,3),(2,1.3));
)";
std::string_view result = R"(
(root:ASTNodeListProcessor)
`-(language::function_evaluation:FunctionProcessor)
+-(language::name:f:NameProcessor)
`-(language::function_argument_list:ASTNodeExpressionListProcessor)
+-(language::integer:2:ValueProcessor)
+-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor, 3ul>)
| +-(language::integer:1:ValueProcessor)
| +-(language::integer:2:ValueProcessor)
| `-(language::integer:3:ValueProcessor)
`-(language::tuple_expression:TupleToVectorProcessor<ASTNodeExpressionListProcessor, 2ul>)
+-(language::integer:2:ValueProcessor)
`-(language::real:1.3:ValueProcessor)
)";
CHECK_AST(data, result);
}
}
SECTION("errors")
......@@ -724,5 +769,68 @@ prev(3 + .24);
CHECK_AST_THROWS_WITH(data, std::string{"invalid implicit conversion: R -> Z"});
}
}
SECTION("arguments invalid tuple -> R^d conversion")
{
SECTION("tuple[3] -> R^2")
{
std::string_view data = R"(
let f : R^2 -> R, x->x[0];
f((1,2,3));
)";
CHECK_AST_THROWS_WITH(data, std::string{"incompatible dimensions in affectation"});
}
SECTION("tuple[2] -> R^3")
{
std::string_view data = R"(
let f : R^3 -> R, x->x[0];
f((1,2));
)";
CHECK_AST_THROWS_WITH(data, std::string{"incompatible dimensions in affectation"});
}
SECTION("compound tuple[3] -> R^2")
{
std::string_view data = R"(
let f : R*R^2 -> R, (t,x)->x[0];
f(1,(1,2,3));
)";
CHECK_AST_THROWS_WITH(data, std::string{"incompatible dimensions in affectation"});
}
SECTION("compound tuple[2] -> R^3")
{
std::string_view data = R"(
let f : R^3*R^2 -> R, (x,y)->x[0]*y[1];
f((1,2),(3,4));
)";
CHECK_AST_THROWS_WITH(data, std::string{"incompatible dimensions in affectation"});
}
SECTION("list instead of tuple -> R^3")
{
std::string_view data = R"(
let f : R^3 -> R, x -> x[0]*x[1];
f(1,2,3);
)";
CHECK_AST_THROWS_WITH(data, std::string{"bad number of arguments: expecting 1, provided 3"});
}
SECTION("list instead of tuple -> R^3*R^2")
{
std::string_view data = R"(
let f : R^3*R^2 -> R, (x,y) -> x[0]*x[1]-y[0];
f((1,2,3),2,3);
)";
CHECK_AST_THROWS_WITH(data, std::string{"bad number of arguments: expecting 2, provided 3"});
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment