Commit 32211b1e authored by Pavel Vainerman's avatar Pavel Vainerman

(tests): Добавил тесты для TriggerAND

parent c3c97227
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
template<class Caller, typename InputType> template<class Caller, typename InputType>
TriggerAND<Caller,InputType>::TriggerAND(Caller* c, Action a): TriggerAND<Caller,InputType>::TriggerAND(Caller* c, Action a):
out(false),
cal(c), cal(c),
act(a) act(a)
{ {
...@@ -84,7 +85,7 @@ template<class Caller, typename InputType> ...@@ -84,7 +85,7 @@ template<class Caller, typename InputType>
void TriggerAND<Caller,InputType>::check() void TriggerAND<Caller,InputType>::check()
{ {
bool old = out; bool old = out;
for( typename InputMap::iterator it=inputs.begin(); it!=inputs.end(); ++it ) for( auto it=inputs.begin(); it!=inputs.end(); ++it )
{ {
if( !it->second ) if( !it->second )
{ {
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
... ...
MyClass rec; MyClass rec;
// Создание // Создание
TriggerOR<MyClass, int> tr(&rec, &MyClass::out); TriggerOR<MyClass> tr(&rec, &MyClass::out);
// Добавление 'входов' // Добавление 'входов'
tr.add(1,true); tr.add(1,true);
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
\endcode \endcode
*/ */
template<class Caller, typename InputType> template<class Caller, typename InputType=int>
class TriggerOR class TriggerOR
{ {
public: public:
......
...@@ -85,6 +85,7 @@ template<class Caller, typename InputType> ...@@ -85,6 +85,7 @@ template<class Caller, typename InputType>
void TriggerOR<Caller,InputType>::check() void TriggerOR<Caller,InputType>::check()
{ {
bool old = out; bool old = out;
for( auto it=inputs.begin(); it!=inputs.end(); ++it ) for( auto it=inputs.begin(); it!=inputs.end(); ++it )
{ {
if( it->second ) if( it->second )
...@@ -94,7 +95,6 @@ void TriggerOR<Caller,InputType>::check() ...@@ -94,7 +95,6 @@ void TriggerOR<Caller,InputType>::check()
out = true; out = true;
if( old != out ) if( old != out )
(cal->*act)(out); (cal->*act)(out);
return; return;
} }
} }
......
...@@ -42,13 +42,13 @@ TEST_CASE("TriggerOR", "[TriggerOR]" ) ...@@ -42,13 +42,13 @@ TEST_CASE("TriggerOR", "[TriggerOR]" )
SECTION("Working") SECTION("Working")
{ {
MyTestClass tc; MyTestClass tc;
TriggerOR<MyTestClass, bool> tr(&tc, &MyTestClass::setOut); TriggerOR<MyTestClass> tr(&tc, &MyTestClass::setOut);
REQUIRE( tc.getNum() == 0 ); REQUIRE( tc.getNum() == 0 );
tr.add(1, true); tr.add(1, true);
REQUIRE( tc.getNum() == 1 ); REQUIRE( tc.getNum() == 1 );
CHECK( tr.state() ); CHECK( tr.state() );
tr.add(2, false); tr.add(2, false);
CHECK( tr.state() );
REQUIRE( tc.getNum() == 1 ); REQUIRE( tc.getNum() == 1 );
tr.add(3, false); tr.add(3, false);
REQUIRE( tc.getNum() == 1 ); REQUIRE( tc.getNum() == 1 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment