test-update-value.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2020 Intel Corporation. All Rights Reserved.
3 
4 //#cmake:add-file ../../../../common/utilities/number/stabilized-value.h
5 
6 
7 #include "../../../test.h"
8 #include <../common/utilities/number/stabilized-value.h>
9 
10 using namespace utilities::number;
11 
12 // Test group description:
13 // * This tests group verifies stabilized_value class.
14 //
15 // Current test description:
16 // * Verify if history is filled with a stable value and then filled with required percentage
17 // of new val, new val is returned as stable value.
18 TEST_CASE( "update stable value - nominal", "[stabilized value]" )
19 {
20  stabilized_value< float > stab_value( 10 );
21  CHECK_NOTHROW( stab_value.add( 55.0f ) );
22  CHECK_NOTHROW( stab_value.add( 55.0f ) );
23  CHECK_NOTHROW( stab_value.add( 55.0f ) );
24  CHECK_NOTHROW( stab_value.add( 55.0f ) );
25  CHECK_NOTHROW( stab_value.add( 60.0f ) );
26  CHECK_NOTHROW( stab_value.add( 60.0f ) );
27  CHECK_NOTHROW( stab_value.add( 60.0f ) );
28  CHECK_NOTHROW( stab_value.add( 60.0f ) );
29  CHECK_NOTHROW( stab_value.add( 60.0f ) );
30  CHECK_NOTHROW( stab_value.add( 60.0f ) );
31 
32  CHECK( 60.0f == stab_value.get( 0.6f ) );
33  CHECK_NOTHROW( stab_value.add( 35.0f ) );
34  CHECK_NOTHROW( stab_value.add( 35.0f ) );
35  CHECK_NOTHROW( stab_value.add( 35.0f ) );
36  CHECK_NOTHROW( stab_value.add( 35.0f ) );
37  CHECK_NOTHROW( stab_value.add( 35.0f ) );
38  CHECK( 60.0f == stab_value.get( 0.6f ) );
39 
40  CHECK_NOTHROW( stab_value.add( 35.0f ) );
41  CHECK( 35.0f == stab_value.get( 0.6f ) );
42 }
43 
44 
45 
46 TEST_CASE("update stable value - last stable not in history", "[stabilized value]")
47 {
48  stabilized_value< float > stab_value(10);
49  stab_value.add(55.0f);
50  CHECK(55.0f == stab_value.get(1.0f));
51 
52  stab_value.add(60.0f);
53  stab_value.add(60.0f);
54  stab_value.add(60.0f);
55  stab_value.add(60.0f);
56  stab_value.add(60.0f);
57  stab_value.add(60.0f);
58  stab_value.add(60.0f);
59  stab_value.add(60.0f);
60  stab_value.add(60.0f);
61  CHECK(55.0f == stab_value.get(1.0f));
62  CHECK(60.0 == stab_value.get(0.9f));
63  stab_value.add(70.0f);
64  CHECK(60.0f == stab_value.get(1.0f));
65 }
66 
67 TEST_CASE("update stable value - last stable is in history", "[stabilized value]")
68 {
69  stabilized_value< float > stab_value(10);
70  stab_value.add(55.0f);
71  stab_value.add(60.0f);
72  stab_value.add(60.0f);
73  CHECK(55.0f == stab_value.get(0.8f));
74 }
TEST_CASE("update stable value - nominal","[stabilized value]")
GLdouble f
T get(float stabilization_percent=0.75f) const
#define CHECK_NOTHROW(...)
Definition: catch.hpp:17421
#define CHECK(condition)


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:50:11