8 #include "../../../test.h" 9 #include <../common/utilities/number/stabilized-value.h> 21 TEST_CASE(
"multi-threading",
"[stabilized value]" )
23 std::atomic< float > inserted_val_1 = { 20.0f };
24 std::atomic< float > inserted_val_2 = { 55.0f };
25 std::vector< float > values_vec;
29 std::thread
first( [&]() {
30 std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
31 for(
int i = 0;
i < 1000;
i++ )
35 stab_value.
add( inserted_val_1 );
39 stab_value.
add( inserted_val_1 );
41 stab_value.
add( inserted_val_2 );
42 std::this_thread::sleep_for( std::chrono::milliseconds( 1 ) );
47 std::thread second( [&]() {
48 while( stab_value.
empty() )
52 for(
int i = 0;
i < 1000;
i++ )
54 values_vec.push_back( stab_value.
get( 0.6f ) );
56 std::this_thread::sleep_for( std::chrono::milliseconds( 1 ) );
60 if(
first.joinable() )
62 if( second.joinable() )
67 for(
auto val : values_vec )
68 if(
val == inserted_val_1 )
71 CHECK( count == 1000 );
T get(float stabilization_percent=0.75f) const
TEST_CASE("multi-threading","[stabilized value]")