Skip to content

Commit c934362

Browse files
committed
Update diff tests.
1 parent b6f0ab1 commit c934362

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Features available from the latest git source
2222
- new procedures `arg`, `argd` and `argpi`
2323
[#498](https://github.com/fortran-lang/stdlib/pull/498)
2424
- new procedure `diff`
25+
[#605](https://github.com/fortran-lang/stdlib/pull/605)
2526

2627
Changes to existing modules
2728

src/stdlib_math_diff.fypp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ contains
1919
integer :: n_, i
2020

2121
n_ = optval(n, 1)
22+
23+
if (size(X) <= n_) then
24+
allocate(Y(0))
25+
return
26+
end if
2227

2328
Y = X
2429
do i = 1, n_
@@ -44,6 +49,11 @@ contains
4449
dim_ = 1
4550
end if
4651

52+
if (size(X, dim_) <= n_) then
53+
allocate(Y(0, 0))
54+
return
55+
end if
56+
4757
Y = X
4858
if (dim_ == 1) then
4959
do i = 1, n_

src/tests/math/test_stdlib_math.fypp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ contains
378378
type(error_type), allocatable, intent(out) :: error
379379
${t1}$ :: x(6) = [${t1}$ :: 0, 5, 15, 30, 50, 75]
380380
${t1}$ :: A(1, 3) = reshape([${t1}$ :: 1, 3, 5], [1, 3])
381+
${t1}$ :: B(2) = [${t1}$ :: 1, 2]
381382

382383
call check(error, all_close(diff(x), [${t1}$ :: 5, 10, 15, 20, 25]), &
383384
"diff(x) in test_diff_real_${k1}$ failed")
@@ -391,6 +392,10 @@ contains
391392
"diff(x, n=1, dim=2) in test_diff_real_${k1}$ failed")
392393
if (allocated(error)) return
393394

395+
call check(error, size(diff(B, 2)), 0, "size(diff(B, 2)) in test_diff_real_${k1}$ failed")
396+
if (allocated(error)) return
397+
call check(error, size(diff(B, 3)), 0, "size(diff(B, 3)) in test_diff_real_${k1}$ failed")
398+
394399
end subroutine test_diff_real_${k1}$
395400
#:endfor
396401

@@ -399,6 +404,7 @@ contains
399404
type(error_type), allocatable, intent(out) :: error
400405
${t1}$ :: x(6) = [${t1}$ :: 0, 5, 15, 30, 50, 75]
401406
${t1}$ :: A(1, 3) = reshape([${t1}$ :: 1, 3, 5], [1, 3])
407+
${t1}$ :: B(2) = [${t1}$ :: 1, 2]
402408

403409
call check(error, all(diff(x) == [${t1}$ :: 5, 10, 15, 20, 25]), &
404410
"diff(x) in test_diff_int_${k1}$ failed")
@@ -412,6 +418,10 @@ contains
412418
"diff(A, n=1, dim=2) in test_diff_int_${k1}$ failed")
413419
if (allocated(error)) return
414420

421+
call check(error, size(diff(B, 2)), 0, "size(diff(B, 2)) in test_diff_real_${k1}$ failed")
422+
if (allocated(error)) return
423+
call check(error, size(diff(B, 3)), 0, "size(diff(B, 3)) in test_diff_real_${k1}$ failed")
424+
415425
end subroutine test_diff_int_${k1}$
416426
#:endfor
417427

0 commit comments

Comments
 (0)