tests/testthat/test-tidy_iobed_stream.R

test_that("tidy_iobed_stream works", {
  # setup
  ok_stream <- c(
    "2", "7", "8", " ", " ", " ", " ", "2", "2", "5", " ", " ", " ",
    "2", "2", "7", " ", " ", " ", " ", "2", "6", "8", " ", " ", " ",
    " ", "6", "5", "5", "3", "0", " ", " ", " ", " ", " ", "1", "2",
    ":", "4", "4", ":", "1", "4", "/", "2", "0", "0", "\n", "\r", "",
    "2", "7", "8", " ", " ", " ", " ", "2", "2", "5", " ", " ", " ",
    "2", "2", "6", " ", " ", " ", " ", "2", "6", "8", " ", " ", " ",
    " ", "6", "5", "5", "3", "0", " ", " ", " ", " ", " ", "1", "2",
    ":", "4", "4", ":", "1", "4", "/", "2", "0", "1", "\n", "\r", "",
    "2", "7", "8", " ", " ", " ", " ", "2", "2", "5", " ", " ", " "
  )

  ko_stream <- c(
    " ", " ", " ", " ", "2", "2", "5", " ", " ", " ",
    "2", "2", "7", " ", " ", " ", " ", "2", "6", "8", " ", " ", " ",
    " ", "6", "5", "5", "3", "0", " ", " ", " ", " ", " ", "1", "2",
    ":", "4", "4", ":", "1", "4", "/", "2", "0", "0", "\n", "\r", "",
    "2", "7", "8", " ", " ", " ", " ", "2", "2", "5", " ", " ", " ",
    "2", "2", "6", " ", " ", " ", " ", "2", "6", "8", " ", " ", " ",
    " ", "6", "5", "5", "3", "0", " ", " ", " ", " ", " ", "1", "2",
    ":", "4", "4", ":", "1", "4", "/", "2", "0", "1", "\n", "\r", "",
    "2", "7", "8", " ", " ", " ", " ", "2", "2", "5", " ", " ", " "
  )

  uscita_stream <- c(
    "2", "7", "9", " ", " ", " ", " ", "2", "2", "5", " ", " ", " ",
    "2", "2", "5", " ", " ", " ", " ", "2", "7", "0", " ", " ", " ",
    " ", "6", "5", "5", "3", "0", " ", " ", " ", " ", " ", "1", "2",
    ":", "5", "0", ":", "2", "t", "i", "p", "o", " ", "u", "s", "c",
    "i", "t", "a", "1", "/", "2", "0", "1", "\n", "\r", "", "2", "7",
    "9", " ", " ", " ", " ", "2", "2", "4", " ", " ", " ", "2", "2",
    "5", " ", " ", " ", " ", "2", "7", "0", " ", " ", " ", " ", "6",
    "5", "5", "3", "0", " ", " ", " ", " ", " ", "1", "2", ":", "5"
  )

  uscita_empty_stream <- c(
    "2", "2", "5", " ", " ", " ",
    "2", "2", "5", " ", " ", " ", " ", "2", "7", "0", " ", " ", " ",
    " ", "6", "5", "5", "3", "0", " ", " ", " ", " ", " ", "1", "2",
    ":", "5", "0", ":", "2", "t", "i", "p", "o", " ", "u", "s", "c",
    "i", "t", "a", "1", "/", "2", "0", "1", "\n", "\r", "", "2", "7",
    "9", " ", " ", " ", " ", "2", "2", "4", " ", " ", " ", "2", "2",
    "5", " ", " ", " ", " ", "2", "7", "0", " ", " ", " ", " ", "6",
    "5", "5", "3", "0", " ", " ", " ", " ", " ", "1", "2", ":", "5"
  )

  uscita_ko_stream <- c(
    "2", "2", "5", " ", " ", " ",
    "2", "2", "5", " ", " ", " ", " ", "2", "7", "0", " ", " ", " ",
    " ", "6", "5", "5", "3", "0", " ", " ", " ", " ", " ", "1", "2",
    ":", "5", "0", ":", "2", "t", "i", "p", "o", " ", "u", "s", "c",
    "i", "t", "a", "1", "/", "2", "0", "1", "\n", "\r", "",
    "2", "7", "9", " ", " ", " ", " ", "2", "2", "5", " ", " ", " ",
    "2", "2", "5", " ", " ", " ", " ", "2", "7", "0", " ", " ", " ",
    " ", "6", "5", "5", "3", "0", " ", " ", " ", " ", " ", "1", "2",
    ":", "5", "0", ":", "2", "t", "i", "p", "o", " ", "u", "s", "c",
    "i", "t", "a", "1", "/", "2", "0", "1", "\n", "\r", "", "2", "7",
    "9", " ", " ", " ", " ", "2", "2", "4", " ", " ", " ", "2", "2",
    "5", " ", " ", " ", " ", "2", "7", "0", " ", " ", " ", " ", "6",
    "5", "5", "3", "0", " ", " ", " ", " ", " ", "1", "2", ":", "5"
  )

  # execute
  tidy_ok <- tidy_iobed_stream(ok_stream)
  tidy_ko <- suppressWarnings(tidy_iobed_stream(ko_stream))
  tidy_uscita <- tidy_iobed_stream(uscita_stream)
  tidy_empty_uscita <- suppressWarnings(
    tidy_iobed_stream(uscita_empty_stream)
  )
  tidy_ko_uscita <- suppressWarnings(
    tidy_iobed_stream(uscita_ko_stream)
  )

  # test
  expect_tibble(tidy_ok)
  expect_silent(tidy_iobed_stream(ok_stream))
  expect_warning(tidy_iobed_stream(ko_stream), "First row")
  expect_named(
    tidy_ok,
    c("sbl", "sbr", "sul", "sur", "weight", "clock", "alarm", "elapsed")
  )
  expect_equal(nrow(tidy_ok), 2)
  expect_equal(nrow(tidy_ko), 1)
  expect_equal(nrow(tidy_uscita), 1)
  expect_equal(nrow(tidy_empty_uscita), 0)
  expect_equal(nrow(tidy_ko_uscita), 1)
})
UBESP-DCTV/iobed.bed documentation built on Sept. 4, 2022, 5:57 a.m.