Skip to content

Commit 7e4bd38

Browse files
authored
fix: Standardize precision alias in tests to wp (fixes #1343) (#1344)
Summary - Replace direct real64/dp usage in selected tests with wp alias for consistency with src/. - Tighten imports to follow project style (`use <module>, only:`) and source `wp` from `fortplot`. Changes - test/test_streamplot_interface_color.f90: use `wp` from `fortplot`; keep advanced API imports. - test/test_streamplot_arrows.f90: switch to explicit `fortplot` imports (`figure, streamplot, title, savefig, wp`). - test/test_png_file_size_scaling.f90: already used `wp` from `fortplot` (no change). - test/test_scatter_color_cycle.f90: import `wp` from `fortplot` alongside `figure_t`. Rationale - Align tests with repository guidelines: - Prefer `use fortplot, only: wp => real64` over intrinsic wp wiring in tests. - Use explicit-only imports for clarity and to prevent namespace bleed. Verification (local) Commands run from repository root: - make test-ci - Project compiled successfully; CI essential test suite completed successfully. - Sample excerpt: "CI essential test suite completed successfully". - make verify-artifacts - Artifact verification passed. - Sample excerpts: - "[ok] symlog ylabel shows superscript three (unicode)" - "[ok] output/example/fortran/pcolormesh_demo/pcolormesh_basic.pdf contains RGB Image XObject" - "Artifact verification passed." Artifacts - Example outputs unchanged under `output/` and `output/example/fortran/`. No rendering changes expected. Notes - Keeps functions small and focused; no behavioral changes, only style/consistency.
1 parent 54c1612 commit 7e4bd38

File tree

4 files changed

+39
-43
lines changed

4 files changed

+39
-43
lines changed

test/test_png_file_size_scaling.f90

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ program test_png_file_size_scaling
22
!! Test that PNG files scale appropriately with content complexity
33
use fortplot, only: figure_t, wp
44
use fortplot_logging, only: set_log_level, LOG_LEVEL_ERROR
5-
use, intrinsic :: iso_fortran_env, only: real64
65
implicit none
76

87
integer :: simple_size, complex_size, empty_size
@@ -78,13 +77,13 @@ end subroutine test_empty_plot
7877
subroutine test_simple_plot(file_size)
7978
integer, intent(out) :: file_size
8079
type(figure_t) :: plt
81-
real(real64), allocatable :: x(:), y(:)
80+
real(wp), allocatable :: x(:), y(:)
8281
character(len=256) :: output_dir, filename
8382

8483
call get_output_directory(output_dir)
8584
call plt%initialize(800, 600) ! Medium size
8685

87-
x = create_linspace(0.0_real64, 10.0_real64, 10)
86+
x = create_linspace(0.0_wp, 10.0_wp, 10)
8887
allocate(y(10))
8988
y = x
9089

@@ -100,21 +99,21 @@ end subroutine test_simple_plot
10099
subroutine test_complex_plot(file_size)
101100
integer, intent(out) :: file_size
102101
type(figure_t) :: plt
103-
real(real64), allocatable :: x(:), y1(:), y2(:), y3(:)
102+
real(wp), allocatable :: x(:), y1(:), y2(:), y3(:)
104103
character(len=256) :: output_dir, filename
105104
integer :: i
106105

107106
call get_output_directory(output_dir)
108107
call plt%initialize(1600, 1200) ! Large size for more data
109108

110-
x = create_linspace(0.0_real64, 10.0_real64, 5000) ! More data points
109+
x = create_linspace(0.0_wp, 10.0_wp, 5000) ! More data points
111110
allocate(y1(5000), y2(5000), y3(5000))
112111

113112
! Add multiple complex lines with high-frequency patterns
114113
do i = 1, size(x)
115-
y1(i) = sin(x(i) * 10.0_real64) * cos(x(i) * 20.0_real64)
116-
y2(i) = exp(-x(i)/5.0_real64) * sin(x(i) * 15.0_real64)
117-
y3(i) = sin(x(i) * 30.0_real64) * cos(x(i) * 25.0_real64)
114+
y1(i) = sin(x(i) * 10.0_wp) * cos(x(i) * 20.0_wp)
115+
y2(i) = exp(-x(i)/5.0_wp) * sin(x(i) * 15.0_wp)
116+
y3(i) = sin(x(i) * 30.0_wp) * cos(x(i) * 25.0_wp)
118117
end do
119118

120119
call plt%add_plot(x, y1, label='High-frequency oscillation 1')
@@ -193,22 +192,22 @@ end function get_file_size
193192

194193
function create_linspace(start, stop, n) result(arr)
195194
!! Create linearly spaced array from start to stop with n points
196-
real(real64), intent(in) :: start, stop
195+
real(wp), intent(in) :: start, stop
197196
integer, intent(in) :: n
198-
real(real64), allocatable :: arr(:)
197+
real(wp), allocatable :: arr(:)
199198
integer :: i
200-
real(real64) :: dx
199+
real(wp) :: dx
201200

202201
allocate(arr(n))
203202

204203
if (n == 1) then
205204
arr(1) = start
206205
else
207-
dx = (stop - start) / real(n - 1, real64)
206+
dx = (stop - start) / real(n - 1, wp)
208207
do i = 1, n
209-
arr(i) = start + real(i - 1, real64) * dx
208+
arr(i) = start + real(i - 1, wp) * dx
210209
end do
211210
end if
212211
end function create_linspace
213212

214-
end program test_png_file_size_scaling
213+
end program test_png_file_size_scaling

test/test_scatter_color_cycle.f90

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
program test_scatter_color_cycle
22
!! Verify scatter plots share the default color cycle with line plots
3-
use, intrinsic :: iso_fortran_env, only: dp => real64
4-
use fortplot, only: figure_t
3+
use fortplot, only: figure_t, wp
54
use fortplot_figure_plot_management, only: next_plot_color
65
implicit none
76

87
type(figure_t) :: fig
9-
real(dp) :: x(5), y_line(5), y_scatter(5)
10-
real(dp) :: expected_color(3)
11-
real(dp) :: scatter_color(3)
8+
real(wp) :: x(5), y_line(5), y_scatter(5)
9+
real(wp) :: expected_color(3)
10+
real(wp) :: scatter_color(3)
1211

1312
integer :: i
1413

15-
x = [(real(i, dp), i = 1, size(x))]
14+
x = [(real(i, wp), i = 1, size(x))]
1615
y_line = x
17-
y_scatter = x + 1.0_dp
16+
y_scatter = x + 1.0_wp
1817

1918
call fig%initialize()
2019

@@ -26,7 +25,7 @@ program test_scatter_color_cycle
2625

2726
scatter_color = fig%plots(fig%plot_count)%color
2827

29-
if (any(abs(scatter_color - expected_color) > 1.0e-12_dp)) then
28+
if (any(abs(scatter_color - expected_color) > 1.0e-12_wp)) then
3029
print *, 'FAIL: scatter default color diverged from shared cycle'
3130
print *, ' expected:', expected_color
3231
print *, ' actual :', scatter_color

test/test_streamplot_arrows.f90

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
program test_streamplot_arrows
22
!! Verify streamplot arrow rendering via matplotlib-style wrapper
3-
use fortplot
4-
use, intrinsic :: iso_fortran_env, only: real64
3+
use fortplot, only: figure, streamplot, title, savefig, wp
54
use test_output_helpers, only: ensure_test_output_dir
65
implicit none
76

8-
real(real64), allocatable :: x(:), y(:)
9-
real(real64), allocatable :: u(:,:), v(:,:)
7+
real(wp), allocatable :: x(:), y(:)
8+
real(wp), allocatable :: u(:,:), v(:,:)
109
character(len=:), allocatable :: outdir
1110
integer :: i, j, nx, ny
1211

@@ -16,22 +15,22 @@ program test_streamplot_arrows
1615
allocate(x(nx), y(ny), u(nx, ny), v(nx, ny))
1716

1817
do i = 1, nx
19-
x(i) = real(i-1, real64) / real(nx-1, real64)
18+
x(i) = real(i-1, wp) / real(nx-1, wp)
2019
end do
2120
do j = 1, ny
22-
y(j) = real(j-1, real64) / real(ny-1, real64)
21+
y(j) = real(j-1, wp) / real(ny-1, wp)
2322
end do
2423

2524
! Simple rotational field
2625
do j = 1, ny
2726
do i = 1, nx
28-
u(i,j) = -(y(j) - 0.5_real64)
29-
v(i,j) = (x(i) - 0.5_real64)
27+
u(i,j) = -(y(j) - 0.5_wp)
28+
v(i,j) = (x(i) - 0.5_wp)
3029
end do
3130
end do
3231

3332
call figure()
34-
call streamplot(x, y, u, v, density=1.0_real64, arrowsize=1.0_real64, arrowstyle='->')
33+
call streamplot(x, y, u, v, density=1.0_wp, arrowsize=1.0_wp, arrowstyle='->')
3534
call title('streamplot arrows smoke test')
3635
call savefig(trim(outdir)//'streamplot_arrows.png')
3736

test/test_streamplot_interface_color.f90

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
program test_streamplot_interface_color
2-
use, intrinsic :: iso_fortran_env, only: real64
2+
use fortplot, only: wp
33
use fortplot_matplotlib_advanced, only: streamplot, get_global_figure, ensure_global_figure_initialized
44
use fortplot_figure_core, only: figure_t
55
use fortplot_plot_data, only: plot_data_t
66
implicit none
77

8-
real(real64), dimension(5) :: x
9-
real(real64), dimension(5) :: y
10-
real(real64), dimension(5,5) :: u, v
8+
real(wp), dimension(5) :: x
9+
real(wp), dimension(5) :: y
10+
real(wp), dimension(5,5) :: u, v
1111
class(figure_t), pointer :: fig
1212
type(plot_data_t), pointer :: plots(:)
1313
integer :: i, j, n
14-
real(real64), dimension(3) :: ref_color
14+
real(wp), dimension(3) :: ref_color
1515
logical :: all_same
1616

1717
! Setup a simple vector field
1818
do i = 1, 5
19-
x(i) = real(i-1, real64)
20-
y(i) = real(i-1, real64)
19+
x(i) = real(i-1, wp)
20+
y(i) = real(i-1, wp)
2121
end do
2222
do j = 1, 5
2323
do i = 1, 5
24-
u(i,j) = 1.0_real64
25-
v(i,j) = 0.0_real64
24+
u(i,j) = 1.0_wp
25+
v(i,j) = 0.0_wp
2626
end do
2727
end do
2828

@@ -40,7 +40,7 @@ program test_streamplot_interface_color
4040
ref_color = plots(1)%color
4141
all_same = .true.
4242
do i = 2, n
43-
if (any(abs(plots(i)%color - ref_color) > 1.0e-12_real64)) then
43+
if (any(abs(plots(i)%color - ref_color) > 1.0e-12_wp)) then
4444
all_same = .false.
4545
exit
4646
end if
@@ -52,11 +52,10 @@ program test_streamplot_interface_color
5252
end if
5353

5454
! Optional: check equals default blue
55-
if (any(abs(ref_color - [0.0_real64, 0.447_real64, 0.698_real64]) > 1.0e-12_real64)) then
55+
if (any(abs(ref_color - [0.0_wp, 0.447_wp, 0.698_wp]) > 1.0e-12_wp)) then
5656
print *, "ERROR: Streamplot default color not blue as expected"
5757
stop 1
5858
end if
5959

6060
print *, "Streamplot interface color test passed"
6161
end program test_streamplot_interface_color
62-

0 commit comments

Comments
 (0)