Skip to content

Commit

Permalink
Added chat gipty tests
Browse files Browse the repository at this point in the history
  • Loading branch information
azimov committed May 2, 2024
1 parent 0af8648 commit 0cc4156
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/testthat/test-DataModelFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,31 @@ test_that("Bad model format", {
checkmate::expect_character(data$charField)
checkmate::expect_date(data$dateField)
})

# Tests for when types need conversion
chunk_numeric <- data.frame(
id = c(1, 2, 3),
name = c("Alice", "Bob", "Charlie"),
stringsAsFactors = FALSE
)

test_that("formatChunk converts non-matching types to character", {
expect_identical(
formatChunk(pkValuesInDb, chunk_numeric)$id,
as.character(chunk_numeric$id),
info = "Numeric columns in chunk should be converted to character."
)
})

# Test for error when types cannot be converted
chunk_factor <- data.frame(
id = c(1, 2, 3),
name = factor(c("Alice", "Bob", "Charlie"))
)

test_that("formatChunk throws error for incompatible types", {
expect_error(
formatChunk(pkValuesInDb, chunk_factor),
"id is of type numeric which cannot be converted between data frames pkValuesInDb and chunk"
)
})

0 comments on commit 0cc4156

Please sign in to comment.