Skip to content
Snippets Groups Projects
Commit 6b5a524c authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Fixed operator << overloading for MeshFunction and added unit tests.

parent d84865cd
No related branches found
No related tags found
No related merge requests found
...@@ -184,6 +184,11 @@ class MeshFunction : ...@@ -184,6 +184,11 @@ class MeshFunction :
}; };
template< typename Mesh,
int MeshEntityDimension,
typename Real >
std::ostream& operator << ( std::ostream& str, const MeshFunction< Mesh, MeshEntityDimension, Real >& f );
} // namespace Functions } // namespace Functions
} // namespace TNL } // namespace TNL
......
...@@ -571,7 +571,17 @@ setupSynchronizer( DistributedMeshType *distributedMesh ) ...@@ -571,7 +571,17 @@ setupSynchronizer( DistributedMeshType *distributedMesh )
this->synchronizer.setDistributedGrid( distributedMesh ); this->synchronizer.setDistributedGrid( distributedMesh );
} }
template< typename Mesh,
int MeshEntityDimension,
typename Real >
std::ostream&
operator << ( std::ostream& str, const MeshFunction< Mesh, MeshEntityDimension, Real >& f )
{
str << f.getData();
return str;
}
} // namespace Functions } // namespace Functions
} // namespace TNL } // namespace TNL
IF( BUILD_CUDA ) IF( BUILD_CUDA )
CUDA_ADD_EXECUTABLE( MeshFunctionTest MeshFunctionTest.h MeshFunctionTest.cu OPTIONS ${CXX_TESTS_FLAGS} )
TARGET_COMPILE_OPTIONS( MeshFunctionTest PRIVATE ${CXX_TESTS_FLAGS} )
TARGET_LINK_LIBRARIES( MeshFunctionTest ${GTEST_BOTH_LIBRARIES} tnl )
CUDA_ADD_EXECUTABLE( BoundaryMeshFunctionTest BoundaryMeshFunctionTest.h BoundaryMeshFunctionTest.cu OPTIONS ${CXX_TESTS_FLAGS} ) CUDA_ADD_EXECUTABLE( BoundaryMeshFunctionTest BoundaryMeshFunctionTest.h BoundaryMeshFunctionTest.cu OPTIONS ${CXX_TESTS_FLAGS} )
TARGET_LINK_LIBRARIES( BoundaryMeshFunctionTest ${GTEST_BOTH_LIBRARIES} TARGET_COMPILE_OPTIONS( BoundaryMeshFunctionTest PRIVATE ${CXX_TESTS_FLAGS} )
tnl ) TARGET_LINK_LIBRARIES( BoundaryMeshFunctionTest ${GTEST_BOTH_LIBRARIES} tnl )
ELSE( BUILD_CUDA ) ELSE( BUILD_CUDA )
ADD_EXECUTABLE( MeshFunctionTest MeshFunctionTest.h MeshFunctionTest.cpp )
TARGET_COMPILE_OPTIONS( MeshFunctionTest PRIVATE ${CXX_TESTS_FLAGS} )
TARGET_LINK_LIBRARIES( MeshFunctionTest ${GTEST_BOTH_LIBRARIES} tnl )
ADD_EXECUTABLE( BoundaryMeshFunctionTest BoundaryMeshFunctionTest.h BoundaryMeshFunctionTest.cpp ) ADD_EXECUTABLE( BoundaryMeshFunctionTest BoundaryMeshFunctionTest.h BoundaryMeshFunctionTest.cpp )
TARGET_COMPILE_OPTIONS( BoundaryMeshFunctionTest PRIVATE ${CXX_TESTS_FLAGS} ) TARGET_COMPILE_OPTIONS( BoundaryMeshFunctionTest PRIVATE ${CXX_TESTS_FLAGS} )
TARGET_LINK_LIBRARIES( BoundaryMeshFunctionTest ${GTEST_BOTH_LIBRARIES} TARGET_LINK_LIBRARIES( BoundaryMeshFunctionTest ${GTEST_BOTH_LIBRARIES} tnl )
tnl )
ENDIF( BUILD_CUDA ) ENDIF( BUILD_CUDA )
ADD_TEST( MeshFunctionTest ${EXECUTABLE_OUTPUT_PATH}/MeshFunctionTest${CMAKE_EXECUTABLE_SUFFIX} )
ADD_TEST( BoundaryMeshFunctionTest ${EXECUTABLE_OUTPUT_PATH}/BoundaryMeshFunctionTest${CMAKE_EXECUTABLE_SUFFIX} ) ADD_TEST( BoundaryMeshFunctionTest ${EXECUTABLE_OUTPUT_PATH}/BoundaryMeshFunctionTest${CMAKE_EXECUTABLE_SUFFIX} )
\ No newline at end of file
/***************************************************************************
MeshFunctionTest.cpp - description
-------------------
begin : Sep 11, 2018
copyright : (C) 2018 by oberhuber
email : tomas.oberhuber@fjfi.cvut.cz
***************************************************************************/
/* See Copyright Notice in tnl/Copyright */
#include "MeshFunctionTest.h"
/***************************************************************************
MeshFunctionTest.cu - description
-------------------
begin : Sep 11, 2018
copyright : (C) 2018 by oberhuber
email : tomas.oberhuber@fjfi.cvut.cz
***************************************************************************/
/* See Copyright Notice in tnl/Copyright */
#include "MeshFunctionTest.h"
/***************************************************************************
MeshFunctionTest.h - description
-------------------
begin : Sep 11, 2018
copyright : (C) 2018 by oberhuber
email : tomas.oberhuber@fjfi.cvut.cz
***************************************************************************/
/* See Copyright Notice in tnl/Copyright */
#pragma once
#include "../GtestMissingError.h"
#ifdef HAVE_GTEST
#include <gtest/gtest.h>
#include <sstream>
#include <TNL/Functions/MeshFunction.h>
#include <TNL/Meshes/Grid.h>
#include <TNL/Pointers/SharedPointer.h>
TEST( MeshFunctionTest, BasicConstructor )
{
using Grid = TNL::Meshes::Grid< 2 >;
TNL::Functions::MeshFunction< Grid > meshFunction;
}
TEST( MeshFunctionTest, OstreamOperatorTest )
{
using GridType = TNL::Meshes::Grid< 2 >;
using GridPointer = TNL::Pointers::SharedPointer< GridType >;
using CoordinatesType = typename GridType::CoordinatesType;
using MeshFunctionType = TNL::Functions::MeshFunction< GridType >;
GridPointer grid;
grid->setDimensions( CoordinatesType( 3, 3 ) );
MeshFunctionType meshFunction( grid );
meshFunction.getData().setValue( 1.0 );
const char* str = "[ 1, 1, 1, 1, 1, 1, 1, 1, 1 ]";
std::stringstream string_stream1, string_stream2( str );
string_stream1 << meshFunction;
EXPECT_EQ( string_stream1.str(), string_stream2.str() );
}
#endif
int main( int argc, char* argv[] )
{
#ifdef HAVE_GTEST
::testing::InitGoogleTest( &argc, argv );
return RUN_ALL_TESTS();
#else
throw GtestMissingError();
#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