Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marberts committed Oct 11, 2023
1 parent d46f98d commit 1ed3d67
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
14 changes: 9 additions & 5 deletions tests/testthat/test-contrib.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@ pias <- as_aggregation_structure(
data.frame(level1 = 1, level2 = c(11, 12, 13, 14), weight = 1)
)

epr <- with(dat, elemental_index(rel, period, ea, contrib = TRUE))
epr <- with(
dat,
elemental_index(setNames(rel, c(1:5, 1, 3, 2, 6)), period, ea, contrib = TRUE)
)
index <- aggregate(epr, pias, na.rm = TRUE)
epr2 <- with(dat, elemental_index(rel, period, ea))

test_that("contrib works", {
expect_equal(
contrib(epr),
matrix(c(0, 0.414213562373095, 2.5962965079607, 2.88444419044716),
2, 2, dimnames = list(c("11.1", "11.2"), 1:2))
2, 2, dimnames = list(c("1", "2"), 1:2))
)
expect_equal(
contrib(epr, "14"),
matrix(c(0, 7),
1, 2, dimnames = list("14.1", 1:2))
1, 2, dimnames = list("6", 1:2))
)
expect_equal(
contrib(epr2),
Expand All @@ -30,7 +33,7 @@ test_that("contrib works", {
test_that("aggregate contributions have the right form", {
contributions <- contrib(index)
expect_equal(rownames(contributions),
c("11.1", "11.2", "12.1", "12.2", "13.1", "14.1"))
c("1", "2", "3", "4", "5", "6"))
expect_equal(colnames(contributions), c("1", "2"))
})

Expand All @@ -48,7 +51,8 @@ test_that("product names are correct", {
expect_equal(
contrib(epr),
contrib(
with(dat, elemental_index(rel, period, ea, w, contrib = TRUE))
with(dat, elemental_index(setNames(rel, c(1:5, 1, 3, 2, 6)),
period, ea, w, contrib = TRUE))
)
)
})
1 change: 1 addition & 0 deletions tests/testthat/test-elemental_index.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ test_that("argument checking works", {
expect_error(elemental_index(1:3, 1:3, 1:3, w = 1:2))
expect_error(elemental_index(1:3, factor(1:3, levels = numeric(0))))
expect_error(elemental_index(1:3, ea = factor(1:3, levels = numeric(0))))
expect_error(elemental_index(setNames(1:3, c("", 1, 2)), contrib = TRUE))
expect_warning(elemental_index(-1:1, r = 1))
expect_warning(elemental_index(setNames(1:3, rep(1, 3)), contrib = TRUE))
})
5 changes: 0 additions & 5 deletions tests/testthat/test-summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,3 @@ test_that("summary methods works", {
expect_no_condition(summary(ind))
expect_no_condition(summary(elemental_index(1:5, contrib = TRUE)))
})

test_that("str methods works", {
expect_no_condition(str(agg))
expect_no_condition(str(ind))
})

0 comments on commit 1ed3d67

Please sign in to comment.