Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/unit tests for chgres_cube.fd/utils.f90 #276

Merged
merged 16 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ if(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release|RelWithDebInfo|MinSizeRel)$")
CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
message(STATUS "Set BUILD_TESTING to YES and build unit testing package under tests")
set(BUILD_TESTING "YES")
endif()

# Set compiler flags.
Expand Down Expand Up @@ -72,6 +74,12 @@ endif()

add_subdirectory(sorc)

# Run unit tests.
include(CTest)
if(BUILD_TESTING)
add_subdirectory(unit-tests)
endif()

# If doxygen documentation we enabled, build it.
if(ENABLE_DOCS)
find_package(Doxygen REQUIRED)
Expand Down
34 changes: 34 additions & 0 deletions unit-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
set(fortran_src
edwardhartnett marked this conversation as resolved.
Show resolved Hide resolved
../sorc/chgres_cube.fd/utils.f90
to_upper_lower.F90)

if(CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel)$")
edwardhartnett marked this conversation as resolved.
Show resolved Hide resolved
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -r8 -convert big_endian -assume byterecl")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU)$")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ffree-line-length-0 -fdefault-real-8 -fconvert=big-endian")
endif()

include_directories(
${PROJECT_SOURCE_DIR}
)

set(exe_name to_upper_lower)
add_executable(${exe_name} ${fortran_src})
target_link_libraries(
${exe_name}
nemsio::nemsio
sfcio::sfcio
sigio::sigio
bacio::bacio_4
sp::sp_d
w3nco::w3nco_d
esmf
wgrib2::wgrib2_lib
wgrib2::wgrib2_api
MPI::MPI_Fortran
NetCDF::NetCDF_Fortran)
if(OpenMP_Fortran_FOUND)
target_link_libraries(${exe_name} OpenMP::OpenMP_Fortran)
endif()

install(TARGETS ${exe_name} RUNTIME DESTINATION ${exec_dir})
48 changes: 48 additions & 0 deletions unit-tests/to_upper_lower.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
!> @file
edwardhartnett marked this conversation as resolved.
Show resolved Hide resolved

!> output
edwardhartnett marked this conversation as resolved.
Show resolved Hide resolved
!!
!! Unit test for to_upper() and to_lower() functions under UFS_UTILS package
!! exit code other than zero identify issue found
!!

program to_upper_lower


implicit none

logical :: match_result

character(len=12) :: test_input_char_1, test_input_char_2, u_st_base, l_st_base

u_st_base="STAGGERLOCCE"
l_st_base="staggerlocce"
test_input_char_1="sTAGGErLOCCE"
test_input_char_2="staGGErLOCCE"

print*, "-------- Starting Unit Testing to_upper_lower ----------"
print*, "------------ Testing to_lower and to_upper --------------"

!-------------------------------------------------------------------------
! Execute testing below by running target function with testing string
! When match_result set to be T - compare to base line is identical
! When match_result set to be F - compare to base line is NOT identical
!-------------------------------------------------------------------------

call to_lower(test_input_char_1)
match_result = test_input_char_1 == l_st_base
edwardhartnett marked this conversation as resolved.
Show resolved Hide resolved

call to_upper(test_input_char_2)
match_result = test_input_char_2 == u_st_base

!-------------------------------------------------------------------------
! Display final result
!-------------------------------------------------------------------------

if (.not.match_result) then
stop 'unit_test to_lower and to_upper failed'
else
print*, "Pass"
endif

end program