tests/testthat/test-tunable.R

test_that("tunable() returns expected parameters for k_means", {
  spec <- k_means(num_clusters = tune()) |>
    set_engine("stats")

  res <- tunable(spec)

  expected <- tibble::tibble(
    name = "num_clusters",
    call_info = list(list(pkg = "dials", fun = "num_clusters")),
    source = "cluster_spec",
    component = "k_means",
    component_id = "main"
  )

  expect_identical(res, expected)
})

test_that("tunable() returns expected parameters for hier_clust", {
  spec <- hier_clust(num_clusters = tune()) |>
    set_engine("stats")

  res <- tunable(spec)

  expected <- tibble::tibble(
    name = c("num_clusters", "linkage_method", "cut_height"),
    call_info = list(
      list(pkg = "dials", fun = "num_clusters"),
      list(pkg = "tidyclust", fun = "linkage_method"),
      list(pkg = "tidyclust", fun = "cut_height")
    ),
    source = "cluster_spec",
    component = "hier_clust",
    component_id = "main"
  )

  expect_identical(res, expected)
})

test_that("tunable() returns tibble for models with fixed params", {
  spec <- k_means(num_clusters = 3) |>
    set_engine("stats")

  res <- tunable(spec)

  expected <- tibble::tibble(
    name = "num_clusters",
    call_info = list(list(pkg = "dials", fun = "num_clusters")),
    source = "cluster_spec",
    component = "k_means",
    component_id = "main"
  )

  expect_identical(res, expected)
})

Try the tidyclust package in your browser

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

tidyclust documentation built on June 20, 2026, 9:08 a.m.