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

Add missing compatibility check when affecting lists to R^d or R^dxd

Add also a few missing tests
parent 015d2fd5
No related branches found
No related tags found
1 merge request!89Add missing compatibility check when affecting lists to R^d or R^dxd
...@@ -37,6 +37,12 @@ ASTNodeAffectationExpressionBuilder::ASTNodeAffectationExpressionBuilder(ASTNode ...@@ -37,6 +37,12 @@ ASTNodeAffectationExpressionBuilder::ASTNodeAffectationExpressionBuilder(ASTNode
ASTNode& lhs_node = *node.children[0]; ASTNode& lhs_node = *node.children[0];
ASTNode& rhs_node = *node.children[1]; ASTNode& rhs_node = *node.children[1];
if (rhs_node.m_data_type == ASTNodeDataType::list_t) {
if ((lhs_node.m_data_type == ASTNodeDataType::vector_t) or (lhs_node.m_data_type == ASTNodeDataType::matrix_t)) {
ASTNodeNaturalConversionChecker(rhs_node, lhs_node.m_data_type);
}
}
node.m_node_processor = optional_processor_builder.value()->getNodeProcessor(lhs_node, rhs_node); node.m_node_processor = optional_processor_builder.value()->getNodeProcessor(lhs_node, rhs_node);
} else { } else {
std::ostringstream error_message; std::ostringstream error_message;
......
...@@ -482,6 +482,13 @@ TEST_CASE("AffectationProcessor", "[language]") ...@@ -482,6 +482,13 @@ TEST_CASE("AffectationProcessor", "[language]")
CHECK_AFFECTATION_THROWS_WITH("let x : R^2, x = 3.2;", "undefined affectation type: R^2 = R"); CHECK_AFFECTATION_THROWS_WITH("let x : R^2, x = 3.2;", "undefined affectation type: R^2 = R");
CHECK_AFFECTATION_THROWS_WITH("let x : R^3, x = 2.3;", "undefined affectation type: R^3 = R"); CHECK_AFFECTATION_THROWS_WITH("let x : R^3, x = 2.3;", "undefined affectation type: R^3 = R");
CHECK_AFFECTATION_THROWS_WITH("let x : R^1; let y : R^1x1, y = 1; x = y;",
"undefined affectation type: R^1 = R^1x1");
CHECK_AFFECTATION_THROWS_WITH("let x : R^2; let y : R^2x2, y = (1,2,4,4); x = y;",
"undefined affectation type: R^2 = R^2x2");
CHECK_AFFECTATION_THROWS_WITH("let x : R^3; let y : R^3x3, y = (1,2,3,4,5,6,7,8,9); x = y;",
"undefined affectation type: R^3 = R^3x3");
CHECK_AFFECTATION_THROWS_WITH("let x : R^2, x = 4;", "invalid integral value (0 is the solely valid value)"); CHECK_AFFECTATION_THROWS_WITH("let x : R^2, x = 4;", "invalid integral value (0 is the solely valid value)");
CHECK_AFFECTATION_THROWS_WITH("let x : R^3, x = 3;", "invalid integral value (0 is the solely valid value)"); CHECK_AFFECTATION_THROWS_WITH("let x : R^3, x = 3;", "invalid integral value (0 is the solely valid value)");
...@@ -499,6 +506,65 @@ TEST_CASE("AffectationProcessor", "[language]") ...@@ -499,6 +506,65 @@ TEST_CASE("AffectationProcessor", "[language]")
"undefined affectation type: R^1 = R^3"); "undefined affectation type: R^1 = R^3");
CHECK_AFFECTATION_THROWS_WITH("let x : R^3, x = 0; let y : R^2, y = x;", CHECK_AFFECTATION_THROWS_WITH("let x : R^3, x = 0; let y : R^2, y = x;",
"undefined affectation type: R^2 = R^3"); "undefined affectation type: R^2 = R^3");
CHECK_AFFECTATION_THROWS_WITH("let x : R^1, x = (1,2);", "undefined affectation type: R^1 = list");
CHECK_AFFECTATION_THROWS_WITH("let x : R^2, x = (1,2,3);",
"incompatible dimensions in affectation: expecting 2, but provided 3");
CHECK_AFFECTATION_THROWS_WITH("let x : R^3, x = (1,2);",
"incompatible dimensions in affectation: expecting 3, but provided 2");
CHECK_AFFECTATION_THROWS_WITH("let x : R^3, x = (1,2,3,4);",
"incompatible dimensions in affectation: expecting 3, but provided 4");
}
SECTION("-> R^nxn")
{
CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2, x = \"foobar\";", "undefined affectation type: R^2x2 = string");
CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3, x = \"foobar\";", "undefined affectation type: R^3x3 = string");
CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2, x = 3.2;", "undefined affectation type: R^2x2 = R");
CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3, x = 2.3;", "undefined affectation type: R^3x3 = R");
CHECK_AFFECTATION_THROWS_WITH("let x : R^1x1; let y : R^1, y = 1; x = y;",
"undefined affectation type: R^1x1 = R^1");
CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2; let y : R^2, y = (1,2); x = y;",
"undefined affectation type: R^2x2 = R^2");
CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3; let y : R^3, y = (1,2,3); x = y;",
"undefined affectation type: R^3x3 = R^3");
CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2; x = 3.2;", "undefined affectation type: R^2x2 = R");
CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3; x = 2.3;", "undefined affectation type: R^3x3 = R");
CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2, x = 4;", "invalid integral value (0 is the solely valid value)");
CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3, x = 3;", "invalid integral value (0 is the solely valid value)");
CHECK_AFFECTATION_THROWS_WITH("let x : R^1x1, x = 0; let y : R^2x2, y = x;",
"undefined affectation type: R^2x2 = R^1x1");
CHECK_AFFECTATION_THROWS_WITH("let x : R^1x1, x = 0; let y : R^3x3, y = x;",
"undefined affectation type: R^3x3 = R^1x1");
CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2, x = 0; let y : R^1x1, y = x;",
"undefined affectation type: R^1x1 = R^2x2");
CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2, x = 0; let y : R^3x3, y = x;",
"undefined affectation type: R^3x3 = R^2x2");
CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3, x = 0; let y : R^1x1, y = x;",
"undefined affectation type: R^1x1 = R^3x3");
CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3, x = 0; let y : R^2x2, y = x;",
"undefined affectation type: R^2x2 = R^3x3");
CHECK_AFFECTATION_THROWS_WITH("let x : R^1x1, x = (1,2);", "undefined affectation type: R^1x1 = list");
CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2, x = (1,2,3);",
"incompatible dimensions in affectation: expecting 4, but provided 3");
CHECK_AFFECTATION_THROWS_WITH("let x : R^2x2, x = (1,2,3,4,5);",
"incompatible dimensions in affectation: expecting 4, but provided 5");
CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3, x = (1,2,3,4,5,6,7,8);",
"incompatible dimensions in affectation: expecting 9, but provided 8");
CHECK_AFFECTATION_THROWS_WITH("let x : R^3x3, x = (1,2,3,4,5,6,7,8,9,10);",
"incompatible dimensions in affectation: expecting 9, but provided 10");
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment