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 all 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
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ jobs:
mkdir build && cd build
cmake .. -DCMAKE_PREFIX_PATH='~;~/jasper;~/nceplibs'
make -j2
make test



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ jobs:
mkdir build && cd build
cmake .. -DCMAKE_PREFIX_PATH='~;~/jasper'
make -j2
make test



Expand Down
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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 @@ -73,6 +75,12 @@ endif()

add_subdirectory(sorc)

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

# If doxygen documentation we enabled, build it.
if(ENABLE_DOCS)
find_package(Doxygen REQUIRED)
Expand Down
8 changes: 8 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This is the CMake file for the tests directory of the UFS_UTILS
# project.
#
# Ed Hartnett 2/11/21

# Add the test subdirecotries.
add_subdirectory(chres_cube)

42 changes: 42 additions & 0 deletions tests/chres_cube/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This is the cmake build file for the tests directory of the
# UFS_UTILS project.
#
# George Gayno, Lin Gan, Ed Hartnett

set(fortran_src
"${CMAKE_SOURCE_DIR}/sorc/chgres_cube.fd/utils.f90"
ftst_utils.F90)

if(CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel)$")
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 ftst_utils)
add_executable(${exe_name} ${fortran_src})
add_test(NAME ftst_utils COMMAND ftst_utils)
target_link_libraries(
ftst_utils
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(ftst_utils OpenMP::OpenMP_Fortran)
endif()




48 changes: 48 additions & 0 deletions tests/chres_cube/ftst_utils.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
! Unit test for to_upper() and to_lower() functions under UFS_UTILS
! package, chres_cube utility.
!
! Lin Gan NCEP/EMC

program ftst_utils


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
if (.not.match_result) then
stop
endif

call to_upper(test_input_char_2)
match_result = test_input_char_2 == u_st_base
if (.not.match_result) then
stop
endif

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

print*, "OK"
print*, "SUCCESS!"

end program ftst_utils