Skip to content

Commit 5a96061

Browse files
author
Esteban Pavese
committed
added tests
1 parent 3e640b2 commit 5a96061

4 files changed

Lines changed: 21 additions & 6 deletions

File tree

flatdata-cpp/benchmark/main.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,14 @@ main( int argc, char** argv )
215215
}
216216
else if ( args.at( "lookup" ).asBool( ) )
217217
{
218-
size_t num_runs = args.at( "--num-runs" ).asLong( );
219218
call_for_graph< DoLookup >( argv[ 2 ], num_nodes, num_runs );
220219
}
221220
else if ( args.at( "bfs" ).asBool( ) )
222221
{
223-
size_t num_runs = args.at( "--num-runs" ).asLong( );
224222
call_for_graph< DoBFS >( argv[ 2 ], num_nodes, num_runs );
225223
}
226224
else if ( args.at( "dijkstra" ).asBool( ) )
227225
{
228-
size_t num_runs = args.at( "--num-runs" ).asLong( );
229226
call_for_graph< DoDijkstra >( argv[ 2 ], num_nodes, num_runs );
230227
}
231228
}

flatdata-cpp/include/flatdata/internal/Reader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ struct Reader< Tagged< T, INVALID_VALUE >, offset, num_bits, struct_size_bytes >
159159
template < typename U >
160160
operator std::optional< U >( ) const
161161
{
162-
boost::optional< U > bopt = this;
162+
boost::optional< U > bopt = static_cast< boost::optional< U > >( *this );
163163
if ( bopt )
164164
{
165165
return *bopt;

flatdata-cpp/include/flatdata/internal/Writer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ struct Writer< Tagged< T, INVALID_VALUE >, offset, num_bits, struct_size_bytes >
128128

129129
operator std::optional< T >( ) const
130130
{
131-
boost::optional< T > bopt = this;
131+
boost::optional< T > bopt = static_cast< boost::optional< T > >( *this );
132132
if ( bopt )
133133
{
134134
return *bopt;

flatdata-cpp/test/StructTest.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,54 +43,72 @@ TEST_CASE( "Invalid values are handled", "[Struct]" )
4343
REQUIRE( static_cast< bool >( writer.invalid_zero ) == true );
4444
REQUIRE( static_cast< boost::optional< int8_t > >( writer.invalid_zero )
4545
== boost::optional< int8_t >( 10 ) );
46+
REQUIRE( static_cast< std::optional< int8_t > >( writer.invalid_zero )
47+
== std::optional< int8_t >( 10 ) );
4648
REQUIRE( *reader.invalid_zero == 10 );
4749
REQUIRE( static_cast< bool >( reader.invalid_zero ) == true );
4850
REQUIRE( static_cast< boost::optional< int8_t > >( reader.invalid_zero )
4951
== boost::optional< int8_t >( 10 ) );
52+
REQUIRE( static_cast< std::optional< int8_t > >( reader.invalid_zero )
53+
== std::optional< int8_t >( 10 ) );
5054

5155
writer.invalid_zero = 0;
5256
REQUIRE( *writer.invalid_zero == 0 );
5357
REQUIRE( static_cast< bool >( writer.invalid_zero ) == false );
5458
REQUIRE( static_cast< boost::optional< int8_t > >( writer.invalid_zero ) == boost::none );
59+
REQUIRE( static_cast< std::optional< int8_t > >( writer.invalid_zero ) == std::nullopt );
5560
REQUIRE( *reader.invalid_zero == 0 );
5661
REQUIRE( static_cast< bool >( reader.invalid_zero ) == false );
5762
REQUIRE( static_cast< boost::optional< int8_t > >( reader.invalid_zero ) == boost::none );
63+
REQUIRE( static_cast< std::optional< int8_t > >( reader.invalid_zero ) == std::nullopt );
5864

5965
writer.invalid_min_int = 10;
6066
REQUIRE( *writer.invalid_min_int == 10 );
6167
REQUIRE( static_cast< bool >( writer.invalid_min_int ) == true );
6268
REQUIRE( static_cast< boost::optional< int8_t > >( writer.invalid_min_int )
6369
== boost::optional< int8_t >( 10 ) );
70+
REQUIRE( static_cast< std::optional< int8_t > >( writer.invalid_min_int )
71+
== std::optional< int8_t >( 10 ) );
6472
REQUIRE( *reader.invalid_min_int == 10 );
6573
REQUIRE( static_cast< bool >( reader.invalid_min_int ) == true );
6674
REQUIRE( static_cast< boost::optional< int8_t > >( reader.invalid_min_int )
6775
== boost::optional< int8_t >( 10 ) );
76+
REQUIRE( static_cast< std::optional< int8_t > >( reader.invalid_min_int )
77+
== std::optional< int8_t >( 10 ) );
6878

6979
writer.invalid_min_int = -128;
7080
REQUIRE( *writer.invalid_min_int == -128 );
7181
REQUIRE( static_cast< bool >( writer.invalid_min_int ) == false );
7282
REQUIRE( static_cast< boost::optional< int8_t > >( writer.invalid_min_int ) == boost::none );
83+
REQUIRE( static_cast< std::optional< int8_t > >( writer.invalid_min_int ) == std::nullopt );
7384
REQUIRE( *reader.invalid_min_int == -128 );
7485
REQUIRE( static_cast< bool >( reader.invalid_min_int ) == false );
7586
REQUIRE( static_cast< boost::optional< int8_t > >( reader.invalid_min_int ) == boost::none );
87+
REQUIRE( static_cast< std::optional< int8_t > >( reader.invalid_min_int ) == std::nullopt );
7688

7789
writer.invalid_max_int = 10;
7890
REQUIRE( *writer.invalid_max_int == 10 );
7991
REQUIRE( static_cast< bool >( writer.invalid_max_int ) == true );
8092
REQUIRE( static_cast< boost::optional< int8_t > >( writer.invalid_max_int )
8193
== boost::optional< int8_t >( 10 ) );
94+
REQUIRE( static_cast< std::optional< int8_t > >( writer.invalid_max_int )
95+
== std::optional< int8_t >( 10 ) );
8296
REQUIRE( *reader.invalid_max_int == 10 );
8397
REQUIRE( static_cast< bool >( reader.invalid_max_int ) == true );
8498
REQUIRE( static_cast< boost::optional< int8_t > >( reader.invalid_max_int )
8599
== boost::optional< int8_t >( 10 ) );
100+
REQUIRE( static_cast< std::optional< int8_t > >( reader.invalid_max_int )
101+
== std::optional< int8_t >( 10 ) );
86102

87103
writer.invalid_max_int = 127;
88104
REQUIRE( *writer.invalid_max_int == 127 );
89105
REQUIRE( static_cast< bool >( writer.invalid_max_int ) == false );
90106
REQUIRE( static_cast< boost::optional< int8_t > >( writer.invalid_max_int ) == boost::none );
107+
REQUIRE( static_cast< std::optional< int8_t > >( writer.invalid_max_int ) == std::nullopt );
91108
REQUIRE( *reader.invalid_max_int == 127 );
92109
REQUIRE( static_cast< bool >( reader.invalid_max_int ) == false );
93110
REQUIRE( static_cast< boost::optional< int8_t > >( reader.invalid_max_int ) == boost::none );
111+
REQUIRE( static_cast< std::optional< int8_t > >( reader.invalid_max_int ) == std::nullopt );
94112
}
95113

96114
TEST_CASE( "Invalid values can be converted to string", "[Struct]" )
@@ -102,4 +120,4 @@ TEST_CASE( "Invalid values can be converted to string", "[Struct]" )
102120
invalid_max_int : 0,
103121
})";
104122
REQUIRE( ( *data ).to_string( ) == EXPECTED );
105-
}
123+
}

0 commit comments

Comments
 (0)