RNGkind(sample.kind = "Rounding")
set.seed(42)
n <- 2000
knapsack_objects <-
data.frame(
w=sample(1:4000, size = n, replace = TRUE),
v=runif(n= n, 0, 10000)
)
test_that("Correct object is returned", {
expect_silent(output<-greedy_knapsack(x = knapsack_objects[1:800,], W = 3500))
expect_named(output, c("value", "elements"))
})
test_that("incorrect input given",{
expect_error(greedy_knapsack("data", "weight"))
expect_error(greedy_knapsack(1300, "weight"))
expect_error(greedy_knapsack(1300, 500))
})
test_that("Correct expected output",{
output<-greedy_knapsack(x = knapsack_objects[1:15,], W = 3500)
expect_equal(round(output$value), 22160)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.