tests/testthat/test-proportional.R

# Testing proportional methods of messydates

test_that("proportional methods work", {
  expect_equal(class(as_messydate("2012-06-02") %l% as_messydate("2012-06")),
               "numeric")
  expect_equal(class(as_messydate("2012-06") %g%
                       as_messydate("2012-06-10")), "numeric")
  expect_equal(class(as_messydate("2012-06") %le%
                       as_messydate("2012-06-10")), "numeric")
  expect_equal(class(as_messydate("2012-06") %ge%
                       as_messydate("2012-06-10")), "numeric")
  expect_equal(class(as_messydate("2012-06") %><%
                       as_messydate("2012-06-15..2012-07-15")), "numeric")
  expect_equal(class(as_messydate("2012-06") %>=<%
                       as_messydate("2012-06-15..2012-07-15")), "numeric")
  expect_equal(as_messydate("2012-06") %l% as_messydate("2012-06-10"), 0.3)
  expect_equal(round(as_messydate("2012-06") %g%
                       as_messydate("2012-06-10"), 2), 0.67)
  expect_equal(round(as_messydate("2012-06") %le%
                       as_messydate("2012-06-10"), 2), 0.33)
  expect_equal(as_messydate("2012-06") %ge% as_messydate("2012-06-10"), 0.70)
  expect_equal(round(as_messydate("2012-06") %><%
                       as_messydate("2012-06-15..2012-07-15"), 2), 0.52)
  expect_equal(round(as_messydate("2012-06") %>=<%
                       as_messydate("2012-06-15..2012-07-15"), 2), 0.53)
})

Try the messydates package in your browser

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

messydates documentation built on May 29, 2024, 2:16 a.m.