Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

42 cohort methods test #47

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/testthat/test-cohort_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,19 @@ test_that("Defining and accessing description works fine", {
)
})

test_that("steps_range returns empty character when from is greater than to", {
expect_equal(steps_range(3,2),character(0))
})

test_that("eval_step_filters returns empty character when step id is equal", {
expect_equal(eval_step_filters(list(0, id = "2"),patients_source),list())
})

test_that("next_step from Step.R returns the next index as a character string", {
expect_equal(next_step("1"),"2")
expect_type(next_step("1"),"character")
})

# if (!covr::in_covr()) { # covr modifies function body so the test doesn't pass
# test_that("(experimental) Retrieving reproducible code works fine", {
# # Using direct Cohort methods
Expand Down
27 changes: 27 additions & 0 deletions tests/testthat/test-reproducible_code_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,30 @@ test_that("combine_expressions merges multiple expressions into a single one", {
})
)
})

test_that("pair_seq handles empty input gracefully", {
# Given an empty input, expect empty integer vector
result <- pair_seq(integer(0))
expect_true(is.integer(result))
expect_identical(result,integer(0))
expect_length(result, 0)
})

test_that("pair_seq requires an even number of indexes", {
# If odd length input is provided, function should fail due to indexing error
expect_error(pair_seq(c(1, 2, 3)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect_error function can use regex, for check an error, worth to verify if it make sense to use that.

})

test_that("pair_seq always returns a strictly increasing sequence of integers", {
# Check that output is sorted and has no duplicates for a known even-length input
input <- c(3, 1, 7, 5) # Unsorted input
result <- pair_seq(input)

# Expect numeric output
expect_true(is.numeric(result))

# Expect output is in strictly ascending order
expect_true(all(diff(result) > 0))

})