tests/testthat/test-arithmetic.R

library(testthat)
library(tsbox)


test_that("arithmetic operations work properly", {
  expect_equal(
    fdeaths + mdeaths,
    ts_ts(ts_df(fdeaths) %ts+% mdeaths)
  )

  expect_equal(
    fdeaths - mdeaths,
    ts_ts(ts_df(fdeaths) %ts-% mdeaths)
  )

  expect_equal(
    fdeaths * mdeaths,
    ts_ts(ts_df(fdeaths) %ts*% mdeaths)
  )

  expect_equal(
    fdeaths / mdeaths,
    ts_ts(ts_df(fdeaths) %ts/% mdeaths)
  )



  # functional test
  library(dplyr)
  a <- bind_rows(
    mutate(ts_tbl(ts_c(mdeaths, fdeaths)), id2 = "a"),
    mutate(ts_tbl(ts_c(mdeaths, fdeaths)), id2 = "b")
  )
  expect_s3_class(a %ts/% a, "data.frame")

  z <- ts_df(ts_c(mdeaths, fdeaths) %ts/% 1)
  expect_s3_class(z, "data.frame")
})

Try the tsbox package in your browser

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

tsbox documentation built on May 31, 2023, 6:41 p.m.