tests/testthat/test-r-utils.R

context("test-r-utils")

test_that(
  "HeavySet input is cleaned correctly, the class is added, has 7 columns, factor variables, and date is as.Date", {
    df <- data.frame(
      Dates = rep(Sys.Date(), 5),
      Workouts = rep("Workout 1", 5),
      exercisenames = rep("Exercise 1", 5),
      Repetitions = seq(1, 5, 1),
      kilos = seq(10, 50, 10),
      lbs = seq(20, 60, 10),
      notes = rep("", 5)
    )
    names <-
      c(
        "date",
        "workoutName",
        "exerciseName",
        "reps",
        "weightKg",
        "weightLb",
        "notes"
      )
    df <- cleanHSinput(df)
    expect_equal(ncol(df), length(names))
    expect_equal(names(df), names)
    expect_true(is.factor(df$workoutName))
    expect_true(is.factor(df$exerciseName))
    expect_true(is.factor(df$notes))
    expect_true(inherits(df$date, "Date"))
  }
)

test_that("checkHSclass checks a dataframe for the class correctly", {
  # Should return an error as this is a list and not a dataframe.
  mylist <- list(1,2,3,4)
  expect_error(checkHSclass(mylist))

  # Should return null, as class[1] == "data.frame" and class[2] == "HS.data.frame"
  df <- simData()
  expect_equal(class(df), c("data.frame", "HS.data.frame"))
})


test_that("addHSclass adds a class to an object that is of class data.frame", {
  df <- data.frame(
    x1 = c(2, 3),
    y1 = c(1, 4)
  )
  # Should be equal
  df <- addHSclass(df)
  expect_equal(class(df), c("data.frame", "HS.data.frame"))
})
MarijnJABoer/HeavySetR documentation built on May 22, 2019, 5:31 p.m.