Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pugs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
code
pugs
Commits
48aad214
Commit
48aad214
authored
Feb 12, 2020
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Add missing tests for ASTNodeFunctionExpressionBuilder
parent
ef95037e
No related branches found
No related tags found
1 merge request
!37
Feature/language
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/language/ASTNodeFunctionExpressionBuilder.cpp
+37
-17
37 additions, 17 deletions
src/language/ASTNodeFunctionExpressionBuilder.cpp
tests/test_ASTNodeFunctionExpressionBuilder.cpp
+254
-0
254 additions, 0 deletions
tests/test_ASTNodeFunctionExpressionBuilder.cpp
with
291 additions
and
17 deletions
src/language/ASTNodeFunctionExpressionBuilder.cpp
+
37
−
17
View file @
48aad214
...
...
@@ -37,7 +37,8 @@ ASTNodeFunctionExpressionBuilder::_getArgumentConverter(SymbolType& parameter_sy
}
// LCOV_EXCL_START
default
:
{
throw
parse_error
(
"invalid argument type"
,
std
::
vector
{
node_sub_data_type
.
m_parent_node
.
begin
()});
throw
parse_error
(
"unexpected error: invalid argument type"
,
std
::
vector
{
node_sub_data_type
.
m_parent_node
.
begin
()});
}
// LCOV_EXCL_STOP
}
...
...
@@ -51,9 +52,10 @@ ASTNodeFunctionExpressionBuilder::_getArgumentConverter(SymbolType& parameter_sy
if
(
node_sub_data_type
.
m_data_type
.
dimension
()
==
parameter_v
.
dimension
())
{
return
std
::
make_unique
<
FunctionArgumentConverter
<
ParameterT
,
ParameterT
>>
(
parameter_id
);
}
else
{
throw
parse_error
(
"invalid argument dimension (expected "
+
std
::
to_string
(
parameter_v
.
dimension
())
+
", provided "
+
std
::
to_string
(
node_sub_data_type
.
m_data_type
.
dimension
())
+
")
"
,
// LCOV_EXCL_START
throw
parse_error
(
"unexpected error: invalid argument
dimension"
,
std
::
vector
{
node_sub_data_type
.
m_parent_node
.
begin
()});
// LCOV_EXCL_STOP
}
}
case
ASTNodeDataType
::
int_t
:
{
...
...
@@ -92,7 +94,8 @@ ASTNodeFunctionExpressionBuilder::_getArgumentConverter(SymbolType& parameter_sy
}
// LCOV_EXCL_START
default
:
{
throw
parse_error
(
"invalid argument type"
,
std
::
vector
{
node_sub_data_type
.
m_parent_node
.
begin
()});
throw
parse_error
(
"unexpected error: invalid argument type"
,
std
::
vector
{
node_sub_data_type
.
m_parent_node
.
begin
()});
}
// LCOV_EXCL_STOP
}
...
...
@@ -202,8 +205,6 @@ ASTNodeFunctionExpressionBuilder::_getFunctionProcessor(const ASTNodeDataType re
ASTNode
&
node
,
ASTNode
&
function_component_expression
)
{
ASTNodeNaturalConversionChecker
{
function_component_expression
,
return_value_type
};
auto
get_function_processor_for_expression_value
=
[
&
](
const
auto
&
return_v
)
->
std
::
unique_ptr
<
INodeProcessor
>
{
using
ReturnT
=
std
::
decay_t
<
decltype
(
return_v
)
>
;
switch
(
function_component_expression
.
m_data_type
)
{
...
...
@@ -244,7 +245,10 @@ ASTNodeFunctionExpressionBuilder::_getFunctionProcessor(const ASTNodeDataType re
if
(
function_component_expression
.
m_data_type
.
dimension
()
==
return_v
.
dimension
())
{
return
std
::
make_unique
<
FunctionExpressionProcessor
<
ReturnT
,
ReturnT
>>
(
function_component_expression
);
}
else
{
throw
parse_error
(
"invalid dimension for returned vector"
,
std
::
vector
{
function_component_expression
.
begin
()});
// LCOV_EXCL_START
throw
parse_error
(
"unexpected error: invalid dimension for returned vector"
,
std
::
vector
{
function_component_expression
.
begin
()});
// LCOV_EXCL_STOP
}
}
case
ASTNodeDataType
::
int_t
:
{
...
...
@@ -253,9 +257,10 @@ ASTNodeFunctionExpressionBuilder::_getFunctionProcessor(const ASTNodeDataType re
return
std
::
make_unique
<
FunctionExpressionProcessor
<
ReturnT
,
ZeroType
>>
(
function_component_expression
);
}
}
// LCOV_EXCL_START
throw
parse_error
(
"unexpected error: undefined expression value type for function"
,
std
::
vector
{
function_component_expression
.
begin
()});
break
;
// LCOV_EXCL_STOP
}
// LCOV_EXCL_START
default
:
{
...
...
@@ -283,7 +288,11 @@ ASTNodeFunctionExpressionBuilder::_getFunctionProcessor(const ASTNodeDataType re
case
ASTNodeDataType
::
vector_t
:
{
switch
(
return_value_type
.
dimension
())
{
case
1
:
{
if
(
function_component_expression
.
m_data_type
==
ASTNodeDataType
::
vector_t
)
{
return
get_function_processor_for_expression_vector
(
TinyVector
<
1
>
{});
}
else
{
return
get_function_processor_for_expression_value
(
TinyVector
<
1
>
{});
}
}
case
2
:
{
return
get_function_processor_for_expression_vector
(
TinyVector
<
2
>
{});
...
...
@@ -291,9 +300,11 @@ ASTNodeFunctionExpressionBuilder::_getFunctionProcessor(const ASTNodeDataType re
case
3
:
{
return
get_function_processor_for_expression_vector
(
TinyVector
<
3
>
{});
}
// LCOV_EXCL_START
default
:
{
throw
parse_error
(
"unexpected error: invalid dimension in returned type"
,
std
::
vector
{
node
.
begin
()});
}
// LCOV_EXCL_STOP
}
}
case
ASTNodeDataType
::
string_t
:
{
...
...
@@ -343,7 +354,11 @@ ASTNodeFunctionExpressionBuilder::ASTNodeFunctionExpressionBuilder(ASTNode& node
Assert
(
return_value_type
!=
ASTNodeDataType
::
undefined_t
);
if
((
return_value_type
==
ASTNodeDataType
::
vector_t
)
and
(
return_value_type
.
dimension
()
==
1
))
{
ASTNodeNaturalConversionChecker
{
expression_node
,
ASTNodeDataType
::
double_t
};
}
else
{
ASTNodeNaturalConversionChecker
{
expression_node
,
return_value_type
};
}
function_processor
->
addFunctionExpressionProcessor
(
this
->
_getFunctionProcessor
(
return_value_type
,
node
,
expression_node
));
...
...
@@ -355,7 +370,11 @@ ASTNodeFunctionExpressionBuilder::ASTNodeFunctionExpressionBuilder(ASTNode& node
if
(
function_image_domain
.
is_type
<
language
::
vector_type
>
())
{
ASTNodeDataType
vector_type
=
getVectorDataType
(
function_image_domain
);
if
((
vector_type
.
dimension
()
==
1
)
and
(
function_expression
.
m_data_type
!=
ASTNodeDataType
::
vector_t
))
{
ASTNodeNaturalConversionChecker
{
function_expression
,
ASTNodeDataType
::
double_t
};
}
else
{
ASTNodeNaturalConversionChecker
{
function_expression
,
vector_type
};
}
if
(
function_expression
.
is_type
<
language
::
expression_list
>
())
{
Assert
(
vector_type
.
dimension
()
==
function_expression
.
children
.
size
());
...
...
@@ -365,11 +384,6 @@ ASTNodeFunctionExpressionBuilder::ASTNodeFunctionExpressionBuilder(ASTNode& node
}
switch
(
vector_type
.
dimension
())
{
case
1
:
{
node
.
m_node_processor
=
std
::
make_unique
<
TupleToVectorProcessor
<
FunctionProcessor
,
1
>>
(
node
,
std
::
move
(
function_processor
));
break
;
}
case
2
:
{
node
.
m_node_processor
=
std
::
make_unique
<
TupleToVectorProcessor
<
FunctionProcessor
,
2
>>
(
node
,
std
::
move
(
function_processor
));
...
...
@@ -380,9 +394,11 @@ ASTNodeFunctionExpressionBuilder::ASTNodeFunctionExpressionBuilder(ASTNode& node
std
::
make_unique
<
TupleToVectorProcessor
<
FunctionProcessor
,
3
>>
(
node
,
std
::
move
(
function_processor
));
break
;
}
// LCOV_EXCL_START
default
:
{
throw
parse_error
(
"unexpected error: invalid vector_t dimension"
,
std
::
vector
{
node
.
begin
()});
}
// LCOV_EXCL_STOP
}
}
else
if
(
function_expression
.
is_type
<
language
::
integer
>
())
{
if
(
std
::
stoi
(
function_expression
.
string
())
==
0
)
{
...
...
@@ -402,12 +418,16 @@ ASTNodeFunctionExpressionBuilder::ASTNodeFunctionExpressionBuilder(ASTNode& node
std
::
make_unique
<
FunctionExpressionProcessor
<
TinyVector
<
3
>
,
ZeroType
>>
(
function_expression
);
break
;
}
// LCOV_EXCL_START
default
:
{
throw
parse_error
(
"unexpected error: invalid vector_t dimension"
,
std
::
vector
{
node
.
begin
()});
}
// LCOV_EXCL_STOP
}
}
else
{
// LCOV_EXCL_START
throw
parse_error
(
"unexpected error: expecting 0"
,
std
::
vector
{
function_expression
.
begin
()});
// LCOV_EXCL_STOP
}
}
else
{
function_processor
->
addFunctionExpressionProcessor
(
...
...
This diff is collapsed.
Click to expand it.
tests/test_ASTNodeFunctionExpressionBuilder.cpp
+
254
−
0
View file @
48aad214
...
...
@@ -330,6 +330,260 @@ cat("foo", 2.5e-3);
CHECK_AST
(
data
,
result
);
}
SECTION
(
"Return R^1 -> R^1"
)
{
std
::
string_view
data
=
R"(
let f : R^1 -> R^1, x -> x+x;
R^1 x = 1;
f(x);
)"
;
std
::
string_view
result
=
R"(
(root:ASTNodeListProcessor)
`-(language::function_evaluation:FunctionProcessor)
+-(language::name:f:NameProcessor)
`-(language::name:x:NameProcessor)
)"
;
CHECK_AST
(
data
,
result
);
}
SECTION
(
"Return R^2 -> R^2"
)
{
std
::
string_view
data
=
R"(
let f : R^2 -> R^2, x -> x+x;
R^2 x = (1,2);
f(x);
)"
;
std
::
string_view
result
=
R"(
(root:ASTNodeListProcessor)
`-(language::function_evaluation:FunctionProcessor)
+-(language::name:f:NameProcessor)
`-(language::name:x:NameProcessor)
)"
;
CHECK_AST
(
data
,
result
);
}
SECTION
(
"Return R^3 -> R^3"
)
{
std
::
string_view
data
=
R"(
let f : R^3 -> R^3, x -> x+x;
R^3 x = (1,2,3);
f(x);
)"
;
std
::
string_view
result
=
R"(
(root:ASTNodeListProcessor)
`-(language::function_evaluation:FunctionProcessor)
+-(language::name:f:NameProcessor)
`-(language::name:x:NameProcessor)
)"
;
CHECK_AST
(
data
,
result
);
}
SECTION
(
"Return scalar -> R^1"
)
{
std
::
string_view
data
=
R"(
let f : R -> R^1, x -> x+1;
f(1);
)"
;
std
::
string_view
result
=
R"(
(root:ASTNodeListProcessor)
`-(language::function_evaluation:FunctionProcessor)
+-(language::name:f:NameProcessor)
`-(language::integer:1:ValueProcessor)
)"
;
CHECK_AST
(
data
,
result
);
}
SECTION
(
"Return tuple -> R^2"
)
{
std
::
string_view
data
=
R"(
let f : R*R -> R^2, (x,y) -> (x,y);
f(1,2);
)"
;
std
::
string_view
result
=
R"(
(root:ASTNodeListProcessor)
`-(language::function_evaluation:TupleToVectorProcessor<FunctionProcessor, 2ul>)
+-(language::name:f:NameProcessor)
`-(language::function_argument_list:ASTNodeExpressionListProcessor)
+-(language::integer:1:ValueProcessor)
`-(language::integer:2:ValueProcessor)
)"
;
CHECK_AST
(
data
,
result
);
}
SECTION
(
"Return tuple -> R^3"
)
{
std
::
string_view
data
=
R"(
let f : R*R*R -> R^3, (x,y,z) -> (x,y,z);
f(1,2,3);
)"
;
std
::
string_view
result
=
R"(
(root:ASTNodeListProcessor)
`-(language::function_evaluation:TupleToVectorProcessor<FunctionProcessor, 3ul>)
+-(language::name:f:NameProcessor)
`-(language::function_argument_list:ASTNodeExpressionListProcessor)
+-(language::integer:1:ValueProcessor)
+-(language::integer:2:ValueProcessor)
`-(language::integer:3:ValueProcessor)
)"
;
CHECK_AST
(
data
,
result
);
}
SECTION
(
"Return '0' -> R^1"
)
{
std
::
string_view
data
=
R"(
let f : R -> R^1, x -> 0;
f(1);
)"
;
std
::
string_view
result
=
R"(
(root:ASTNodeListProcessor)
`-(language::function_evaluation:FunctionExpressionProcessor<TinyVector<1ul, double>, ZeroType>)
+-(language::name:f:NameProcessor)
`-(language::integer:1:ValueProcessor)
)"
;
CHECK_AST
(
data
,
result
);
}
SECTION
(
"Return '0' -> R^2"
)
{
std
::
string_view
data
=
R"(
let f : R -> R^2, x -> 0;
f(1);
)"
;
std
::
string_view
result
=
R"(
(root:ASTNodeListProcessor)
`-(language::function_evaluation:FunctionExpressionProcessor<TinyVector<2ul, double>, ZeroType>)
+-(language::name:f:NameProcessor)
`-(language::integer:1:ValueProcessor)
)"
;
CHECK_AST
(
data
,
result
);
}
SECTION
(
"Return '0' -> R^3"
)
{
std
::
string_view
data
=
R"(
let f : R -> R^3, x -> 0;
f(1);
)"
;
std
::
string_view
result
=
R"(
(root:ASTNodeListProcessor)
`-(language::function_evaluation:FunctionExpressionProcessor<TinyVector<3ul, double>, ZeroType>)
+-(language::name:f:NameProcessor)
`-(language::integer:1:ValueProcessor)
)"
;
CHECK_AST
(
data
,
result
);
}
SECTION
(
"Return embedded R^d compound"
)
{
std
::
string_view
data
=
R"(
let f : R*R*R*R -> R*R^1*R^2*R^3, (x,y,z,t) -> (t, (x), (x,y), (x,y,z));
f(1,2,3,4);
)"
;
std
::
string_view
result
=
R"(
(root:ASTNodeListProcessor)
`-(language::function_evaluation:FunctionProcessor)
+-(language::name:f:NameProcessor)
`-(language::function_argument_list:ASTNodeExpressionListProcessor)
+-(language::integer:1:ValueProcessor)
+-(language::integer:2:ValueProcessor)
+-(language::integer:3:ValueProcessor)
`-(language::integer:4:ValueProcessor)
)"
;
CHECK_AST
(
data
,
result
);
}
SECTION
(
"Return embedded R^d compound with '0'"
)
{
std
::
string_view
data
=
R"(
let f : R*R*R*R -> R*R^1*R^2*R^3, (x,y,z,t) -> (t, 0, 0, (x,y,z));
f(1,2,3,4);
)"
;
std
::
string_view
result
=
R"(
(root:ASTNodeListProcessor)
`-(language::function_evaluation:FunctionProcessor)
+-(language::name:f:NameProcessor)
`-(language::function_argument_list:ASTNodeExpressionListProcessor)
+-(language::integer:1:ValueProcessor)
+-(language::integer:2:ValueProcessor)
+-(language::integer:3:ValueProcessor)
`-(language::integer:4:ValueProcessor)
)"
;
CHECK_AST
(
data
,
result
);
}
SECTION
(
"Arguments '0' -> R^1"
)
{
std
::
string_view
data
=
R"(
let f : R^1 -> R^1, x -> x;
f(0);
)"
;
std
::
string_view
result
=
R"(
(root:ASTNodeListProcessor)
`-(language::function_evaluation:FunctionProcessor)
+-(language::name:f:NameProcessor)
`-(language::integer:0:ValueProcessor)
)"
;
CHECK_AST
(
data
,
result
);
}
SECTION
(
"Arguments '0' -> R^2"
)
{
std
::
string_view
data
=
R"(
let f : R^2 -> R^2, x -> x;
f(0);
)"
;
std
::
string_view
result
=
R"(
(root:ASTNodeListProcessor)
`-(language::function_evaluation:FunctionProcessor)
+-(language::name:f:NameProcessor)
`-(language::integer:0:ValueProcessor)
)"
;
CHECK_AST
(
data
,
result
);
}
SECTION
(
"Arguments '0' -> R^3"
)
{
std
::
string_view
data
=
R"(
let f : R^3 -> R^3, x -> x;
f(0);
)"
;
std
::
string_view
result
=
R"(
(root:ASTNodeListProcessor)
`-(language::function_evaluation:FunctionProcessor)
+-(language::name:f:NameProcessor)
`-(language::integer:0:ValueProcessor)
)"
;
CHECK_AST
(
data
,
result
);
}
}
SECTION
(
"errors"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment