ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
test_pm_str.F90
Go to the documentation of this file.
1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3!!!! !!!!
4!!!! ParaMonte: Parallel Monte Carlo and Machine Learning Library. !!!!
5!!!! !!!!
6!!!! Copyright (C) 2012-present, The Computational Data Science Lab !!!!
7!!!! !!!!
8!!!! This file is part of the ParaMonte library. !!!!
9!!!! !!!!
10!!!! LICENSE !!!!
11!!!! !!!!
12!!!! https://github.com/cdslaborg/paramonte/blob/main/LICENSE.md !!!!
13!!!! !!!!
14!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
15!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
16
24
26
27 use pm_str
28 use pm_kind, only: LK
29 use pm_test, only: test_type, LK
30 implicit none
31
32 private
33 public :: setTest
34 type(test_type) :: test
35
36!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37
38 interface
39 module function test_getMaxLoc_SK_1 () result(assertion); logical(LK) :: assertion; end function
40 module function test_getMaxVal_SK_1 () result(assertion); logical(LK) :: assertion; end function
41 module function test_getMinLoc_SK_1 () result(assertion); logical(LK) :: assertion; end function
42 module function test_getMinVal_SK_1 () result(assertion); logical(LK) :: assertion; end function
43 end interface
44
45!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46
47contains
48
49!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50
51 subroutine setTest()
52
53 implicit none
54
56
57 call test%run(test_getMaxLoc_SK_1, SK_"test_getMaxLoc_SK_1")
58 call test%run(test_getMaxVal_SK_1, SK_"test_getMaxVal_SK_1")
59 call test%run(test_getMinLoc_SK_1, SK_"test_getMinLoc_SK_1")
60 call test%run(test_getMinVal_SK_1, SK_"test_getMinVal_SK_1")
61 call test%run(test_getCharVec_SK_1, SK_"test_getCharVec_SK_1")
62 call test%run(test_getString_SK_1, SK_"test_getString_SK_1")
63
64 call test%summarize()
65
66 end subroutine setTest
67
68!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69
70 function test_getCharVec_SK_1() result(assertion)
71 logical(LK) :: assertion
72 assertion = all(getCharVec(SK_"ParaMonte") == [character(1,SK) :: 'P','a','r','a','M','o','n','t','e'])
73 end function
74
75!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76
77 function test_getString_SK_1() result(assertion)
78 logical(LK) :: assertion
79 assertion = getCharSeq([character(1,SK) :: 'P','a','r','a','M','o','n','t','e']) == SK_"ParaMonte"
80 end function
81
82!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83
84! function test_padString_1() result(assertion)
85! use pm_kind, only: IK
86! implicit none
87! logical(LK) :: assertion
88! integer(IK) , parameter :: lenPadded = 30_IK
89! character(*, SK), parameter :: string_nonPadded = "ParaMonte"
90! character(*, SK), parameter :: stringPadded_ref = "ParaMonte....................."
91! character(*, SK), parameter :: fill = "."
92! character(:, SK), allocatable :: strPadded
93! strPadded = getPadded(string_nonPadded, fill, lenPadded)
94! assertion = strPadded == stringPadded_ref .and. len(strPadded) == len(stringPadded_ref)
95! if (test%traceable .and. .not. assertion) then
96! ! LCOV_EXCL_START
97! write(test%disp%unit,"(*(g0))")
98! write(test%disp%unit,"(*(g0))") "string_nonPadded : '", string_nonPadded, "'"
99! write(test%disp%unit,"(*(g0))") "stringPadded_ref : '", stringPadded_ref, "'"
100! write(test%disp%unit,"(*(g0))") "strPadded : '", strPadded, "'"
101! write(test%disp%unit,"(*(g0))")
102! end if
103! ! LCOV_EXCL_STOP
104! end function test_padString_1
105!
106!!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107!
108! function test_padString_2() result(assertion)
109! use pm_kind, only: IK
110! implicit none
111! logical(LK) :: assertion
112! integer(IK) , parameter :: lenPadded = 9_IK
113! character(*, SK), parameter :: string_nonPadded = "ParaMonte"
114! character(*, SK), parameter :: stringPadded_ref = "ParaMonte"
115! character(*, SK), parameter :: fill = "."
116! character(:, SK), allocatable :: strPadded
117! strPadded = getPadded(string_nonPadded, fill, lenPadded)
118! assertion = strPadded == stringPadded_ref .and. len(strPadded) == len(stringPadded_ref)
119! if (test%traceable .and. .not. assertion) then
120! ! LCOV_EXCL_START
121! write(test%disp%unit,"(*(g0))")
122! write(test%disp%unit,"(*(g0))") "string_nonPadded : '", string_nonPadded, "'"
123! write(test%disp%unit,"(*(g0))") "stringPadded_ref : '", stringPadded_ref, "'"
124! write(test%disp%unit,"(*(g0))") "strPadded : '", strPadded, "'"
125! write(test%disp%unit,"(*(g0))")
126! end if
127! ! LCOV_EXCL_STOP
128! end function test_padString_2
129!
130!!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131!
132! !> \brief
133! !> When `len(string) > lenPadded`, the full string must be returned without any padding.
134! function test_padString_3() result(assertion)
135! use pm_kind, only: IK
136! implicit none
137! logical(LK) :: assertion
138! integer(IK) , parameter :: lenPadded = 5_IK
139! character(*, SK), parameter :: string_nonPadded = "ParaMonte"
140! character(*, SK), parameter :: stringPadded_ref = "ParaM"
141! character(*, SK), parameter :: fill = "."
142! character(:, SK), allocatable :: strPadded
143! strPadded = getPadded(string_nonPadded, fill, lenPadded)
144! assertion = strPadded == stringPadded_ref .and. len(strPadded) == lenPadded .and. strPadded == stringPadded_ref
145! if (test%traceable .and. .not. assertion) then
146! ! LCOV_EXCL_START
147! write(test%disp%unit,"(*(g0))")
148! write(test%disp%unit,"(*(g0))") "string_nonPadded : '", string_nonPadded, "'"
149! write(test%disp%unit,"(*(g0))") "stringPadded_ref : '", stringPadded_ref, "'"
150! write(test%disp%unit,"(*(g0))") "strPadded : '", strPadded, "'"
151! write(test%disp%unit,"(*(g0))")
152! end if
153! ! LCOV_EXCL_STOP
154! end function test_padString_3
155!
156!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157
158end module test_pm_str ! LCOV_EXCL_LINE
Generate and return a scalar string resulting from the concatenation of the individual elements (sing...
Definition: pm_str.F90:1347
Generate and return a vector of single-characters each element of which corresponds to one character ...
Definition: pm_str.F90:1242
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
This module contains classes and procedures for various string manipulations and inquiries.
Definition: pm_str.F90:49
character(*, SK), parameter MODULE_NAME
Definition: pm_str.F90:79
This module contains a simple unit-testing framework for the Fortran libraries, including the ParaMon...
Definition: pm_test.F90:42
This module contains tests of the module pm_str.
Definition: test_pm_str.F90:25
logical(LK) function test_getCharVec_SK_1()
Definition: test_pm_str.F90:71
subroutine setTest()
Definition: test_pm_str.F90:52
logical(LK) function test_getString_SK_1()
Definition: test_pm_str.F90:78
type(test_type) test
Definition: test_pm_str.F90:34
This is the derived type test_type for generating objects that facilitate testing of a series of proc...
Definition: pm_test.F90:209