tests/testthat/test-convert-matrix.R

test_that("integer matrix to nr works", {
  mat <- matrix(1:24, 8, 3)
  
  nr <- matrix_to_nr(mat, palette = rainbow(24))
  
  expected <-matrix(
    colorfast::col_to_int(rainbow(24))
    , 8, 3, byrow = FALSE
  ) |> t()
  dim(expected) <- c(8, 3) 
  
  expect_equal(nr, expected, ignore_attr = TRUE)
})




test_that("numeric matrix to nr works", {
  mat <- matrix(seq(0, 1, length = 24), 8, 3)
  
  nr <- matrix_to_nr(mat, palette = rainbow(24))
  # plot(nr)
  
  colorfast::col_to_int(rainbow(24))
  
  
  expected <-matrix(
    colorfast::col_to_int(rainbow(24))
    , 8, 3, byrow = FALSE
  ) |> t()
  dim(expected) <- c(8, 3) 
  
  expect_equal(nr, expected, ignore_attr = TRUE)
})

Try the nara package in your browser

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

nara documentation built on May 28, 2026, 5:07 p.m.