Commit 2a9b5be2 authored by Pavel Vainerman's avatar Pavel Vainerman

(tests): небольщой рефакторинг тестов, для лучшего понимая "отчётов"

parent 85906e18
#include <catch.hpp> #include <catch.hpp>
// -----------------------------------------------------------------------------
#include "Exceptions.h" #include "Exceptions.h"
#include "Extensions.h" #include "Extensions.h"
#include "DigitalFilter.h" #include "DigitalFilter.h"
// -----------------------------------------------------------------------------
using namespace std; using namespace std;
using namespace UniSetTypes; using namespace UniSetTypes;
using namespace UniSetExtensions; using namespace UniSetExtensions;
// -----------------------------------------------------------------------------
TEST_CASE("DigitalFilter","[DigitalFilter]") TEST_CASE("[DigitalFilter]: default","[DigitalFilter]")
{ {
SECTION("..") SECTION("..")
{ {
...@@ -37,9 +37,10 @@ TEST_CASE("DigitalFilter","[DigitalFilter]") ...@@ -37,9 +37,10 @@ TEST_CASE("DigitalFilter","[DigitalFilter]")
REQUIRE( df10.currentRC() == 50 ); REQUIRE( df10.currentRC() == 50 );
REQUIRE( df10.currentMedian() == 50 ); REQUIRE( df10.currentMedian() == 50 );
} }
}
SECTION("Median filter") // -----------------------------------------------------------------------------
{ TEST_CASE("[DigitalFilter]: median","[DigitalFilter][median]")
{
DigitalFilter df; DigitalFilter df;
for( int i=0; i<20; i++ ) for( int i=0; i<20; i++ )
df.median(50); df.median(50);
...@@ -57,10 +58,10 @@ TEST_CASE("DigitalFilter","[DigitalFilter]") ...@@ -57,10 +58,10 @@ TEST_CASE("DigitalFilter","[DigitalFilter]")
REQUIRE( df1.currentMedian() == 252 ); REQUIRE( df1.currentMedian() == 252 );
REQUIRE( df10.currentMedian() == 252 ); REQUIRE( df10.currentMedian() == 252 );
} }
// -----------------------------------------------------------------------------
SECTION("filter1") TEST_CASE("[DigitalFilter]: filter1","[DigitalFilter][filter1]")
{ {
DigitalFilter df1; DigitalFilter df1;
DigitalFilter df10; DigitalFilter df10;
// "выброс" за СКО отсекается.. // "выброс" за СКО отсекается..
...@@ -73,10 +74,10 @@ TEST_CASE("DigitalFilter","[DigitalFilter]") ...@@ -73,10 +74,10 @@ TEST_CASE("DigitalFilter","[DigitalFilter]")
REQUIRE( df1.current1() == 10 ); REQUIRE( df1.current1() == 10 );
REQUIRE( df10.current1() == 10 ); REQUIRE( df10.current1() == 10 );
} }
// -----------------------------------------------------------------------------
SECTION("filterRC") TEST_CASE("[DigitalFilter]: filterRC","[DigitalFilter][filterRC]")
{ {
double Ti = 0.09; // постоянная времени фильтра double Ti = 0.09; // постоянная времени фильтра
DigitalFilter df1(5,Ti); DigitalFilter df1(5,Ti);
DigitalFilter df10(10,Ti); DigitalFilter df10(10,Ti);
...@@ -91,5 +92,4 @@ TEST_CASE("DigitalFilter","[DigitalFilter]") ...@@ -91,5 +92,4 @@ TEST_CASE("DigitalFilter","[DigitalFilter]")
REQUIRE( df1.currentRC() == 10 ); REQUIRE( df1.currentRC() == 10 );
REQUIRE( df10.currentRC() == 10 ); REQUIRE( df10.currentRC() == 10 );
}
} }
#include <catch.hpp> #include <catch.hpp>
// -----------------------------------------------------------------------------
#include "DelayTimer.h" #include "DelayTimer.h"
#include "UniSetTypes.h" #include "UniSetTypes.h"
using namespace std; using namespace std;
// -----------------------------------------------------------------------------
TEST_CASE("DelayTimer", "[DelayTimer]" ) TEST_CASE("[DelayTimer]: default", "[DelayTimer]" )
{ {
SECTION( "Default constructor" ) SECTION( "Default constructor" )
{ {
...@@ -28,9 +28,36 @@ TEST_CASE("DelayTimer", "[DelayTimer]" ) ...@@ -28,9 +28,36 @@ TEST_CASE("DelayTimer", "[DelayTimer]" )
CHECK_FALSE( dt.check(false) ); CHECK_FALSE( dt.check(false) );
CHECK_FALSE( dt.check(true) ); CHECK_FALSE( dt.check(true) );
} }
SECTION( "Copy" )
{
DelayTimer dt1(100,50);
DelayTimer dt2(200,100);
dt1 = dt2;
SECTION( "Working" ) REQUIRE( dt1.getOnDelay() == 200 );
REQUIRE( dt1.getOffDelay() == 100 );
dt1.check(true);
msleep(220);
CHECK( dt1.get() );
CHECK_FALSE( dt2.get() );
}
SECTION( "Other" )
{ {
DelayTimer dt(100,50);
REQUIRE( dt.getOnDelay() == 100 );
REQUIRE( dt.getOffDelay() == 50 );
dt.set(150,200);
REQUIRE( dt.getOnDelay() == 150 );
REQUIRE( dt.getOffDelay() == 200 );
}
}
// -----------------------------------------------------------------------------
TEST_CASE("[DelayTimer]: working", "[DelayTimer]" )
{
DelayTimer dt(100,60); DelayTimer dt(100,60);
CHECK_FALSE( dt.get() ); CHECK_FALSE( dt.get() );
CHECK_FALSE( dt.check(false) ); CHECK_FALSE( dt.check(false) );
...@@ -65,10 +92,10 @@ TEST_CASE("DelayTimer", "[DelayTimer]" ) ...@@ -65,10 +92,10 @@ TEST_CASE("DelayTimer", "[DelayTimer]" )
msleep(60); msleep(60);
CHECK( dt.check(true) ); CHECK( dt.check(true) );
CHECK( dt.get() ); CHECK( dt.get() );
} }
// -----------------------------------------------------------------------------
SECTION( "Debounce" ) TEST_CASE("[DelayTimer]: debounce", "[DelayTimer]" )
{ {
DelayTimer dt(150,100); DelayTimer dt(150,100);
CHECK_FALSE( dt.get() ); CHECK_FALSE( dt.get() );
CHECK_FALSE( dt.check(false) ); CHECK_FALSE( dt.check(false) );
...@@ -101,32 +128,5 @@ TEST_CASE("DelayTimer", "[DelayTimer]" ) ...@@ -101,32 +128,5 @@ TEST_CASE("DelayTimer", "[DelayTimer]" )
msleep(40); msleep(40);
CHECK_FALSE( dt.check(false) ); CHECK_FALSE( dt.check(false) );
CHECK_FALSE( dt.get() ); CHECK_FALSE( dt.get() );
}
SECTION( "Copy" )
{
DelayTimer dt1(100,50);
DelayTimer dt2(200,100);
dt1 = dt2;
REQUIRE( dt1.getOnDelay() == 200 );
REQUIRE( dt1.getOffDelay() == 100 );
dt1.check(true);
msleep(220);
CHECK( dt1.get() );
CHECK_FALSE( dt2.get() );
}
SECTION( "Other" )
{
DelayTimer dt(100,50);
REQUIRE( dt.getOnDelay() == 100 );
REQUIRE( dt.getOffDelay() == 50 );
dt.set(150,200);
REQUIRE( dt.getOnDelay() == 150 );
REQUIRE( dt.getOffDelay() == 200 );
}
} }
// -----------------------------------------------------------------------------
#include <catch.hpp> #include <catch.hpp>
// -----------------------------------------------------------------------------
#include <iostream> #include <iostream>
// -----------------------------------------------------------------------------
using namespace std;
#include "Exceptions.h" #include "Exceptions.h"
#include "UniXML.h" #include "UniXML.h"
#include "UniSetTypes.h" #include "UniSetTypes.h"
// -----------------------------------------------------------------------------
using namespace std;
// -----------------------------------------------------------------------------
TEST_CASE("UniXML", "[unixml][basic]" ) TEST_CASE("UniXML", "[unixml][basic]" )
{ {
SECTION( "Default constructor" ) SECTION( "Default constructor" )
...@@ -44,9 +44,16 @@ TEST_CASE("UniXML", "[unixml][basic]" ) ...@@ -44,9 +44,16 @@ TEST_CASE("UniXML", "[unixml][basic]" )
// remove // remove
// copy // copy
// nextNode // nextNode
}
// -----------------------------------------------------------------------------
TEST_CASE("UniXML::iterator", "[unixml][iterator][basic]" )
{
UniXML uxml("tests_unixml.xml");
CHECK( uxml.isOpen() );
xmlNode* cnode = uxml.findNode(uxml.getFirstNode(),"UniSet");
CHECK( cnode != NULL );
SECTION( "Iterator" );
{
UniXML::iterator it(cnode); UniXML::iterator it(cnode);
CHECK( it.getCurrent() != 0 ); CHECK( it.getCurrent() != 0 );
it = uxml.begin(); it = uxml.begin();
...@@ -112,5 +119,4 @@ TEST_CASE("UniXML", "[unixml][basic]" ) ...@@ -112,5 +119,4 @@ TEST_CASE("UniXML", "[unixml][basic]" )
CHECK( it.getPIntProp("zero",20) == 0 ); CHECK( it.getPIntProp("zero",20) == 0 );
CHECK( it.getPIntProp("negative",20) == -10 ); CHECK( it.getPIntProp("negative",20) == -10 );
CHECK( it.getPIntProp("unknown",20) == 20 ); CHECK( it.getPIntProp("unknown",20) == 20 );
}
} }
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