Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt unittest for read_txt_Renishaw() function #54

Merged
merged 7 commits into from
Aug 6, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/fileio/txt.Renishaw", package="hySpc.read.txt")
paracetamol <- paste0(path, "/paracetamol.txt")
laser <- paste0(path, "/laser.txt.gz")
chondro <- paste0(path, "/chondro.txt")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you, please, not use the names paracetamol, laser, and chondro for file names. Use f_paracetamol, f_laser, and f_chondro instead.


test_that("single spectrum", {
skip("TODO: adapt to new package")
tmp <- read_txt_Renishaw("fileio/txt.Renishaw/paracetamol.txt", "spc")
tmp <- read_txt_Renishaw(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(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(chondro, "xyspc")
GegznaV marked this conversation as resolved.
Show resolved Hide resolved
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(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(chondro, nlines = 10),
"Wavelengths do not correspond"
)

tmp <- read_txt_Renishaw("fileio/txt.Renishaw/chondro.txt", nlines = 1e5)
tmp <- read_txt_Renishaw(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