Commit aaf5a790 authored by Pavel Vainerman's avatar Pavel Vainerman

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

parent 189567d1
......@@ -80,19 +80,19 @@ class Calibration
long getValue( long raw, bool crop_raw=false );
/*! Возвращает минимальное значение 'x' встретившееся в диаграмме */
inline long getMinVal(){ return minVal; }
inline long getMinValue(){ return minVal; }
/*! Возвращает максимальное значение 'x' втретившееся в диаграмме */
inline long getMaxVal(){ return maxVal; }
inline long getMaxValue(){ return maxVal; }
/*! Возвращает крайнее левое значение 'x' встретившееся в диаграмме (ПОСЛЕ СОРТИРОВКИ ПО ВОЗРАСТАНИЮ 'x'!) */
inline long getLeftVal(){ return leftVal; }
inline long getLeftValue(){ return leftVal; }
/*! Возвращает крайнее правое значение 'x' встретившееся в диаграмме (ПОСЛЕ СОРТИРОВКИ ПО ВОЗРАСТАНИЮ 'x'!) */
inline long getRightVal(){ return rightVal; }
inline long getRightValue(){ return rightVal; }
/*!
Получение сырого значения по калиброванному
\param range=true вернуть крайнее значение в диаграмме
если cal<leftVal или cal>rightVal (т.е. выходит за диапазон)
если cal < leftVal или cal > rightVal (т.е. выходит за диапазон)
Если range=false, то может быть возвращено значение outOfRange.
*/
......
......@@ -6,7 +6,7 @@ tests_SOURCES = tests.cc calibration.cc digitalfilter.cc
tests_LDADD = $(top_builddir)/lib/libUniSet2.la $(top_builddir)/extensions/lib/libUniSet2Extensions.la
tests_CPPFLAGS = -I$(top_builddir)/include -I$(top_builddir)/extensions/include -I$(includedir)/Catch
tests_with_conf_SOURCES = tests_with_conf.cc
tests_with_conf_SOURCES = tests_with_conf.cc calibration.cc
tests_with_conf_LDADD = $(top_builddir)/lib/libUniSet2.la $(top_builddir)/extensions/lib/libUniSet2Extensions.la
tests_with_conf_CPPFLAGS = -I$(top_builddir)/include -I$(top_builddir)/extensions/include -I$(includedir)/Catch
......
#include <catch.hpp>
#include "Configuration.h"
#include "Extensions.h"
#include "Calibration.h"
using namespace std;
using namespace UniSetTypes;
using namespace UniSetExtensions;
TEST_CASE("Calibration","[calibration]")
{
Calibration* cal = buildCalibrationDiagram("testcal");
CHECK( cal!=0 );
SECTION("getValue")
{
REQUIRE( cal->getValue(1500,true) == 600 );
REQUIRE( cal->getValue(1500,false) == Calibration::outOfRange );
REQUIRE( cal->getValue(1000) == 600 );
REQUIRE( cal->getValue(933) == 466 );
REQUIRE( cal->getValue(800) == 300 );
REQUIRE( cal->getValue(700) == 250 );
REQUIRE( cal->getValue(600) == 200 );
REQUIRE( cal->getValue(650) > 200 );
REQUIRE( cal->getValue(650) < 250 );
REQUIRE( cal->getValue(200)== 60 );
REQUIRE( cal->getValue(50) == 20 );
REQUIRE( cal->getValue(10) == 0 );
REQUIRE( cal->getValue(5) == 0 );
REQUIRE( cal->getValue(0) == 0 );
REQUIRE( cal->getValue(-5) == 0 );
REQUIRE( cal->getValue(-10) == 0 );
REQUIRE( cal->getValue(-50) == -20 );
REQUIRE( cal->getValue(-500) == -80 );
REQUIRE( cal->getValue(-900) == -250 );
REQUIRE( cal->getValue(-1000) == -300 );
REQUIRE( cal->getValue(-1050,true) == -300 );
REQUIRE( cal->getValue(-1050,false) == Calibration::outOfRange );
}
SECTION("Other function")
{
REQUIRE( cal->getMinValue() == -300 );
REQUIRE( cal->getMaxValue() == 600 );
REQUIRE( cal->getLeftValue() == -300 );
REQUIRE( cal->getRightValue() == 600 );
REQUIRE( cal->getRawValue(-80) == -500 );
REQUIRE( cal->getRawValue(-500,false) == Calibration::outOfRange );
REQUIRE( cal->getRawValue(-500,true) == -1000 );
REQUIRE( cal->getRawValue(150) == 500 );
REQUIRE( cal->getRawValue(700,false) == Calibration::outOfRange );
REQUIRE( cal->getRawValue(700,true) == 1000 );
REQUIRE( cal->getMinRaw() == -1000 );
REQUIRE( cal->getMaxRaw() == 1000 );
REQUIRE( cal->getLeftRaw() == -1000 );
REQUIRE( cal->getRightRaw() == 1000 );
}
}
#if 0
#include <iostream>
#include "Exceptions.h"
......
......@@ -86,4 +86,31 @@
<messages name="messages" idfromfile="1" >
</messages>
<Calibrations name="Calibrations">
<diagram name="testcal">
<point x="-1000" y="-300"/>
<point x="-900" y="-250"/>
<point x="-800" y="-200"/>
<point x="-700" y="-150"/>
<point x="-600" y="-100"/>
<point x="-500" y="-80"/>
<point x="-200" y="-60"/>
<point x="-100" y="-60"/>
<point x="-50" y="-20"/>
<point x="-10" y="0"/>
<point x="0" y="0"/>
<point x="10" y="0"/>
<point x="50" y="20"/>
<point x="100" y="60"/>
<point x="200" y="60"/>
<point x="300" y="80"/>
<point x="400" y="100"/>
<point x="500" y="150"/>
<point x="600" y="200"/>
<point x="700" y="250"/>
<point x="800" y="300"/>
<point x="900" y="400"/>
<point x="1000" y="600"/>
</diagram>
</Calibrations>
</UNISETPLC>
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