tests/testthat/test-r-getrecords.R

context("test-r-getrecords")

testthat::test_that("getRecords extracts records correctly from simulated data", {
  df <- simData(2, 1)
  # Test for all exercises in a dat.frame
  p <- getRecords(df)
  records <-
    structure(
      list(
        exerciseName = structure(
          1:6,
          .Label = c(
            "Barbell Row",
            "Bench Press",
            "Chin Up",
            "Deadlift",
            "Overhead Press",
            "Squat"
          ),
          class = "factor"
        ),
        reps = c(4, 3, 5, 3, 5, 4),
        weightKg = c(55,
                     62.5, 55, 60, 60, 60)
      ),
      row.names = c(NA, -6L),
      class = c("tbl_df",
                "tbl", "data.frame")
    )
  expect_equal(p, records)
  # Test for 1 exercise
  p <- getRecords(df, exercise = "Squat")
  expect_equal(p,
               data.frame(
                 exerciseName = "Squat",
                 reps = 4,
                 weightKg = 60,
                 stringsAsFactors = TRUE
               ))

  # Test for a list of exercises
  p <- getRecords(df, exercise = c("Squat", "Deadlift"))
  expect_equal(p,
               data.frame(
                 exerciseName = c("Deadlift", "Squat"),
                 reps = c(3, 4),
                 weightKg = c(60, 60),
                 stringsAsFactors = TRUE
               ))
})
MarijnJABoer/HeavySetR documentation built on May 22, 2019, 5:31 p.m.