|
4 | 4 |
|
5 | 5 | module test_stdlib_math
|
6 | 6 | use testdrive, only : new_unittest, unittest_type, error_type, check, skip_test
|
7 |
| - use stdlib_math, only: clip, arg, argd, argpi, arange, is_close, all_close, diff, & |
| 7 | + use stdlib_math, only: clip, swap, arg, argd, argpi, arange, is_close, all_close, diff, & |
8 | 8 | arange, deg2rad, rad2deg
|
9 | 9 | use stdlib_kinds, only: int8, int16, int32, int64, sp, dp, xdp, qp
|
10 | 10 | implicit none
|
@@ -38,6 +38,15 @@ contains
|
38 | 38 | new_unittest("clip-real-quad", test_clip_rqp), &
|
39 | 39 | new_unittest("clip-real-quad-bounds", test_clip_rqp_bounds) &
|
40 | 40 |
|
| 41 | + !> Tests swap |
| 42 | + #:for k1, t1 in INT_KINDS_TYPES + REAL_KINDS_TYPES |
| 43 | + , new_unittest("swap_${k1}$", test_swap_${k1}$) & |
| 44 | + #:endfor |
| 45 | + #:for k1, t1 in CMPLX_KINDS_TYPES |
| 46 | + , new_unittest("swap_c${k1}$", test_swap_c${k1}$) & |
| 47 | + #:endfor |
| 48 | + , new_unittest("swap_str", test_swap_str) & |
| 49 | + |
41 | 50 | !> Tests for arg/argd/argpi
|
42 | 51 | #:for k1 in CMPLX_KINDS
|
43 | 52 | , new_unittest("arg-cmplx-${k1}$", test_arg_${k1}$) &
|
@@ -246,6 +255,55 @@ contains
|
246 | 255 |
|
247 | 256 | end subroutine test_clip_rqp_bounds
|
248 | 257 |
|
| 258 | + #:for k1, t1 in INT_KINDS_TYPES + REAL_KINDS_TYPES |
| 259 | + subroutine test_swap_${k1}$(error) |
| 260 | + type(error_type), allocatable, intent(out) :: error |
| 261 | + ${t1}$ :: x(3), y(3) |
| 262 | + |
| 263 | + x = [${t1}$ :: 1, 2, 3] |
| 264 | + y = [${t1}$ :: 4, 5, 6] |
| 265 | + |
| 266 | + call swap(x,y) |
| 267 | + |
| 268 | + call check(error, all( x == [${t1}$ :: 4, 5, 6] ) ) |
| 269 | + if (allocated(error)) return |
| 270 | + call check(error, all( y == [${t1}$ :: 1, 2, 3] ) ) |
| 271 | + if (allocated(error)) return |
| 272 | + end subroutine test_swap_${k1}$ |
| 273 | + #:endfor |
| 274 | + |
| 275 | + #:for k1, t1 in CMPLX_KINDS_TYPES |
| 276 | + subroutine test_swap_c${k1}$(error) |
| 277 | + type(error_type), allocatable, intent(out) :: error |
| 278 | + ${t1}$ :: x(3), y(3) |
| 279 | + |
| 280 | + x = cmplx( [1, 2, 3] , [4, 5, 6] ) |
| 281 | + y = cmplx( [4, 5, 6] , [1, 2, 3] ) |
| 282 | + |
| 283 | + call swap(x,y) |
| 284 | + |
| 285 | + call check(error, all( x == cmplx( [4, 5, 6] , [1, 2, 3] ) ) ) |
| 286 | + if (allocated(error)) return |
| 287 | + call check(error, all( y == cmplx( [1, 2, 3] , [4, 5, 6] ) ) ) |
| 288 | + if (allocated(error)) return |
| 289 | + end subroutine test_swap_c${k1}$ |
| 290 | + #:endfor |
| 291 | + |
| 292 | + subroutine test_swap_str(error) |
| 293 | + type(error_type), allocatable, intent(out) :: error |
| 294 | + character(5) :: x(2), y(2) |
| 295 | + |
| 296 | + x = ['abcde','fghij'] |
| 297 | + y = ['fghij','abcde'] |
| 298 | + |
| 299 | + call swap(x,y) |
| 300 | + |
| 301 | + call check(error, all( x == ['fghij','abcde'] ) ) |
| 302 | + if (allocated(error)) return |
| 303 | + call check(error, all( y == ['abcde','fghij'] ) ) |
| 304 | + if (allocated(error)) return |
| 305 | + end subroutine test_swap_str |
| 306 | + |
249 | 307 | #:for k1 in CMPLX_KINDS
|
250 | 308 | subroutine test_arg_${k1}$(error)
|
251 | 309 | type(error_type), allocatable, intent(out) :: error
|
|
0 commit comments