Skip to content

Commit

Permalink
Changing w_max now also correctly updates ft_mask, closing #296
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavdelius committed Oct 13, 2024
1 parent fe9ea20 commit ef80b0e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
invests 100% of its energy into reproduction. Set to `w_max` by default.
- `removeSpecies()` now also removes species parameters that are not set for
any of the remaining species.
- Changing `w_max` now also correctly updates `ft_mask` (#296).
- `compareParams()` now also spells out differences in given species parameters.
- `getDiet()` now also includes the contribution of the external encounter rate
to the diet.
Expand Down
15 changes: 0 additions & 15 deletions R/MizerParams-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,6 @@ validMizerParams <- function(object) {
w_idx <- (no_w_full - no_w + 1):no_w_full

# Check weight grids ----
# Check dw and dw_full are correct length
if (length(object@dw) != no_w) {
msg <- paste("dw is length ", length(object@dw),
" and w is length ", no_w,
". These should be the same length", sep = "")
errors <- c(errors, msg)
}

if (length(object@dw_full) != no_w_full) {
msg <- paste("dw_full is length ", length(object@dw_full),
" and w_full is length ", no_w_full,
". These should be the same length", sep = "")
errors <- c(errors, msg)
}

# Check that the last entries of w_full and dw_full agree with w and dw
if (different(object@w[], object@w_full[w_idx])) {
msg <- "The later entries of w_full should be equal to those of w."
Expand Down
15 changes: 14 additions & 1 deletion tests/testthat/test-newMultispeciesParams.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,20 @@ test_that("Errors are reported", {
"min_w_pp must be larger than min_w")
})

## setParams ----
# setParams ----
test_that("setParams can leave params unchanged", {
expect_unchanged(setParams(NS_params), NS_params)
})

test_that("setParams handles change in w_max", {
params <- NS_params
# Check that ft_mask is recalculated correctly
params@species_params$w_max[1] <- 1000
params <- setParams(params)
expect_equal(sum(params@ft_mask[1, ]), 205)

# Check that error is thrown if w_max is too large
params@species_params$w_max[1] <- max(params@w) + 10
expect_error(setParams(params),
"The maximum weight of a species is larger than")
})

0 comments on commit ef80b0e

Please sign in to comment.