matiasandina / fed3

An R package to read and analyze data from FED3 devices
https://matiasandina.github.io/fed3/
Other
0 stars 0 forks source link

Write unit tests for `set_alignment()` #17

Open matiasandina opened 11 months ago

matiasandina commented 11 months ago

Here are the unit tests with expected results Ideally this should be incorporated to the examples and tests

library(tidyverse)
library(fed3)
df <- tibble(
  group_col = c(1, 1, 1, 2, 2, 3, 3, 3),
  datetime_col = c(
    as.POSIXct("2023-01-01 12:00:00"),
    as.POSIXct("2023-01-01 12:30:00"),
    as.POSIXct("2023-01-03 10:00:01"),
    as.POSIXct("2023-01-01 13:15:00"),
    as.POSIXct("2023-01-01 13:45:00"),
    as.POSIXct("2023-01-20 10:00:00"),
    as.POSIXct("2023-01-20 11:00:00"),
    as.POSIXct("2023-01-31 16:00:00")
  )
)

df %>% group_by(group_col) %>%
  set_alignment(datetime_col, "midnight")

df %>% group_by(group_col) %>%
   set_alignment(datetime_col, "time")

# One issue here is the change of dttm to drtn, maybe we can consider behaving differently
df %>% group_by(group_col) %>%
  set_alignment(datetime_col, "elapsed")