Skip to content

Commit

Permalink
Merge pull request #161 from Toshihiko-tan/master
Browse files Browse the repository at this point in the history
Bug Fixes for shiny, test file for range_glu function
  • Loading branch information
irinagain authored Sep 12, 2024
2 parents 472371f + c7ef8a7 commit eb99769
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions inst/shiny_iglu/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,11 @@ shinyServer(function(input, output) {
}
}
else if(parameter_type == "all_metrics") {
string = paste0("iglu::", input$metric, "(data, metrics_to_include='", input$parameter , "')")
string = paste0("iglu::", input$metric, "(data, , , , , , '", input$parameter , "')")
print(string)
}
else if(parameter_type == 'pgs'){
string = paste0('iglu::', input$metric, '(data, dur_length=', input$parameter, ', end_length=', input$parameter2, ')')
string = paste0('iglu::', input$metric, '(data, ', input$parameter, ', ', input$parameter2, ')')
}
else if(parameter_type == "nested"){
strlist = strsplit(input$parameter, ")")[[1]]
Expand Down
25 changes: 25 additions & 0 deletions tests/testthat/test-range_glu.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Simple test
test_data <- data.frame(
id = c(1, 1, 1, 2, 2, 2),
gl = c(100, 120, NA, 140, 160, 180),
time = c("08:00", "12:00", "16:00")
)


test_that("range_glu calculates correct range for each id", {
result <- range_glu(test_data)
expect_equal(result$range[result$id == 1], 20)
expect_equal(result$range[result$id == 2], 40)
})

# All values are the same
test_data_same <- data.frame(
id = c(1, 1, 1),
gl = c(100, 100, 100),
time = c("08:00", "12:00", "16:00")
)

test_that("range_glu handles all values the same correctly", {
result <- range_glu(test_data_same)
expect_equal(result$range, c(0))
})

0 comments on commit eb99769

Please sign in to comment.