Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgirard committed Oct 27, 2024
1 parent 7026d57 commit 7009cf5
Show file tree
Hide file tree
Showing 6 changed files with 413 additions and 4 deletions.
77 changes: 77 additions & 0 deletions tests/testthat/_snaps/ssm_plot/many-circle-plots.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
226 changes: 226 additions & 0 deletions tests/testthat/_snaps/ssm_plot/many-curve-plots.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 39 additions & 3 deletions tests/testthat/_snaps/ssm_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,51 @@
ssm_table(res, render = FALSE)
Output
Profile Elevation X.Value Y.Value
1 All 0.92 (0.89, 0.95) 0.35 (0.32, 0.38) -0.25 (-0.28, -0.22)
1 All 0.92 (0.89, 0.94) 0.35 (0.32, 0.38) -0.25 (-0.28, -0.22)
Amplitude Displacement Fit
1 0.43 (0.40, 0.46) 324.3 (320.9, 328.0) 0.878
1 0.43 (0.40, 0.46) 324.3 (320.8, 327.8) 0.878

---

Code
ssm_table(res, drop_xy = TRUE, render = FALSE)
Output
Profile Elevation Amplitude Displacement Fit
1 All 0.92 (0.89, 0.95) 0.43 (0.40, 0.46) 324.3 (320.9, 328.0) 0.878
1 All 0.92 (0.89, 0.94) 0.43 (0.40, 0.46) 324.3 (320.8, 327.8) 0.878

---

Code
ssm_table(res, render = TRUE)
Output
<table class='gmisc_table' style='border-collapse: collapse; margin-top: 1em; margin-bottom: 1em;' >
<thead>
<tr><td colspan='7' style='text-align: left;'>
Mean-based Structural Summary Statistics with 95% CIs</td></tr>
<tr>
<th style='font-weight: 900; border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: left;'>Profile</th>
<th style='font-weight: 900; border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: left;'>Elevation</th>
<th style='font-weight: 900; border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: left;'>X.Value</th>
<th style='font-weight: 900; border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: left;'>Y.Value</th>
<th style='font-weight: 900; border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: left;'>Amplitude</th>
<th style='font-weight: 900; border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: left;'>Displacement</th>
<th style='font-weight: 900; border-bottom: 1px solid grey; border-top: 2px solid grey; text-align: left;'>Fit</th>
</tr>
</thead>
<tbody>
<tr>
<td style='padding-right: 1em; min-width: 3em; white-space: nowrap; border-bottom: 2px solid grey; text-align: left;'>All</td>
<td style='padding-right: 1em; min-width: 3em; white-space: nowrap; border-bottom: 2px solid grey; text-align: left;'>0.92 (0.89, 0.94)</td>
<td style='padding-right: 1em; min-width: 3em; white-space: nowrap; border-bottom: 2px solid grey; text-align: left;'>0.35 (0.32, 0.38)</td>
<td style='padding-right: 1em; min-width: 3em; white-space: nowrap; border-bottom: 2px solid grey; text-align: left;'>-0.25 (-0.28, -0.22)</td>
<td style='padding-right: 1em; min-width: 3em; white-space: nowrap; border-bottom: 2px solid grey; text-align: left;'>0.43 (0.40, 0.46)</td>
<td style='padding-right: 1em; min-width: 3em; white-space: nowrap; border-bottom: 2px solid grey; text-align: left;'>324.3 (320.8, 327.8)</td>
<td style='padding-right: 1em; min-width: 3em; white-space: nowrap; border-bottom: 2px solid grey; text-align: left;'>0.878</td>
</tr>
</tbody>
</table>
Profile Elevation X.Value Y.Value
1 All 0.92 (0.89, 0.94) 0.35 (0.32, 0.38) -0.25 (-0.28, -0.22)
Amplitude Displacement Fit
1 0.43 (0.40, 0.46) 324.3 (320.8, 327.8) 0.878

12 changes: 11 additions & 1 deletion tests/testthat/test-ssm_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ test_that("Single-group mean-based SSM plot is correct", {
expect_s3_class(p, "ggplot")
vdiffr::expect_doppelganger("single group mean ssm", p)

# TODO: Add tests of transformed data and legend
p2 <- ssm_plot_circle(res, palette = NULL)
vdiffr::expect_doppelganger("single group mean ssm no palette", p2)
})

test_that("Single-group correlation-based SSM plot is correct", {
Expand Down Expand Up @@ -67,3 +68,12 @@ test_that("Removing plots with low fit works as expected", {
res <- ssm_analyze(jz2017, scales = 2:9, measures = "OCPD")
expect_error(ssm_plot_circle(res, drop_lowfit = TRUE))
})

test_that("many plots works as expected", {
data("jz2017")
res <- ssm_analyze(jz2017, scales = 2:9, measures = 10:13)
p <- ssm_plot_circle(res)
vdiffr::expect_doppelganger("many_circle-plots", p)
p2 <- ssm_plot_curve(res)
vdiffr::expect_doppelganger("many_curve-plots", p2)
})
2 changes: 2 additions & 0 deletions tests/testthat/test-ssm_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ test_that("SSM Table captions are correct", {


test_that("ssm_table is correct", {
set.seed(12345)
data("jz2017")
res <- ssm_analyze(jz2017, scales = 2:9)
expect_snapshot(ssm_table(res, render = FALSE))
expect_snapshot(ssm_table(res, drop_xy = TRUE, render = FALSE))
expect_snapshot(ssm_table(res, render = TRUE))
})

0 comments on commit 7009cf5

Please sign in to comment.