tests/testthat/test-milkr_cost.R

test_that("milkr_cost returns correct result", {
  demand <- rep(1, 10)

  pos <-
    data.frame(
      pos_x = 0:10,
      pos_y = 0
    )

  res <- clarke_wright(
    demand, dist(pos),
    data.frame(n = NA_integer_, caps = 1)
  )

  expect_equal(
    milkr_cost(res),
    sum(1:10 * 2)
  )
})

test_that("milkr_saving returns correct result", {
  demand <- rep(1, 10)

  pos <-
    data.frame(
      pos_x = 0:10,
      pos_y = 0
    )

  res <- clarke_wright(
    demand, dist(pos),
    data.frame(n = NA_integer_, caps = 1)
  )

  expect_equal(
    milkr_saving(res),
    0
  )

  expect_equal(
    milkr_saving(res, relative = TRUE),
    0
  )
})

Try the heumilkr package in your browser

Any scripts or data that you put into this service are public.

heumilkr documentation built on June 8, 2025, 10:52 a.m.