Skip to content

Commit

Permalink
Merge pull request #54 from r-hyperspec/features/42-read-txt-Renishaw
Browse files Browse the repository at this point in the history
Adapt unittest for read_txt_Renishaw() function
  • Loading branch information
GegznaV authored Aug 6, 2021
2 parents 13b62f1 + e5613f3 commit d0c0a44
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions R/read_txt_Renishaw.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,48 +164,47 @@ read_txt_Renishaw <- function(file = stop("file is required"),

hySpc.testthat::test(read_txt_Renishaw) <- function() {
context("read_txt_Renishaw")
path <- system.file("extdata", "txt.Renishaw", package = "hySpc.read.txt")
f_paracetamol <- paste0(path, "/paracetamol.txt")
f_laser <- paste0(path, "/laser.txt.gz")
f_chondro <- paste0(path, "/chondro.txt")

test_that("single spectrum", {
skip("TODO: adapt to new package")
tmp <- read_txt_Renishaw("fileio/txt.Renishaw/paracetamol.txt", "spc")
tmp <- read_txt_Renishaw(f_paracetamol, "spc")
expect_equal(dim(tmp), c(nrow = 1L, ncol = 2L, nwl = 4064L))
})

test_that("time series spectrum, gzipped", {
skip("TODO: adapt to new package")
tmp <- read_txt_Renishaw("fileio/txt.Renishaw/laser.txt.gz", "ts")
tmp <- read_txt_Renishaw(f_laser, "ts")
expect_equal(dim(tmp), c(nrow = 84L, ncol = 3L, nwl = 140L))
expect_equal(colnames(tmp), c("t", "spc", "filename"))
})

test_that("map (= default)", {
skip("TODO: adapt to new package")
tmp <- read_txt_Renishaw("fileio/txt.Renishaw/chondro.txt", "xyspc")
tmp <- read_txt_Renishaw(f_chondro, "xyspc")
expect_equal(dim(tmp), c(nrow = 875L, ncol = 4L, nwl = 1272L))
expect_equal(colnames(tmp), c("y", "x", "spc", "filename"))

tmp <- read_txt_Renishaw("fileio/txt.Renishaw/chondro.txt")
tmp <- read_txt_Renishaw(f_chondro)
expect_equal(dim(tmp), c(nrow = 875L, ncol = 4L, nwl = 1272L))
expect_equal(colnames(tmp), c("y", "x", "spc", "filename"))
})

test_that("chunked reading", {
skip("TODO: adapt to new package")

## error on too small chunk size
expect_error(
read_txt_Renishaw("fileio/txt.Renishaw/chondro.txt", nlines = 10),
read_txt_Renishaw(f_chondro, nlines = 10),
"Wavelengths do not correspond"
)

tmp <- read_txt_Renishaw("fileio/txt.Renishaw/chondro.txt", nlines = 1e5)
tmp <- read_txt_Renishaw(f_chondro, nlines = 1e5)
expect_equal(dim(tmp), c(nrow = 875L, ncol = 4L, nwl = 1272L))
})

test_that("compressed files", {
skip("TODO: adapt to new package")

files <- Sys.glob("fileio/txt.Renishaw/chondro.*")
files <- Sys.glob(paste0(path, "/chondro.*"))
files <- grep("[.]zip", files, invert = TRUE, value = TRUE) # .zip is tested with read_zip_Renishaw
for (f in files) {
expect_equal(dim(read_txt_Renishaw(!!f)), c(nrow = 875L, ncol = 4L, nwl = 1272L))
Expand Down

0 comments on commit d0c0a44

Please sign in to comment.