tests/testthat/test_mlr_learners_clust_agnes.R

skip_if_not_installed("clue")

test_that("autotest", {
  learner = mlr3::lrn("clust.agnes")
  expect_learner(learner)
  result = run_autotest(learner)
  expect_true(result, info = result$error)
})

test_that("Learner properties are respected", {
  task = tsk("usarrests")
  learner = lrn("clust.agnes")
  expect_learner(learner, task)

  # test on multiple paramsets
  parset_list = list(
    list(k = 2L),
    list(k = 5L),
    list(k = 2L, metric = "manhattan", method = "single"),
    list(k = 2L, stand = TRUE)
  )

  for (i in seq_along(parset_list)) {
    parset = parset_list[[i]]
    learner$param_set$values = parset

    p = suppressWarnings(learner$train(task)$predict(task), classes = "predictionUselessWarning")
    expect_prediction_clust(p)

    if ("complete" %in% learner$properties) {
      expect_prediction_complete(p, learner$predict_type)
    }
    if ("exclusive" %in% learner$properties) {
      expect_prediction_exclusive(p, learner$predict_type)
    }
  }
})
mlr-org/mlr3cluster documentation built on May 6, 2024, 1:24 p.m.