Skip to content

Commit

Permalink
Merge pull request #19 from yng-me/wip
Browse files Browse the repository at this point in the history
fixed failed test
  • Loading branch information
yng-me committed Dec 26, 2023
2 parents 035a4d6 + 01b143a commit 602ef79
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 29 deletions.
38 changes: 20 additions & 18 deletions tests/testthat/test-compute-contribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,23 @@ test_that("contribution by dimension works correctly", {
})


# test_that("contribution by dimension works correctly with aggregation", {
# mpi_specs <- use_global_mpi_specs(.uid = 'uuid', .aggregation = 'class')
# dm <- df_household |>
# create_deprivation_matrix(deprivation_profile, .mpi_specs = mpi_specs)
#
# hr <- dm$censored |>
# compute_headcount_ratio(.aggregation = attr_spec$aggregation)
#
# m_0 <- dm$censored |>
# compute_headcount_ratio_adjusted(.aggregation = attr_spec$aggregation) |>
# dplyr::select(MPI) |>
# dplyr::bind_cols(hr) |>
# compute_contribution(.mpi_specs = mpi_specs)
#
# expect_equal(nrow(m_0), 2)
# expect_equal(ncol(m_0), 12)
#
# })
test_that("contribution by dimension works correctly with aggregation", {
mpi_specs <- use_global_mpi_specs(.uid = "uuid", .aggregation = "class")
attr_spec <- attributes(mpi_specs)

dm <- df_household |>
create_deprivation_matrix(deprivation_profile, .mpi_specs = mpi_specs)

hr <- dm$censored |>
compute_headcount_ratio(.aggregation = attr_spec$aggregation)

m_0 <- dm$censored |>
compute_headcount_ratio_adjusted(.aggregation = attr_spec$aggregation) |>
dplyr::select(mpi) |>
dplyr::bind_cols(hr) |>
compute_contribution(.mpi_specs = mpi_specs)

expect_equal(nrow(m_0), 2)
expect_equal(ncol(m_0), 12)

})
7 changes: 0 additions & 7 deletions tests/testthat/test-define-deprivation.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ test_that("dimension is returned correctly", {
})


# test_that("error if specs file is not defined", {
# expect_error(
# define_deprivation(df_household, drinking_water, drinking_water == 2),
# "MPI specifications must be defined first."
# )
# })

test_that("collapsing is correctly implemented", {
dp <- df_household_roster |>
define_deprivation(
Expand Down
4 changes: 0 additions & 4 deletions tests/testthat/test-define-mpi-specs.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ test_that("[csv] sample specs file loads correctly", {
expect_length(unique(specs$dimension), 3)
expect_length(unique(specs$indicator), 10)
expect_length(unique(specs$variable), 10)
# expect_identical(names(mpi_specs), list_name)
expect_equal(ncol(mpi_specs), 7)
expect_equal(nrow(mpi_specs), 10)
})
Expand All @@ -109,7 +108,6 @@ test_that("[xlsx] sample specs file loads correctly", {
expect_length(unique(specs$dimension), 3)
expect_length(unique(specs$indicator), 10)
expect_length(unique(specs$variable), 10)
# expect_identical(names(mpi_specs), list_name)
expect_equal(ncol(mpi_specs), 7)
expect_equal(nrow(mpi_specs), 10)
})
Expand All @@ -127,7 +125,6 @@ test_that("[txt] sample specs file loads correctly", {
expect_length(unique(specs$dimension), 3)
expect_length(unique(specs$indicator), 10)
expect_length(unique(specs$variable), 10)
# expect_identical(names(mpi_specs), list_name)
expect_equal(ncol(mpi_specs), 7)
expect_equal(nrow(mpi_specs), 10)
})
Expand All @@ -145,7 +142,6 @@ test_that("[json] sample specs file loads correctly", {
expect_length(unique(specs$dimension), 3)
expect_length(unique(specs$indicator), 10)
expect_length(unique(specs$variable), 10)
# expect_identical(names(mpi_specs), list_name)
expect_equal(ncol(mpi_specs), 7)
expect_equal(nrow(mpi_specs), 10)
})

0 comments on commit 602ef79

Please sign in to comment.