Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dynamic-graph
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
Container Registry
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Guilhem Saurel
dynamic-graph
Commits
f6423581
Commit
f6423581
authored
14 years ago
by
Thomas Moulard
Browse files
Options
Downloads
Patches
Plain Diff
Convert test_depend example into depend unit test.
parent
f118e8fa
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/CMakeLists.txt
+2
-2
2 additions, 2 deletions
tests/CMakeLists.txt
tests/signal-time-dependent.cpp
+256
-0
256 additions, 0 deletions
tests/signal-time-dependent.cpp
tests/test_depend.cpp
+0
-160
0 additions, 160 deletions
tests/test_depend.cpp
with
258 additions
and
162 deletions
tests/CMakeLists.txt
+
2
−
2
View file @
f6423581
...
...
@@ -39,7 +39,6 @@ MACRO(DYNAMIC_GRAPH_TEST NAME)
# Link against Boost.
TARGET_LINK_LIBRARIES
(
${
NAME
}
${
Boost_LIBRARIES
}
)
ENDMACRO
(
DYNAMIC_GRAPH_TEST
)
DYNAMIC_GRAPH_TEST
(
test_depend
)
# Signal cast test.
...
...
@@ -58,4 +57,5 @@ TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME} ${signalcast_libs})
DYNAMIC_GRAPH_TEST
(
entity
)
DYNAMIC_GRAPH_TEST
(
custom-entity
)
DYNAMIC_GRAPH_TEST
(
factory
)
DYNAMIC_GRAPH_TEST
(
pool
)
\ No newline at end of file
DYNAMIC_GRAPH_TEST
(
pool
)
DYNAMIC_GRAPH_TEST
(
signal-time-dependent
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
tests/signal-time-dependent.cpp
0 → 100644
+
256
−
0
View file @
f6423581
// Copyright 2010 Thomas Moulard.
//
// This file is part of dynamic-graph.
// dynamic-graph is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// dynamic-graph is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public License
// along with dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
#include
<boost/foreach.hpp>
#include
<dynamic-graph/signal.h>
#include
<dynamic-graph/signal-time-dependent.h>
#define BOOST_TEST_MODULE signal_time_dependent
#include
<boost/test/unit_test.hpp>
#include
<boost/test/output_test_stream.hpp>
using
boost
::
test_tools
::
output_test_stream
;
typedef
dynamicgraph
::
SignalTimeDependent
<
double
,
int
>
sigDouble_t
;
typedef
dynamicgraph
::
SignalTimeDependent
<
std
::
string
,
int
>
sigString_t
;
template
<
class
T
>
class
DummyClass
{
public:
std
::
string
proname
;
std
::
list
<
sigDouble_t
*>
inputsig
;
std
::
list
<
sigString_t
*>
inputsigV
;
DummyClass
(
const
std
::
string
&
n
)
:
proname
(
n
),
res
(),
call
(),
timedata
()
{}
T
&
fun
(
T
&
res
,
int
t
)
{
++
call
;
timedata
=
t
;
BOOST_FOREACH
(
sigDouble_t
*
ptr
,
inputsig
)
ptr
->
access
(
timedata
);
BOOST_FOREACH
(
sigString_t
*
ptr
,
inputsigV
)
ptr
->
access
(
timedata
);
res
=
(
*
this
)
();
return
res
;
}
void
add
(
sigDouble_t
&
sig
)
{
inputsig
.
push_back
(
&
sig
);
}
void
add
(
sigString_t
&
sig
)
{
inputsigV
.
push_back
(
&
sig
);
}
T
operator
()
();
T
res
;
int
call
;
int
timedata
;
};
template
<
>
double
DummyClass
<
double
>::
operator
()
()
{
res
=
call
*
timedata
;
return
res
;
}
template
<
>
std
::
string
DummyClass
<
std
::
string
>::
operator
()
()
{
std
::
ostringstream
oss
;
oss
<<
call
*
timedata
;
return
oss
.
str
();
}
template
<
class
T
>
T
DummyClass
<
T
>::
operator
()
()
{
return
this
->
res
;
}
BOOST_AUTO_TEST_CASE
(
signaltimedependent
)
{
DummyClass
<
double
>
pro1
(
"pro1"
),
pro3
(
"pro3"
),
pro5
(
"pro5"
);
DummyClass
<
std
::
string
>
pro2
(
"pro2"
),
pro4
(
"pro4"
),
pro6
(
"pro6"
);
sigDouble_t
sig5
(
"Sig5"
);
sigString_t
sig6
(
"Sig6"
);
sigString_t
sig4
(
sig5
,
"Sig4"
);
sigString_t
sig2
(
sig4
<<
sig4
<<
sig4
<<
sig6
,
"Sig2"
);
sigDouble_t
sig3
(
sig2
<<
sig5
<<
sig6
,
"Sig3"
);
sigDouble_t
sig1
(
boost
::
bind
(
&
DummyClass
<
double
>::
fun
,
&
pro1
,
_1
,
_2
),
sig2
<<
sig3
,
"Sig1"
);
sig2
.
setFunction
(
boost
::
bind
(
&
DummyClass
<
std
::
string
>::
fun
,
&
pro2
,
_1
,
_2
));
sig3
.
setFunction
(
boost
::
bind
(
&
DummyClass
<
double
>::
fun
,
&
pro3
,
_1
,
_2
));
sig4
.
setFunction
(
boost
::
bind
(
&
DummyClass
<
std
::
string
>::
fun
,
&
pro4
,
_1
,
_2
));
sig5
.
setFunction
(
boost
::
bind
(
&
DummyClass
<
double
>::
fun
,
&
pro5
,
_1
,
_2
));
sig6
.
setFunction
(
boost
::
bind
(
&
DummyClass
<
std
::
string
>::
fun
,
&
pro6
,
_1
,
_2
));
pro1
.
add
(
sig2
);
pro1
.
add
(
sig3
);
pro2
.
add
(
sig4
);
pro2
.
add
(
sig4
);
pro2
.
add
(
sig4
);
pro3
.
add
(
sig2
);
pro4
.
add
(
sig5
);
pro2
.
add
(
sig6
);
pro3
.
add
(
sig5
);
pro3
.
add
(
sig6
);
sig5
.
setDependencyType
(
dynamicgraph
::
TimeDependency
<
int
>::
ALWAYS_READY
);
sig6
.
setDependencyType
(
dynamicgraph
::
TimeDependency
<
int
>::
BOOL_DEPENDENT
);
sig6
.
setReady
();
{
output_test_stream
output
;
sig1
.
displayDependencies
(
output
);
BOOST_CHECK
(
output
.
is_equal
(
"-- Sig:Sig1 (Type Fun) (t=0 (/1) )
\n
"
" |-- Sig:Sig3 (Type Fun) (t=0 (/1) )
\n
"
" | |-- Sig:Sig6 (Type Fun) (ready=TRUE)
\n
"
" | |-- Sig:Sig5 (Type Fun) (A)
\n
"
" | `-- Sig:Sig2 (Type Fun) (t=0 (/1) )
\n
"
" | |-- Sig:Sig6 (Type Fun) (ready=TRUE)
\n
"
" | |-- Sig:Sig4 (Type Fun) (t=0 (/1) )
\n
"
" | | `-- Sig:Sig5 (Type Fun) (A)
\n
"
" | |-- Sig:Sig4 (Type Fun) (t=0 (/1) )
\n
"
" | | `-- Sig:Sig5 (Type Fun) (A)
\n
"
" | `-- Sig:Sig4 (Type Fun) (t=0 (/1) )
\n
"
" | `-- Sig:Sig5 (Type Fun) (A)
\n
"
" `-- Sig:Sig2 (Type Fun) (t=0 (/1) )
\n
"
" |-- Sig:Sig6 (Type Fun) (ready=TRUE)
\n
"
" |-- Sig:Sig4 (Type Fun) (t=0 (/1) )
\n
"
" | `-- Sig:Sig5 (Type Fun) (A)
\n
"
" |-- Sig:Sig4 (Type Fun) (t=0 (/1) )
\n
"
" | `-- Sig:Sig5 (Type Fun) (A)
\n
"
" `-- Sig:Sig4 (Type Fun) (t=0 (/1) )
\n
"
" `-- Sig:Sig5 (Type Fun) (A)"
));
}
BOOST_CHECK
(
sig1
.
needUpdate
(
2
));
sig1
.
access
(
2
);
{
output_test_stream
output
;
sig1
.
displayDependencies
(
output
);
BOOST_CHECK
(
output
.
is_equal
(
"-- Sig:Sig1 (Type Fun) (t=2 (/1) )
\n
"
" |-- Sig:Sig3 (Type Fun) (t=2 (/1) )
\n
"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)
\n
"
" | |-- Sig:Sig5 (Type Fun) (A)
\n
"
" | `-- Sig:Sig2 (Type Fun) (t=2 (/1) )
\n
"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)
\n
"
" | |-- Sig:Sig4 (Type Fun) (t=2 (/1) )
\n
"
" | | `-- Sig:Sig5 (Type Fun) (A)
\n
"
" | |-- Sig:Sig4 (Type Fun) (t=2 (/1) )
\n
"
" | | `-- Sig:Sig5 (Type Fun) (A)
\n
"
" | `-- Sig:Sig4 (Type Fun) (t=2 (/1) )
\n
"
" | `-- Sig:Sig5 (Type Fun) (A)
\n
"
" `-- Sig:Sig2 (Type Fun) (t=2 (/1) )
\n
"
" |-- Sig:Sig6 (Type Fun) (ready=FALSE)
\n
"
" |-- Sig:Sig4 (Type Fun) (t=2 (/1) )
\n
"
" | `-- Sig:Sig5 (Type Fun) (A)
\n
"
" |-- Sig:Sig4 (Type Fun) (t=2 (/1) )
\n
"
" | `-- Sig:Sig5 (Type Fun) (A)
\n
"
" `-- Sig:Sig4 (Type Fun) (t=2 (/1) )
\n
"
" `-- Sig:Sig5 (Type Fun) (A)"
));
}
sig2
.
access
(
4
);
{
output_test_stream
output
;
sig1
.
displayDependencies
(
output
);
BOOST_CHECK
(
output
.
is_equal
(
"-- Sig:Sig1 (Type Fun) (t=2 (/1) )
\n
"
" |-- Sig:Sig3 (Type Fun) (t=2 (/1) )
\n
"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)
\n
"
" | |-- Sig:Sig5 (Type Fun) (A)
\n
"
" | `-- Sig:Sig2 (Type Fun) (t=4 (/1) )
\n
"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)
\n
"
" | |-- Sig:Sig4 (Type Fun) (t=4 (/1) )
\n
"
" | | `-- Sig:Sig5 (Type Fun) (A)
\n
"
" | |-- Sig:Sig4 (Type Fun) (t=4 (/1) )
\n
"
" | | `-- Sig:Sig5 (Type Fun) (A)
\n
"
" | `-- Sig:Sig4 (Type Fun) (t=4 (/1) )
\n
"
" | `-- Sig:Sig5 (Type Fun) (A)
\n
"
" `-- Sig:Sig2 (Type Fun) (t=4 (/1) )
\n
"
" |-- Sig:Sig6 (Type Fun) (ready=FALSE)
\n
"
" |-- Sig:Sig4 (Type Fun) (t=4 (/1) )
\n
"
" | `-- Sig:Sig5 (Type Fun) (A)
\n
"
" |-- Sig:Sig4 (Type Fun) (t=4 (/1) )
\n
"
" | `-- Sig:Sig5 (Type Fun) (A)
\n
"
" `-- Sig:Sig4 (Type Fun) (t=4 (/1) )
\n
"
" `-- Sig:Sig5 (Type Fun) (A)"
));
}
sig1
.
access
(
4
);
{
output_test_stream
output
;
sig1
.
displayDependencies
(
output
);
BOOST_CHECK
(
output
.
is_equal
(
"-- Sig:Sig1 (Type Fun) (t=4 (/1) )
\n
"
" |-- Sig:Sig3 (Type Fun) (t=4 (/1) )
\n
"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)
\n
"
" | |-- Sig:Sig5 (Type Fun) (A)
\n
"
" | `-- Sig:Sig2 (Type Fun) (t=4 (/1) )
\n
"
" | |-- Sig:Sig6 (Type Fun) (ready=FALSE)
\n
"
" | |-- Sig:Sig4 (Type Fun) (t=4 (/1) )
\n
"
" | | `-- Sig:Sig5 (Type Fun) (A)
\n
"
" | |-- Sig:Sig4 (Type Fun) (t=4 (/1) )
\n
"
" | | `-- Sig:Sig5 (Type Fun) (A)
\n
"
" | `-- Sig:Sig4 (Type Fun) (t=4 (/1) )
\n
"
" | `-- Sig:Sig5 (Type Fun) (A)
\n
"
" `-- Sig:Sig2 (Type Fun) (t=4 (/1) )
\n
"
" |-- Sig:Sig6 (Type Fun) (ready=FALSE)
\n
"
" |-- Sig:Sig4 (Type Fun) (t=4 (/1) )
\n
"
" | `-- Sig:Sig5 (Type Fun) (A)
\n
"
" |-- Sig:Sig4 (Type Fun) (t=4 (/1) )
\n
"
" | `-- Sig:Sig5 (Type Fun) (A)
\n
"
" `-- Sig:Sig4 (Type Fun) (t=4 (/1) )
\n
"
" `-- Sig:Sig5 (Type Fun) (A)"
));
}
sig1
.
needUpdate
(
6
);
sig1
.
needUpdate
(
6
);
}
This diff is collapsed.
Click to expand it.
tests/test_depend.cpp
deleted
100644 → 0
+
0
−
160
View file @
f118e8fa
/*
* Copyright 2010,
* François Bleibel,
* Olivier Stasse,
*
* CNRS/AIST
*
* This file is part of dynamic-graph.
* dynamic-graph is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* dynamic-graph is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. You should
* have received a copy of the GNU Lesser General Public License along
* with dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
*/
/* -------------------------------------------------------------------------- */
/* --- INCLUDES ------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
// #include <dynamic-graph/all-signals.h>
#include
<dynamic-graph/signal.h>
#include
<dynamic-graph/signal-time-dependent.h>
//#include <sot/TimeDependency.h>
#include
<dynamic-graph/debug.h>
#include
<iostream>
#include
<string>
using
namespace
std
;
using
namespace
dynamicgraph
;
template
<
class
Res
=
double
>
class
DummyClass
{
public:
std
::
string
proname
;
list
<
SignalTimeDependent
<
double
,
int
>*
>
inputsig
;
list
<
SignalTimeDependent
<
string
,
int
>*
>
inputsigV
;
public:
DummyClass
(
const
std
::
string
&
n
)
:
proname
(
n
),
res
(),
appel
(
0
),
timedata
(
0
)
{}
Res
&
fun
(
Res
&
res
,
int
t
)
{
appel
++
;
timedata
=
t
;
cout
<<
"Inside "
<<
proname
<<
" -> "
<<
this
<<
endl
;
for
(
list
<
SignalTimeDependent
<
double
,
int
>*
>::
iterator
it
=
inputsig
.
begin
();
it
!=
inputsig
.
end
();
++
it
)
{
cout
<<
*
(
*
it
)
<<
endl
;
(
*
it
)
->
access
(
timedata
);
}
for
(
list
<
SignalTimeDependent
<
string
,
int
>*
>::
iterator
it
=
inputsigV
.
begin
();
it
!=
inputsigV
.
end
();
++
it
)
{
cout
<<
*
(
*
it
)
<<
endl
;
(
*
it
)
->
access
(
timedata
);}
return
res
=
(
*
this
)();
}
void
add
(
SignalTimeDependent
<
double
,
int
>&
sig
)
{
inputsig
.
push_back
(
&
sig
);
}
void
add
(
SignalTimeDependent
<
string
,
int
>&
sig
)
{
inputsigV
.
push_back
(
&
sig
);
}
Res
operator
()
(
void
);
Res
res
;
int
appel
;
int
timedata
;
};
template
<
class
Res
>
Res
DummyClass
<
Res
>::
operator
()
(
void
)
{
return
this
->
res
;
}
template
<
>
double
DummyClass
<
double
>::
operator
()
(
void
)
{
res
=
appel
*
timedata
;
return
res
;
}
template
<
>
string
DummyClass
<
string
>::
operator
()
(
void
)
{
ostringstream
oss
;
oss
<<
appel
*
timedata
;
return
oss
.
str
();
}
int
main
(
void
)
{
DummyClass
<
double
>
pro1
(
"pro1"
),
pro3
(
"pro3"
),
pro5
(
"pro5"
);
DummyClass
<
string
>
pro2
(
"pro2"
),
pro4
(
"pro4"
),
pro6
(
"pro6"
);
SignalTimeDependent
<
double
,
int
>
sig5
(
"Sig5"
);
SignalTimeDependent
<
string
,
int
>
sig6
(
"Sig6"
);
SignalTimeDependent
<
string
,
int
>
sig4
(
sig5
,
"Sig4"
);
SignalTimeDependent
<
string
,
int
>
sig2
(
sig4
<<
sig4
<<
sig4
<<
sig6
,
"Sig2"
);
SignalTimeDependent
<
double
,
int
>
sig3
(
sig2
<<
sig5
<<
sig6
,
"Sig3"
);
SignalTimeDependent
<
double
,
int
>
sig1
(
boost
::
bind
(
&
DummyClass
<
double
>::
fun
,
&
pro1
,
_1
,
_2
),
sig2
<<
sig3
,
"Sig1"
);
// cout << "--- Test Array ------ "<<endl;
// SignalArray<int> tarr(12);
// tarr<<sig3<<sig2;//+sig2+sig3;
// dispArray(sig4<<sig2<<sig3);
// dispArray(tarr);
sig2
.
setFunction
(
boost
::
bind
(
&
DummyClass
<
string
>::
fun
,
&
pro2
,
_1
,
_2
)
);
sig3
.
setFunction
(
boost
::
bind
(
&
DummyClass
<
double
>::
fun
,
&
pro3
,
_1
,
_2
)
);
sig4
.
setFunction
(
boost
::
bind
(
&
DummyClass
<
string
>::
fun
,
&
pro4
,
_1
,
_2
)
);
sig5
.
setFunction
(
boost
::
bind
(
&
DummyClass
<
double
>::
fun
,
&
pro5
,
_1
,
_2
)
);
sig6
.
setFunction
(
boost
::
bind
(
&
DummyClass
<
string
>::
fun
,
&
pro6
,
_1
,
_2
)
);
pro1
.
add
(
sig2
);
pro1
.
add
(
sig3
);
pro2
.
add
(
sig4
);
pro2
.
add
(
sig4
);
pro2
.
add
(
sig4
);
pro3
.
add
(
sig2
);
pro4
.
add
(
sig5
);
pro2
.
add
(
sig6
);
pro3
.
add
(
sig5
);
pro3
.
add
(
sig6
);
sig5
.
setDependencyType
(
TimeDependency
<
int
>::
ALWAYS_READY
);
sig6
.
setDependencyType
(
TimeDependency
<
int
>::
BOOL_DEPENDENT
);
sig6
.
setReady
();
sig1
.
displayDependencies
(
cout
)
<<
endl
;
cout
<<
"Needs update?"
<<
endl
<<
sig1
.
needUpdate
(
2
)
<<
endl
;
dgDEBUG
(
1
)
<<
"Access sig1(2) "
<<
endl
;
sig1
.
access
(
2
);
sig1
.
displayDependencies
(
cout
)
<<
endl
;
dgDEBUG
(
1
)
<<
"Access sig2(4) "
<<
endl
;
sig2
.
access
(
4
);
sig1
.
displayDependencies
(
cout
)
<<
endl
;
dgDEBUG
(
1
)
<<
"Access sig1(4) "
<<
endl
;
sig1
.
access
(
4
);
sig1
.
displayDependencies
(
cout
)
<<
endl
;
sig1
.
needUpdate
(
6
);
sig1
.
needUpdate
(
6
);
return
0
;
}
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