Skip to content
Merged
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
4 changes: 3 additions & 1 deletion R/aesthetics.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
detect_mixture <- function(sim_situation) {
is_Dominance <- grep("Dominance", x = colnames(sim_situation), fixed = TRUE)
if (length(is_Dominance) > 0) {
is_mixture <- length(unique(sim_situation[[is_Dominance]])) > 1
# NA values come from binding versions without a Dominance column:
dominance <- sim_situation[[is_Dominance]]
is_mixture <- length(unique(dominance[!is.na(dominance)])) > 1
} else {
is_mixture <- FALSE
}
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-detect_mixture.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ test_that("detect_mixture", {

sim_data <- data.frame(lai = c(1, 1.2))
expect_false(CroPlotR:::detect_mixture(sim_data))

# NA values (e.g. versions bound together, only one with a Dominance column)
# are not counted as a distinct value:
sim_data <- data.frame(Dominance = c("0", "0", NA, NA))
expect_false(CroPlotR:::detect_mixture(sim_data))

sim_data <- data.frame(Dominance = c("Principal", "Associated", NA))
expect_true(CroPlotR:::detect_mixture(sim_data))
})
18 changes: 18 additions & 0 deletions tests/testthat/test-generic_statistics.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ test_that("statistics summary: three groups", {
expect_equal(length(unique(df_stats$situation)), 1)
})

test_that("statistics summary: sole crop with Dominance in one group only", {
# Only one group has a (single valued) Dominance column for the sole crops,
# binding the groups must not detect them as mixtures:
sim_dom <- sim
sim_dom$`SC_Pea_2005-2006_N0`$Dominance <- "0"
sim_dom$`SC_Wheat_2005-2006_N0`$Dominance <- "0"

df_stats <- summary(
stics_1 = sim, stics_2 = sim_dom, obs = obs,
all_situations = FALSE
)
df_ref <- summary(
stics_1 = sim, stics_2 = sim, obs = obs,
all_situations = FALSE
)
expect_equal(df_stats, df_ref)
})


test_that("statistics summary: no obs", {
## when computing statistics for each situation one by one
Expand Down
Loading