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

Исправил тесты iobase для работы в 64bit

parent b9c92a58
...@@ -506,6 +506,7 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname ...@@ -506,6 +506,7 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
# history of current unpublished changes # history of current unpublished changes
# Modbus: refactoring code and test (for 64bit) # Modbus: refactoring code and test (for 64bit)
# iobase: refactoring tests for 64bit
%changelog %changelog
* Mon Dec 12 2016 Pavel Vainerman <pv@altlinux.ru> 2.6-alt6 * Mon Dec 12 2016 Pavel Vainerman <pv@altlinux.ru> 2.6-alt6
......
#include <catch.hpp> #include <catch.hpp>
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include <memory> #include <memory>
#include <cmath>
#include "Exceptions.h" #include "Exceptions.h"
#include "Extensions.h" #include "Extensions.h"
#include "tests_with_sm.h" #include "tests_with_sm.h"
...@@ -17,6 +18,11 @@ static void init_test() ...@@ -17,6 +18,11 @@ static void init_test()
CHECK( shm != nullptr ); CHECK( shm != nullptr );
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
static float myRound( float v, size_t delim )
{
return ( std::round(v*delim) / (float)delim );
}
// -----------------------------------------------------------------------------
static bool init_iobase( IOBase* ib, const std::string& sensor ) static bool init_iobase( IOBase* ib, const std::string& sensor )
{ {
init_test(); init_test();
...@@ -262,7 +268,7 @@ TEST_CASE("[IOBase::calibration]: AI calibration", "[iobase][calibration][ai][ex ...@@ -262,7 +268,7 @@ TEST_CASE("[IOBase::calibration]: AI calibration", "[iobase][calibration][ai][ex
REQUIRE( IOBase::processingFasAO(&ib, shm, true) == 99.5f ); REQUIRE( IOBase::processingFasAO(&ib, shm, true) == 99.5f );
shm->setValue(ai, 994); shm->setValue(ai, 994);
REQUIRE( IOBase::processingFasAO(&ib, shm, true) == 99.4f ); REQUIRE( myRound( IOBase::processingFasAO(&ib, shm, true), 10 ) == 99.4f );
} }
SECTION("AI calibration rawdata=1 (asAI)") SECTION("AI calibration rawdata=1 (asAI)")
...@@ -374,19 +380,19 @@ TEST_CASE("[IOBase::calibration]: AI calibration (precision)", "[iobase][calibra ...@@ -374,19 +380,19 @@ TEST_CASE("[IOBase::calibration]: AI calibration (precision)", "[iobase][calibra
REQUIRE( IOBase::processingFasAO(&ib, shm, true) == 0 ); REQUIRE( IOBase::processingFasAO(&ib, shm, true) == 0 );
shm->setValue(ai, -990); shm->setValue(ai, -990);
REQUIRE( IOBase::processingFasAO(&ib, shm, true) == -0.99f ); REQUIRE( myRound( IOBase::processingFasAO(&ib, shm, true), 1000 ) == -0.99f );
shm->setValue(ai, -995); shm->setValue(ai, -995);
REQUIRE( IOBase::processingFasAO(&ib, shm, true) == -0.995f ); REQUIRE( myRound( IOBase::processingFasAO(&ib, shm, true), 1000 ) == -0.995f );
shm->setValue(ai, 1000); shm->setValue(ai, 1000);
REQUIRE( IOBase::processingFasAO(&ib, shm, true) == 1.0f ); REQUIRE( IOBase::processingFasAO(&ib, shm, true) == 1.0f );
shm->setValue(ai, 995); shm->setValue(ai, 995);
REQUIRE( IOBase::processingFasAO(&ib, shm, true) == 0.995f ); REQUIRE( myRound( IOBase::processingFasAO(&ib, shm, true), 1000 ) == 0.995f );
shm->setValue(ai, 994); shm->setValue(ai, 994);
REQUIRE( IOBase::processingFasAO(&ib, shm, true) == 0.994f ); REQUIRE( myRound( IOBase::processingFasAO(&ib, shm, true), 1000 ) == 0.994f );
} }
SECTION("AI calibration noprecision=1 (FasAO)") SECTION("AI calibration noprecision=1 (FasAO)")
...@@ -397,19 +403,19 @@ TEST_CASE("[IOBase::calibration]: AI calibration (precision)", "[iobase][calibra ...@@ -397,19 +403,19 @@ TEST_CASE("[IOBase::calibration]: AI calibration (precision)", "[iobase][calibra
REQUIRE( IOBase::processingFasAO(&ib, shm, true) == 0 ); REQUIRE( IOBase::processingFasAO(&ib, shm, true) == 0 );
shm->setValue(ai, -990); shm->setValue(ai, -990);
REQUIRE( IOBase::processingFasAO(&ib, shm, true) == -99.0f ); REQUIRE( myRound( IOBase::processingFasAO(&ib, shm, true), 100 ) == -99.0f );
shm->setValue(ai, -995); shm->setValue(ai, -995);
REQUIRE( IOBase::processingFasAO(&ib, shm, true) == -99.5f ); REQUIRE( myRound( IOBase::processingFasAO(&ib, shm, true), 100 ) == -99.5f );
shm->setValue(ai, 1000); shm->setValue(ai, 1000);
REQUIRE( IOBase::processingFasAO(&ib, shm, true) == 100.0f ); REQUIRE( IOBase::processingFasAO(&ib, shm, true) == 100.0f );
shm->setValue(ai, 995); shm->setValue(ai, 995);
REQUIRE( IOBase::processingFasAO(&ib, shm, true) == 99.5f ); REQUIRE( myRound( IOBase::processingFasAO(&ib, shm, true), 100 ) == 99.5f );
shm->setValue(ai, 994); shm->setValue(ai, 994);
REQUIRE( IOBase::processingFasAO(&ib, shm, true) == 99.4f ); REQUIRE( myRound( IOBase::processingFasAO(&ib, shm, true), 100 ) == 99.4f );
ib.noprecision = false; ib.noprecision = false;
} }
......
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