Skip to content

Commit a3de6a7

Browse files
committed
fix: shift tests
1 parent 615de11 commit a3de6a7

File tree

2 files changed

+23
-31
lines changed

2 files changed

+23
-31
lines changed

src/forcolormap.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ pure subroutine shift(self, sh)
10381038
class(Colormap), intent(inout) :: self
10391039
integer, intent(in) :: sh !! The shift
10401040

1041-
self%map = cshift(self%map, sh)
1041+
self%map = cshift(self%map, sh, dim=1)
10421042
end subroutine
10431043

10441044
!> Extracts colors from the colormap based on specified number of levels (extractedLevels).

test/check.f90

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -960,34 +960,30 @@ subroutine test_043(id, nfail)
960960
call report_test(name, ok, id, nfail)
961961
end subroutine test_043
962962

963-
!> shift(+1) should match the intrinsic circular shift `cshift(map, +1)`.
963+
!> shift(+1) should match the intrinsic circular shift `cshift(map, +1, dim=1)`.
964964
subroutine test_044(id, nfail)
965965
use forcolormap, only: Colormap, wp
966966
integer, intent(inout) :: id, nfail
967967
character(len=*), parameter :: name = "Colormap%shift: matches cshift for sh=+1"
968968
logical :: ok
969969
type(Colormap) :: cm
970-
integer :: map(3,3)
971-
integer :: ref(3,3)
972-
integer :: i
973-
integer :: r, g, b, rr, gg, bb
970+
integer :: map(0:2,3)
971+
integer :: ref(0:2,3)
972+
integer :: i, r, g, b
974973

975-
map(1,:) = [ 10, 20, 30 ]
976-
map(2,:) = [ 40, 50, 60 ]
977-
map(3,:) = [ 70, 80, 90 ]
974+
map(0,:) = [ 10, 20, 30 ]
975+
map(1,:) = [ 40, 50, 60 ]
976+
map(2,:) = [ 70, 80, 90 ]
978977

979978
call cm%create("custom", 0.0_wp, 2.0_wp, map)
980979

981-
ref = cshift(map, 1)
980+
ref = cshift(map, 1, dim=1)
982981
call cm%shift(1)
983982

984983
ok = .true.
985984
do i = 0, cm%get_levels()-1
986985
call cm%get_RGB(i, r, g, b)
987-
rr = ref(i+1, 1)
988-
gg = ref(i+1, 2)
989-
bb = ref(i+1, 3)
990-
ok = ok .and. (r == rr) .and. (g == gg) .and. (b == bb)
986+
ok = ok .and. (r == ref(i,1)) .and. (g == ref(i,2)) .and. (b == ref(i,3))
991987
end do
992988

993989
call report_test(name, ok, id, nfail)
@@ -1086,34 +1082,30 @@ subroutine test_048(id, nfail)
10861082
call report_test(name, ok, id, nfail)
10871083
end subroutine test_048
10881084

1089-
!> shift(-1) should match the intrinsic circular shift `cshift(map, -1)`.
1085+
!> shift(-1) should match the intrinsic circular shift `cshift(map, -1, dim=1)`.
10901086
subroutine test_049(id, nfail)
10911087
use forcolormap, only: Colormap, wp
10921088
integer, intent(inout) :: id, nfail
10931089
character(len=*), parameter :: name = "Colormap%shift: matches cshift for sh=-1"
10941090
logical :: ok
10951091
type(Colormap) :: cm
1096-
integer :: map(3,3)
1097-
integer :: ref(3,3)
1098-
integer :: i
1099-
integer :: r, g, b, rr, gg, bb
1092+
integer :: map(0:2,3)
1093+
integer :: ref(0:2,3)
1094+
integer :: i, r, g, b
11001095

1101-
map(1,:) = [ 10, 20, 30 ]
1102-
map(2,:) = [ 40, 50, 60 ]
1103-
map(3,:) = [ 70, 80, 90 ]
1096+
map(0,:) = [ 10, 20, 30 ]
1097+
map(1,:) = [ 40, 50, 60 ]
1098+
map(2,:) = [ 70, 80, 90 ]
11041099

11051100
call cm%create("custom", 0.0_wp, 2.0_wp, map)
11061101

1107-
ref = cshift(map, -1)
1102+
ref = cshift(map, -1, dim=1)
11081103
call cm%shift(-1)
11091104

11101105
ok = .true.
11111106
do i = 0, cm%get_levels()-1
11121107
call cm%get_RGB(i, r, g, b)
1113-
rr = ref(i+1, 1)
1114-
gg = ref(i+1, 2)
1115-
bb = ref(i+1, 3)
1116-
ok = ok .and. (r == rr) .and. (g == gg) .and. (b == bb)
1108+
ok = ok .and. (r == ref(i,1)) .and. (g == ref(i,2)) .and. (b == ref(i,3))
11171109
end do
11181110

11191111
call report_test(name, ok, id, nfail)
@@ -1260,22 +1252,22 @@ subroutine test_054(id, nfail)
12601252

12611253
call cmap%create("discrete", 0.0_wp, 2.0_wp, test_colormap)
12621254

1263-
ref = cshift(test_colormap, 2)
1255+
ref = cshift(test_colormap, 2, dim=1)
12641256
call cmap%shift(2)
12651257
ok = .true.
12661258
do i = 0, 6
12671259
call cmap%get_RGB(i, r, g, b)
12681260
ok = ok .and. (r == ref(i,1)) .and. (g == ref(i,2)) .and. (b == ref(i,3))
12691261
end do
12701262

1271-
ref = cshift(ref, -1)
1263+
ref = cshift(ref, -1, dim=1)
12721264
call cmap%shift(-1)
12731265
do i = 0, 6
12741266
call cmap%get_RGB(i, r, g, b)
12751267
ok = ok .and. (r == ref(i,1)) .and. (g == ref(i,2)) .and. (b == ref(i,3))
12761268
end do
12771269

1278-
ref = cshift(ref, -1)
1270+
ref = cshift(ref, -1, dim=1)
12791271
call cmap%shift(-1)
12801272
do i = 0, 6
12811273
call cmap%get_RGB(i, r, g, b)
@@ -1576,7 +1568,7 @@ subroutine test_067(id, nfail)
15761568

15771569
sh = 100
15781570
shmod = modulo(sh, cm%get_levels())
1579-
ref = cshift(test_colormap, shmod)
1571+
ref = cshift(test_colormap, shmod, dim=1)
15801572

15811573
call cm%shift(sh)
15821574

0 commit comments

Comments
 (0)