tests/testthat/test_time_2transform.R

library(timetrackr)

context("Transforming the data in preparation for plotting it")

# Example data file
example_text_file1 <- "example_text_data_dst1.csv"
example_text_file2 <- "example_text_data_dst2.csv"
#example_text_file1 <- "tests/testthat/example_text_data_dst1.csv"
#example_text_file2 <- "tests/testthat/example_text_data_dst2.csv"

# Reading in data
example_time_data1 <- time_2transform(time_1read(example_text_file1))
actual_output1 <- example_time_data1[8,]
example_time_data2 <- time_2transform(time_1read(example_text_file2))
actual_output2 <- example_time_data2[5,]

# Expected output
expected_output1 <- tibble::tibble(
  date_to_plot = lubridate::ymd("2017-04-02"),
  start_duration_plot = lubridate::as.duration(0),
  mid_duration_plot = lubridate::as.duration(10800),
  end_duration_plot = lubridate::as.duration(21600),
  activity = "13. Transport",
  plot_text = "13. Transport: 7:00\n(Total: 9:00)\nIn Adelaide here - DST"
) %>%
  tibble::remove_rownames()

expected_output2 <- tibble::tibble(
  date_to_plot = lubridate::ymd("2017-10-01"),
  start_duration_plot = lubridate::as.duration(0),
  mid_duration_plot = lubridate::as.duration(9000),
  end_duration_plot = lubridate::as.duration(18000),
  activity = "04. Exercise",
  plot_text = "04. Exercise: 4:00\n(Total: 6:59)\nIn Adelaide here - no DST"
)

test_that("Output is as expected for daylight savings",{
  expect_equal(actual_output1, expected_output1)
  expect_equal(actual_output2, expected_output2)
})

actual_output3 <- example_time_data2[26,]

expected_output3 <- tibble::tibble(
  date_to_plot = lubridate::ymd("2017-10-07"),
  start_duration_plot = lubridate::as.duration(79800),
  mid_duration_plot = lubridate::as.duration(83100),
  end_duration_plot = lubridate::as.duration(86400),
  activity = "01. Sleep",
  plot_text = "01. Sleep: 1:50\n(Total: 7:50)"
)

test_that("Output is as expected for non-daylight savings",{
  expect_equal(actual_output3, expected_output3)
})
andrewjpfeiffer/timetrackr documentation built on Feb. 21, 2020, 4:22 a.m.