-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
75 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
add_cpp_test( ranges.AnyView AnyView.test.cpp ) | ||
add_cpp_test( ranges.AnyView.usecase usecase.test.cpp ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// include Catch2 | ||
#include <catch2/catch_test_macros.hpp> | ||
|
||
// what we are testing | ||
#include "tools/ranges/AnyView.hpp" | ||
|
||
// other includes | ||
#include <forward_list> | ||
#include <list> | ||
#include <vector> | ||
#include "tools/ranges/make_view.hpp" | ||
|
||
// convenience typedefs | ||
using namespace njoy::tools::ranges; | ||
|
||
// a class with data | ||
class Data { | ||
|
||
std::vector< double > data_; | ||
|
||
public: | ||
|
||
Data( int size ) : data_( size ) { | ||
|
||
for ( unsigned int i = 0; i < data_.size(); ++i ) { | ||
|
||
data_[i] = i; | ||
} | ||
} | ||
|
||
const std::vector< double >& data() const { return this->data_; } | ||
|
||
auto view() const { return njoy::tools::ranges::make_view( this->data() ); } | ||
}; | ||
|
||
SCENARIO( "use case" ) { | ||
|
||
GIVEN( "a data object that returns a range" ) { | ||
|
||
Data object( 1000 ); | ||
|
||
WHEN( "retrieving the view and converting it to an AnyView" ) { | ||
|
||
AnyRandomAccessView< double > chunk = object.view(); | ||
|
||
THEN( "an AnyView can be constructed and members can be tested" ) { | ||
|
||
CHECK( 1000 == chunk.size() ); | ||
CHECK( false == chunk.empty() ); | ||
CHECK( false == bool( chunk ) ); | ||
|
||
unsigned int counter = 0; | ||
for ( auto value : chunk ) { | ||
|
||
++counter; | ||
} | ||
CHECK( 1000 == counter ); | ||
|
||
CHECK( 0 == chunk[0] ); | ||
CHECK( 999 == chunk[999] ); | ||
|
||
CHECK( 0 == chunk.at( 0 ) ); | ||
CHECK( 999 == chunk.at( 999 ) ); | ||
|
||
CHECK( 0 == chunk.front() ); | ||
CHECK( 999 == chunk.back() ); | ||
} // THEN | ||
} // WHEN | ||
} // GIVEN | ||
} // SCENARIO |