Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
e9d5d0a6
Commit
e9d5d0a6
authored
Oct 08, 2014
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(tests): добавил тесты для TriggerAND
parent
32211b1e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
123 additions
and
14 deletions
+123
-14
TriggerAND.h
include/TriggerAND.h
+1
-1
TriggerAND.tcc
include/TriggerAND.tcc
+2
-13
triggerAND.cc
tests/triggerAND.cc
+120
-0
No files found.
include/TriggerAND.h
View file @
e9d5d0a6
...
@@ -71,7 +71,7 @@
...
@@ -71,7 +71,7 @@
\endcode
\endcode
*/
*/
template
<
class
Caller
,
typename
InputType
>
template
<
class
Caller
,
typename
InputType
=
int
>
class
TriggerAND
class
TriggerAND
{
{
public
:
public
:
...
...
include/TriggerAND.tcc
View file @
e9d5d0a6
...
@@ -89,30 +89,19 @@ void TriggerAND<Caller,InputType>::check()
...
@@ -89,30 +89,19 @@ void TriggerAND<Caller,InputType>::check()
{
{
if( !it->second )
if( !it->second )
{
{
// если хоть один вход "0" на выходе "0"
// если хоть один вход "0"
выставляем
на выходе "0"
// и прекращаем дальнейший поиск
// и прекращаем дальнейший поиск
out = false;
out = false;
if( old != out )
if( old != out )
{
// try
// {
(cal->*act)(out);
(cal->*act)(out);
// }
// catch(...){}
}
return;
return;
}
}
}
}
out = true;
out = true;
if( old != out )
if( old != out )
{
// try
// {
(cal->*act)(out);
(cal->*act)(out);
// }
// catch(...){}
}
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
template<class Caller, typename InputType>
template<class Caller, typename InputType>
...
...
tests/triggerAND.cc
0 → 100644
View file @
e9d5d0a6
#include <catch.hpp>
#include "TriggerAND.h"
#include "UniSetTypes.h"
using
namespace
std
;
class
MyTestClass
{
public
:
MyTestClass
()
:
num
(
0
){}
~
MyTestClass
(){}
void
setOut
(
bool
newstate
)
{
num
++
;
}
inline
int
getNum
(){
return
num
;
}
private
:
int
num
;
};
TEST_CASE
(
"TriggerAND"
,
"[TriggerAND]"
)
{
SECTION
(
"Constructor"
)
{
MyTestClass
tc
;
TriggerAND
<
MyTestClass
>
tr
(
&
tc
,
&
MyTestClass
::
setOut
);
tr
.
add
(
1
,
true
);
// в этот момент вход всего один и он TRUE поэтому тут out=TRUE
REQUIRE
(
tc
.
getNum
()
==
1
);
CHECK
(
tr
.
state
()
);
tr
.
add
(
2
,
false
);
REQUIRE
(
tc
.
getNum
()
==
2
);
CHECK_FALSE
(
tr
.
state
()
);
tr
.
add
(
3
,
false
);
REQUIRE
(
tc
.
getNum
()
==
2
);
CHECK_FALSE
(
tr
.
state
()
);
CHECK
(
tr
.
getState
(
1
)
);
CHECK_FALSE
(
tr
.
getState
(
2
)
);
CHECK_FALSE
(
tr
.
getState
(
3
)
);
}
SECTION
(
"Working"
)
{
MyTestClass
tc
;
TriggerAND
<
MyTestClass
>
tr
(
&
tc
,
&
MyTestClass
::
setOut
);
tr
.
add
(
1
,
false
);
tr
.
add
(
2
,
false
);
tr
.
add
(
3
,
false
);
REQUIRE
(
tc
.
getNum
()
==
0
);
CHECK_FALSE
(
tr
.
state
()
);
CHECK_FALSE
(
tr
.
getState
(
1
)
);
CHECK_FALSE
(
tr
.
getState
(
2
)
);
CHECK_FALSE
(
tr
.
getState
(
3
)
);
tr
.
commit
(
1
,
true
);
tr
.
commit
(
2
,
true
);
REQUIRE
(
tc
.
getNum
()
==
0
);
CHECK_FALSE
(
tr
.
state
()
);
CHECK
(
tr
.
getState
(
1
)
);
CHECK
(
tr
.
getState
(
2
)
);
CHECK_FALSE
(
tr
.
getState
(
3
)
);
tr
.
commit
(
3
,
true
);
REQUIRE
(
tc
.
getNum
()
==
1
);
CHECK
(
tr
.
state
()
);
CHECK
(
tr
.
getState
(
1
)
);
CHECK
(
tr
.
getState
(
2
)
);
CHECK
(
tr
.
getState
(
3
)
);
tr
.
commit
(
2
,
false
);
CHECK_FALSE
(
tr
.
state
()
);
REQUIRE
(
tc
.
getNum
()
==
2
);
CHECK
(
tr
.
getState
(
1
)
);
CHECK_FALSE
(
tr
.
getState
(
2
)
);
CHECK
(
tr
.
getState
(
3
)
);
tr
.
commit
(
1
,
false
);
tr
.
commit
(
3
,
false
);
CHECK_FALSE
(
tr
.
state
()
);
REQUIRE
(
tc
.
getNum
()
==
2
);
CHECK_FALSE
(
tr
.
getState
(
1
)
);
CHECK_FALSE
(
tr
.
getState
(
2
)
);
CHECK_FALSE
(
tr
.
getState
(
3
)
);
tr
.
commit
(
1
,
true
);
tr
.
commit
(
3
,
true
);
tr
.
commit
(
2
,
true
);
CHECK
(
tr
.
state
()
);
REQUIRE
(
tc
.
getNum
()
==
3
);
tr
.
commit
(
2
,
false
);
CHECK_FALSE
(
tr
.
state
()
);
REQUIRE
(
tc
.
getNum
()
==
4
);
tr
.
remove
(
2
);
CHECK
(
tr
.
getState
(
1
)
);
CHECK
(
tr
.
getState
(
3
)
);
CHECK
(
tr
.
state
()
);
REQUIRE
(
tc
.
getNum
()
==
5
);
// обращение к несуществующему входу
CHECK_FALSE
(
tr
.
getState
(
10
)
);
CHECK_FALSE
(
tr
.
getState
(
-
10
)
);
CHECK_FALSE
(
tr
.
getState
(
0
)
);
tr
.
commit
(
10
,
false
);
CHECK
(
tr
.
state
()
);
tr
.
commit
(
-
10
,
false
);
CHECK
(
tr
.
state
()
);
tr
.
commit
(
0
,
false
);
CHECK
(
tr
.
state
()
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment