Skip to content

Commit

Permalink
test: expand on tests for other data formats
Browse files Browse the repository at this point in the history
  • Loading branch information
lwjohnst86 committed Jun 25, 2024
1 parent 82b355c commit 0d0b963
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions tests/testthat/test-joins.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,29 +137,57 @@ test_that("kontakter and diagnoser are in correct order", {
})

test_that("joining works for DuckDB Database", {
actual <- arrow::to_duckdb(actual_diagnoser) |>
join_lpr3(arrow::to_duckdb(actual_kontakter))
actual <- arrow::to_duckdb(actual_kontakter) |>
join_lpr3(arrow::to_duckdb(actual_diagnoser))

actual_rows <- actual |>
dplyr::count() |>
dplyr::pull(n) |>
as.integer()

expect_contains(class(actual), "tbl_duckdb_connection")
expect_identical(colnames(actual), colnames(expected_lpr3))
expect_identical(actual_rows, nrow(expected_lpr3))
})

test_that("joining works for Arrow Tables (from Parquet)", {
actual <- arrow::as_arrow_table(actual_diagnoser) |>
join_lpr3(arrow::as_arrow_table(actual_kontakter))
actual <- arrow::as_arrow_table(actual_kontakter) |>
join_lpr3(arrow::as_arrow_table(actual_diagnoser))

actual_rows <- actual |>
dplyr::count() |>
dplyr::pull(n) |>
as.integer()

expect_contains(class(actual), "arrow_dplyr_query")
expect_identical(names(actual), colnames(expected_lpr3))
expect_identical(actual_rows, nrow(expected_lpr3))
})

test_that("joining works for data.frame", {
actual <- as.data.frame(actual_diagnoser) |>
join_lpr3(as.data.frame(actual_kontakter))
actual <- as.data.frame(actual_kontakter) |>
join_lpr3(as.data.frame(actual_diagnoser))

actual_rows <- actual |>
dplyr::count() |>
dplyr::pull(n) |>
as.integer()

expect_contains(class(actual), "data.frame")
expect_identical(names(actual), colnames(expected_lpr3))
expect_identical(actual_rows, nrow(expected_lpr3))
})

test_that("joining works for data.table", {
actual <- data.table::as.data.table(actual_diagnoser) |>
join_lpr3(data.table::as.data.table(actual_kontakter))
actual <- data.table::as.data.table(actual_kontakter) |>
join_lpr3(data.table::as.data.table(actual_diagnoser))

actual_rows <- actual |>
dplyr::count() |>
dplyr::pull(n) |>
as.integer()

expect_contains(class(actual), "data.table")
expect_identical(colnames(actual), colnames(expected_lpr3))
expect_identical(actual_rows, nrow(expected_lpr3))
})

0 comments on commit 0d0b963

Please sign in to comment.