Skip to content
Snippets Groups Projects
Commit 69e2aa89 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Added tests for EllpackIndexMultimap

parent 5fd17c63
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,12 @@ SET_TARGET_PROPERTIES( MeshEntityTest${mpiExt}${debugExt} PROPERTIES COMPILE_FLA
TARGET_LINK_LIBRARIES( MeshEntityTest${mpiExt}${debugExt} ${GTEST_BOTH_LIBRARIES}
tnl${mpiExt}${debugExt}-${tnlVersion} )
ADD_EXECUTABLE( MultimapTest${mpiExt}${debugExt} ${headers} MultimapTest.cpp )
SET_TARGET_PROPERTIES( MultimapTest${mpiExt}${debugExt} PROPERTIES COMPILE_FLAGS "${CXX_TESTS_FLAGS}" )
TARGET_LINK_LIBRARIES( MultimapTest${mpiExt}${debugExt} ${GTEST_BOTH_LIBRARIES}
tnl${mpiExt}${debugExt}-${tnlVersion} )
ADD_TEST( MeshTest${mpiExt}${debugExt} ${EXECUTABLE_OUTPUT_PATH}/MeshTest${mpiExt}${debugExt} )
ADD_TEST( MeshEntityTest${mpiExt}${debugExt} ${EXECUTABLE_OUTPUT_PATH}/MeshEntityTest${mpiExt}${debugExt} )
ADD_TEST( MultimapTest${mpiExt}${debugExt} ${EXECUTABLE_OUTPUT_PATH}/MultimapTest${mpiExt}${debugExt} )
#include <TNL/Experimental/Multimaps/EllpackIndexMultimap.h>
using namespace TNL;
using IndexType = int;
using Device = Devices::Host;
using LocalIndexType = short;
#ifdef HAVE_GTEST
#include "gtest/gtest.h"
TEST( MultimapTest, TestTypedefs )
{
using MultimapType = TNL::EllpackIndexMultimap< IndexType, Device, LocalIndexType >;
const bool same_index = std::is_same< typename MultimapType::IndexType, IndexType >::value;
ASSERT_TRUE( same_index );
const bool same_device = std::is_same< typename MultimapType::DeviceType, Device >::value;
ASSERT_TRUE( same_device );
const bool same_localindex = std::is_same< typename MultimapType::LocalIndexType, LocalIndexType >::value;
ASSERT_TRUE( same_localindex );
}
TEST( MultimapTest, TestSettingValues )
{
using MultimapType = TNL::EllpackIndexMultimap< IndexType, Device, LocalIndexType >;
IndexType inputs = 10;
LocalIndexType values = 4;
LocalIndexType allocatedValues = 2;
MultimapType map;
map.setRanges( inputs, values );
ASSERT_EQ( map.getKeysRange(), inputs );
ASSERT_EQ( map.getValuesRange(), values );
typename MultimapType::ValuesAllocationVectorType allocationRanges;
ASSERT_TRUE( allocationRanges.setSize( inputs ) );
allocationRanges.setValue( allocatedValues );
ASSERT_TRUE( map.allocate( allocationRanges ) );
for( IndexType i = 0; i < inputs; i++ ) {
auto values = map.getValues( i );
const auto constValues = ( (const MultimapType) map ).getValues( i );
for( LocalIndexType o = 0; o < allocatedValues; o++ )
values.setOutput( o, i + o );
for( LocalIndexType o = 0; o < allocatedValues; o++ ) {
ASSERT_EQ( values.getOutput( o ), i + o );
ASSERT_EQ( values[ o ], i + o );
ASSERT_EQ( constValues.getOutput( o ), i + o );
ASSERT_EQ( constValues[ o ], i + o );
}
for( LocalIndexType o = 0; o < allocatedValues; o++ )
values[ o ] = i * o;
for( LocalIndexType o = 0; o < allocatedValues; o++ ) {
ASSERT_EQ( values.getOutput( o ), i * o );
ASSERT_EQ( values[ o ], i * o );
ASSERT_EQ( constValues.getOutput( o ), i * o );
ASSERT_EQ( constValues[ o ], i * o );
}
}
}
#endif
int main( int argc, char* argv[] )
{
#ifdef HAVE_GTEST
::testing::InitGoogleTest( &argc, argv );
return RUN_ALL_TESTS();
#else
return EXIT_FAILURE;
#endif
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment