tests/testthat/test-r-strength.R

context("test-r-strength.R")

# `calculate_wilks`` -----
test_that("test Wilks score", {
  expect_equal(calculate_wilks(
    weight = 80,
    sex = "male",
    lift = 100
  ),
  68.27,
  tolerance = 0.01)
  expect_equal(calculate_wilks(
    weight = 80,
    sex = "female",
    lift = 100
  ),
  91.50,
  tolerance = 0.01)
})

# `calculate_wilks` -----
test_that("test Wilks score asserts input correctly", {
  expect_error(calculate_wilks(
    weight = "80",
    sex = "male",
    lift = 100
  ))
  expect_error(calculate_wilks(
    weight = -80,
    sex = "male",
    lift = 100
  ))
  expect_error(calculate_wilks(
    weight = 80,
    sex = "unknown",
    lift = 100
  ))
  expect_error(calculate_wilks(
    weight = 80,
    sex = "male",
    lift = "100"
  ))
  expect_error(calculate_wilks(
    weight = 80,
    sex = "male",
    lift = -100
  ))
})

# `calculate_one_rm` -----
test_that("1RM calculations", {
  expect_equal(calculate_one_rm(
    reps = 5,
    lift = 100,
    equation = "brzycki"
  ),
  112.51,
  tolerance = 0.01)
  expect_equal(calculate_one_rm(
    reps = 5,
    lift = 100,
    equation = "epley"
  ),
  116.67,
  tolerance = 0.01)
  expect_equal(calculate_one_rm(
    reps = 5,
    lift = 100,
    equation = "mayhew"
  ),
  119.01,
  tolerance = 0.01)
  expect_equal(calculate_one_rm(
    reps = 5,
    lift = 100,
    equation = "mcglothin"
  ),
  113.71,
  tolerance = 0.01)
  expect_equal(calculate_one_rm(
    reps = 5,
    lift = 100,
    equation = "lombardi"
  ),
  117.46,
  tolerance = 0.01)
  expect_equal(calculate_one_rm(
    reps = 5,
    lift = 100,
    equation = "oconnor"
  ),
  112.5,
  tolerance = 0.01)
  expect_equal(calculate_one_rm(
    reps = 5,
    lift = 100,
    equation = "wathan"
  ),
  116.58,
  tolerance = 0.01)
  expect_equal(calculate_one_rm(
    reps = 5,
    lift = 100,
    equation = "wendler"
  ),
  116.65,
  tolerance = 0.01)
})

# `calculate_one_rm` -----
test_that("calculate_one_rm asserts input correctly", {
  expect_error(calculate_one_rm(
    reps = "5",
    lift = 100,
    equation = "epley"
  ))
  expect_error(calculate_one_rm(
    reps = -1,
    lift = 100,
    equation = "epley"
  ))
  expect_error(calculate_one_rm(
    reps = 5,
    lift = "100",
    equation = "epley"
  ))
  expect_error(calculate_one_rm(
    reps = 5,
    lift = -100,
    equation = "epley"
  ))
  expect_error(calculate_one_rm(
    reps = 5,
    lift = 100,
    equation = "unknown"
  ))
})

# `calculate_plates` -----
test_that("calculate_plates works correctly", {
  expect_equal(calculate_plates(97.5), c(20, 10, 5, 2.5, 1.25))
  expect_equal(calculate_plates(98), c(20, 10, 5, 2.5, 1.25))
  expect_error(calculate_plates("91"))
  expect_error(calculate_plates(lift = 90, bar = "20"))
  expect_error(calculate_plates(
    lift = 90,
    bar = 20,
    plates = c("25")
  ))
})

# `calculate_strength_level` -----
test_that("calculate_strength_level works correctly", {
  expect_equal(
    evaluate_promise(
      calculate_strength_level(
        weight = 80,
        sex = "male",
        exercise = "squat",
        lift = 225,
        table = TRUE
      ),
      print = TRUE
    )$message[1],
    "Exercise: squat\nLift: 1 rep for 225 kg\nLevel is: advanced\n"
  )
  expect_equal(
    evaluate_promise(
      calculate_strength_level(
        weight = 80,
        sex = "male",
        exercise = "squat",
        lift = 225,
        table = TRUE
      ),
      print = TRUE
    )$message[2],
    "\nTable for 80 kg and squat is as follows:\n"
  )
  expect_equal(
    evaluate_promise(
      calculate_strength_level(
        weight = 80,
        sex = "male",
        exercise = "squat",
        lift = 225,
        table = TRUE
      ),
      print = TRUE
    )$message[3],
    "# A tibble: 10 x 5\n   body_weight exercise_name sex   level        lift_weight\n   <chr>       <chr>         <chr> <chr>              <dbl>\n 1 82          squat         male  untrained           55  \n 2 82          squat         male  novice             100  \n 3 82          squat         male  intermediate       122. \n 4 82          squat         male  advanced           168. \n 5 82          squat         male  elite              218. \n 6 90          squat         male  untrained           57.5\n 7 90          squat         male  novice             105  \n 8 90          squat         male  intermediate       130  \n 9 90          squat         male  advanced           178. \n10 90          squat         male  elite              230  \n"
  )
})
MarijnJABoer/befitteR documentation built on April 24, 2020, 5:43 a.m.