MONC
Functions/Subroutines
test_conversions_mod Module Reference

Functions/Subroutines

subroutine test_is_integer ()
 
subroutine test_is_real ()
 
subroutine test_is_logical ()
 
subroutine test_real_to_integer ()
 
subroutine test_logical_to_integer ()
 
subroutine test_logical_to_real ()
 
subroutine test_integer_to_string ()
 
subroutine test_real_to_string ()
 
subroutine test_logical_to_string ()
 
subroutine test_string_to_generic ()
 
subroutine test_string_to_generic_copy ()
 
subroutine test_integer_to_generic ()
 
subroutine test_integer_to_generic_copy ()
 
subroutine test_real_to_generic ()
 
subroutine test_real_to_generic_copy ()
 
subroutine test_logical_to_generic ()
 
subroutine test_logical_to_generic_copy ()
 

Function/Subroutine Documentation

◆ test_integer_to_generic()

subroutine test_conversions_mod::test_integer_to_generic ( )

Definition at line 167 of file test_conversions.F90.

167  integer :: test_int
168  integer, pointer :: retrieval_int
169  class(*), pointer :: generic_data
170 
171  test_int = 72
172 
173  generic_data => conv_to_generic(test_int, .false.)
174  call assert_true(associated(generic_data), "Generic data not null")
175  retrieval_int => conv_to_integer(generic_data, .false.)
176  call assert_true(associated(retrieval_int), "Retrieved integer not null")
177  call assert_equals(test_int, retrieval_int, "To and from generic integers are equal")
178  retrieval_int = 13
179  call assert_equals(test_int, retrieval_int, "To and from generic integers are equal after modification")
Here is the caller graph for this function:

◆ test_integer_to_generic_copy()

subroutine test_conversions_mod::test_integer_to_generic_copy ( )

Definition at line 185 of file test_conversions.F90.

185  integer :: test_int
186  integer, pointer :: retrieval_int
187  class(*), pointer :: generic_data
188 
189  test_int = 72
190 
191  generic_data => conv_to_generic(test_int, .true.)
192  call assert_true(associated(generic_data), "Generic data not null")
193  retrieval_int => conv_to_integer(generic_data, .false.)
194  call assert_true(associated(retrieval_int), "Retrieved integer not null")
195  retrieval_int = 19
196  call assert_not_equals(test_int, retrieval_int, "To and from generic integers are different")
197 
198  generic_data => conv_to_generic(test_int, .false.)
199  retrieval_int => conv_to_integer(generic_data, .true.)
200  call assert_true(associated(generic_data), "Generic data not null")
201  retrieval_int = 32
202  call assert_not_equals(test_int, retrieval_int, "To and from generic integers are different")
Here is the caller graph for this function:

◆ test_integer_to_string()

subroutine test_conversions_mod::test_integer_to_string ( )

Definition at line 84 of file test_conversions.F90.

84  integer :: test_int, retrieve_int
85  character(len=15) :: retrieval_string
86 
87  test_int = 92
88  retrieval_string = conv_to_string(test_int)
89  retrieve_int = conv_to_integer(retrieval_string)
90  call assert_equals(retrieve_int, test_int, "Integers after conversion to and from string are equal")
Here is the caller graph for this function:

◆ test_is_integer()

subroutine test_conversions_mod::test_is_integer ( )

Definition at line 13 of file test_conversions.F90.

13  call assert_true(conv_is_integer("1"), "Small number")
14  call assert_true(conv_is_integer("9874321"), "Large number")
15  call assert_true(conv_is_integer("-1024"), "Negative number")
16  call assert_true(conv_is_integer("+986"), "Positive number")
17  call assert_false(conv_is_integer("1.2"), "Floating point")
18  call assert_false(conv_is_integer("ABCD"), "Non number")
19  call assert_false(conv_is_integer("87T"), "Numeric and non number characters")
20  call assert_false(conv_is_integer("0xAB"), "Hexadecimal")
Here is the caller graph for this function:

◆ test_is_logical()

subroutine test_conversions_mod::test_is_logical ( )

Definition at line 41 of file test_conversions.F90.

41  call assert_true(conv_is_logical("true"), "True value")
42  call assert_true(conv_is_logical("false"), "False value")
43  call assert_false(conv_is_logical("1"), "One number")
44  call assert_false(conv_is_logical("0"), "Zero number")
45  call assert_false(conv_is_logical("dsfdsfsd"), "Random characters")
46  call assert_false(conv_is_logical("truexyz"), "Append characters to true")
Here is the caller graph for this function:

◆ test_is_real()

subroutine test_conversions_mod::test_is_real ( )

Definition at line 25 of file test_conversions.F90.

25  call assert_true(conv_is_real("1"), "Small number")
26  call assert_true(conv_is_real("9874321"), "Large number")
27  call assert_true(conv_is_real("-1024"), "Negative number")
28  call assert_true(conv_is_real("+986"), "Positive number")
29  call assert_true(conv_is_real("1.2"), "Floating point")
30  call assert_true(conv_is_real("45432.2343"), "Large floating point")
31  call assert_true(conv_is_real("1e2"), "Exponent floating point")
32  call assert_true(conv_is_real("1.56e+6"), "Large positive exponent floating point")
33  call assert_true(conv_is_real("765.98e-6"), "Small negative exponent floating point")
34  call assert_false(conv_is_real("ABCD"), "Non number")
35  call assert_false(conv_is_real("87T"), "Numeric and non numeric characters")
36  call assert_false(conv_is_real("0xAB"), "Hexadecimal")
Here is the caller graph for this function:

◆ test_logical_to_generic()

subroutine test_conversions_mod::test_logical_to_generic ( )

Definition at line 249 of file test_conversions.F90.

249  logical :: test_logical
250  logical, pointer :: retrieval_logical
251  class(*), pointer :: generic_data
252 
253  test_logical = .true.
254 
255  generic_data => conv_to_generic(test_logical, .false.)
256  call assert_true(associated(generic_data), "Generic data not null")
257  retrieval_logical => conv_to_logical(generic_data, .false.)
258  call assert_true(associated(retrieval_logical), "Retrieved logical not null")
259  call assert_equals(test_logical, retrieval_logical, "To and from generic logicals are equal")
260  retrieval_logical = .false.
261  call assert_equals(test_logical, retrieval_logical, "To and from generic logicals are equal after modification")
Here is the caller graph for this function:

◆ test_logical_to_generic_copy()

subroutine test_conversions_mod::test_logical_to_generic_copy ( )

Definition at line 267 of file test_conversions.F90.

267  logical :: test_logical
268  logical, pointer :: retrieval_logical
269  class(*), pointer :: generic_data
270 
271  test_logical = .true.
272 
273  generic_data => conv_to_generic(test_logical, .true.)
274  call assert_true(associated(generic_data), "Generic data not null")
275  retrieval_logical => conv_to_logical(generic_data, .false.)
276  call assert_true(associated(retrieval_logical), "Retrieved logical not null")
277  retrieval_logical = .false.
278  call assert_not_equals(test_logical, retrieval_logical, "To and from generic logicals are different")
279 
280  generic_data => conv_to_generic(test_logical, .false.)
281  call assert_true(associated(generic_data), "Generic data not null")
282  retrieval_logical => conv_to_logical(generic_data, .true.)
283  retrieval_logical = .false.
284  call assert_not_equals(test_logical, retrieval_logical, "To and from generic logicals are different")
Here is the caller graph for this function:

◆ test_logical_to_integer()

subroutine test_conversions_mod::test_logical_to_integer ( )

Definition at line 62 of file test_conversions.F90.

62  logical :: test_logical, retrieve_logical
63  integer :: retrieval_int
64 
65  test_logical=.true.
66  retrieval_int = conv_to_integer(test_logical)
67  retrieve_logical = conv_to_logical(retrieval_int)
68  call assert_equals(retrieve_logical, test_logical, "Logicals after conversion to and from integer are equal")
Here is the caller graph for this function:

◆ test_logical_to_real()

subroutine test_conversions_mod::test_logical_to_real ( )

Definition at line 73 of file test_conversions.F90.

73  logical :: test_logical, retrieve_logical
74  real :: retrieval_real
75 
76  test_logical=.true.
77  retrieval_real = conv_to_real(test_logical)
78  retrieve_logical = conv_to_logical(retrieval_real)
79  call assert_equals(retrieve_logical, test_logical, "Logicals after conversion to and from real are equal")
Here is the caller graph for this function:

◆ test_logical_to_string()

subroutine test_conversions_mod::test_logical_to_string ( )

Definition at line 108 of file test_conversions.F90.

108  logical :: test_logical, retrieve_logical
109  character(len=5) :: retrieval_string
110 
111  test_logical = .true.
112  retrieval_string = conv_to_string(test_logical)
113  retrieve_logical = conv_to_logical(retrieval_string)
114  call assert_equals(retrieve_logical, test_logical, "Logicals after conversion to and from string are equal")
Here is the caller graph for this function:

◆ test_real_to_generic()

subroutine test_conversions_mod::test_real_to_generic ( )

Definition at line 208 of file test_conversions.F90.

208  real :: test_real
209  real, pointer :: retrieval_real
210  class(*), pointer :: generic_data
211 
212  test_real = 72.92
213 
214  generic_data => conv_to_generic(test_real, .false.)
215  call assert_true(associated(generic_data), "Generic data not null")
216  retrieval_real => conv_to_real(generic_data, .false.)
217  call assert_true(associated(retrieval_real), "Retrieved real not null")
218  call assert_equals(test_real, retrieval_real, "To and from generic reals are equal")
219  retrieval_real = 13.1
220  call assert_equals(test_real, retrieval_real, "To and from generic real are equal after modification")
Here is the caller graph for this function:

◆ test_real_to_generic_copy()

subroutine test_conversions_mod::test_real_to_generic_copy ( )

Definition at line 226 of file test_conversions.F90.

226  real :: test_real
227  real, pointer :: retrieval_real
228  class(*), pointer :: generic_data
229 
230  test_real = 72.92
231 
232  generic_data => conv_to_generic(test_real, .true.)
233  call assert_true(associated(generic_data), "Generic data not null")
234  retrieval_real => conv_to_real(generic_data, .false.)
235  call assert_true(associated(retrieval_real), "Retrieved real not null")
236  retrieval_real = 19
237  call assert_not_equals(test_real, retrieval_real, "To and from generic reals are different")
238 
239  generic_data => conv_to_generic(test_real, .false.)
240  call assert_true(associated(generic_data), "Generic data not null")
241  retrieval_real => conv_to_real(generic_data, .true.)
242  retrieval_real = 32
243  call assert_not_equals(test_real, retrieval_real, "To and from generic reals are different")
Here is the caller graph for this function:

◆ test_real_to_integer()

subroutine test_conversions_mod::test_real_to_integer ( )

Definition at line 51 of file test_conversions.F90.

51  real :: test_real, retrieve_real
52  integer :: retrieval_int
53 
54  test_real=19
55  retrieval_int = conv_to_integer(test_real)
56  retrieve_real = conv_to_real(retrieval_int)
57  call assert_equals(retrieve_real, test_real, "Reals after conversion to and from integer are equal")
Here is the caller graph for this function:

◆ test_real_to_string()

subroutine test_conversions_mod::test_real_to_string ( )

Definition at line 95 of file test_conversions.F90.

95  real :: test_real, retrieve_real, diff
96  character(len=30) :: retrieval_string
97 
98  test_real = 63.45
99  retrieval_string = conv_to_string(test_real)
100  retrieve_real = conv_to_real(retrieval_string)
101  ! Conversion to string is not exact, therefore take the difference and ensure it is within permissable bounds
102  diff = test_real - retrieve_real
103  call assert_true(diff .gt. -0.0001 .and. diff .lt. 0.0001, "Reals after conversion to and from string are equal")
Here is the caller graph for this function:

◆ test_string_to_generic()

subroutine test_conversions_mod::test_string_to_generic ( )

Definition at line 120 of file test_conversions.F90.

120  character(len=100) :: test_string
121  character(len=100), pointer :: retrieval_string
122  class(*), pointer :: generic_data
123 
124  integer :: i
125  do i=1,100
126  test_string(i:i)='C'
127  end do
128 
129  generic_data => conv_to_generic(test_string, .false.)
130  call assert_true(associated(generic_data), "Generic data not null")
131  retrieval_string => conv_to_string(generic_data, .false., 100)
132  call assert_true(associated(retrieval_string), "Retrieved string not null")
133  call assert_equals(test_string, retrieval_string, "To and from generic strings are equal")
134  retrieval_string(4:6) = "LKJ"
135  call assert_equals(test_string, retrieval_string, "To and from generic strings are equal after one modified")
Here is the caller graph for this function:

◆ test_string_to_generic_copy()

subroutine test_conversions_mod::test_string_to_generic_copy ( )

Definition at line 141 of file test_conversions.F90.

141  character(len=100) :: test_string
142  character(len=100), pointer :: retrieval_string
143  class(*), pointer :: generic_data
144 
145  integer :: i
146  do i=1,100
147  test_string(i:i)='C'
148  end do
149 
150  generic_data => conv_to_generic(test_string, .true.)
151  call assert_true(associated(generic_data), "Generic data not null")
152  retrieval_string => conv_to_string(generic_data, .false., 100)
153  call assert_true(associated(retrieval_string), "Retrieved string not null")
154  retrieval_string(4:6) = "LKJ"
155  call assert_not_equals(test_string, retrieval_string, "To and from generic strings are different")
156 
157  generic_data => conv_to_generic(test_string, .false.)
158  retrieval_string => conv_to_string(generic_data, .true., 100)
159  call assert_true(associated(generic_data), "Generic data not null")
160  retrieval_string(4:6) = "LKJ"
161  call assert_not_equals(test_string, retrieval_string, "To and from generic strings are different")
Here is the caller graph for this function: