Skip to content

Commit e5a342d

Browse files
committed
add validation check and test if SUVR negative or zero
1 parent 1c6242f commit e5a342d

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# admiralneuro (development version)
22

3-
## Updates of Existing Functions
3+
## Updates of Existing Functions
44

55
- Improved test coverage in `compute_centiloid()` function when invalid tracer combination is provided. (#106)
66
## New features

R/compute_centiloid.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#'
3434
#' @param suvr SUVR value
3535
#'
36-
#' A numeric value is expected.
36+
#' A positive numeric value is expected.
3737
#'
3838
#' @permitted [num_scalar]
3939
#'
@@ -136,6 +136,11 @@ compute_centiloid <- function(
136136
custom_slope = NULL,
137137
custom_intercept = NULL
138138
) {
139+
# Validation check SUVR must be positive
140+
if (suvr <= 0) {
141+
cli::cli_abort("{.arg suvr} must be a positive numeric value (received {.val {suvr}}).")
142+
}
143+
139144
# Check custom_slope and custom_intercept
140145
has_custom_slope <- !is.null(custom_slope)
141146
has_custom_intercept <- !is.null(custom_intercept)

tests/testthat/_snaps/compute_centiloid.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,11 @@
4949
* pipeline = "AVID FBB SUVR PIPELINE"
5050
* ref_region = "Whole Cerebellum"
5151

52+
# Test 16 compute_centiloid throws error for non-positive SUVR values
53+
54+
`suvr` must be a positive numeric value (received 0).
55+
56+
---
57+
58+
`suvr` must be a positive numeric value (received -1.5).
59+

tests/testthat/test-compute_centiloid.R

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,30 @@ test_that("Test 15 compute_centiloid() throws the expected error message when no
207207
compute_centiloid(
208208
tracer = "18F-Florbetapir",
209209
pipeline = "AVID FBB SUVR PIPELINE",
210-
ref_region = "Whole Cerebellum"
210+
ref_region = "Whole Cerebellum",
211+
suvr = 1.25
212+
)
213+
)
214+
})
215+
216+
test_that("Test 16 compute_centiloid throws error for non-positive SUVR values", {
217+
# Test with zero
218+
expect_snapshot_error(
219+
compute_centiloid(
220+
tracer = "18F-Florbetapir",
221+
pipeline = "AVID FBP SUVR PIPELINE",
222+
ref_region = "Whole Cerebellum",
223+
suvr = 0
224+
)
225+
)
226+
227+
# Test with negative value
228+
expect_snapshot_error(
229+
compute_centiloid(
230+
tracer = "18F-Florbetapir",
231+
pipeline = "AVID FBP SUVR PIPELINE",
232+
ref_region = "Whole Cerebellum",
233+
suvr = -1.5
211234
)
212235
)
213236
})

0 commit comments

Comments
 (0)