tests/testthat/test-r-metabolic.R

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

test_that("RMR calculations are correct", {
  expect_equal(
    calculate_rmr(
      weight = 70,
      height = 180,
      age = 30,
      sex = "female",
      equation = "mifflin"
    ),
    1514,
    tolerance = 0.1
  )

  expect_equal(
    calculate_rmr(
      weight = 70,
      height = 180,
      age = 30,
      sex = "male",
      equation = "harris-benedict"
    ),
    1727,
    tolerance = 0.1
  )

  expect_equal(
    calculate_rmr(
      weight = 70,
      height = 180,
      age = 30,
      sex = "female",
      equation = "harris-benedict"
    ),
    1517,
    tolerance = 0.1
  )

  expect_equal(
    calculate_rmr(
      weight = 70,
      height = 180,
      age = 30,
      sex = "male",
      equation = "revised-harris-benedict"
    ),
    1720,
    tolerance = 0.1
  )

  expect_equal(
    calculate_rmr(
      weight = 70,
      height = 180,
      age = 30,
      sex = "female",
      equation = "revised-harris-benedict"
    ),
    1523,
    tolerance = 0.1
  )

  expect_equal(calculate_rmr(
    weight = 70,
    equation = "katch-mcardle",
    bfp = 14.5
  ),
  1663,
  tolerance = 0.1)

  expect_equal(
    calculate_rmr(
      weight = 70,
      equation = "katch-mcardle-hybrid",
      bfp = 14.5
    ),
    1672,
    tolerance = 0.1
  )

  expect_equal(calculate_rmr(
    weight = 70,
    equation = "cunningham",
    bfp = 14.5
  ),
  1817,
  tolerance = 0.1)

  expect_error(calculate_rmr(equation = "fantasy-equation"))
  expect_error(
    calculate_rmr(
      weight = 70,
      height = 180,
      age = 30,
      sex = "nothing",
      equation = "harris-benedict"
    )
  )

  # Expect error when equation is revised-harris-benedict and sex is not correct
  expect_error(
    calculate_rmr(
      weight = 70,
      height = 180,
      age = 30,
      sex = "unknown",
      equation = "revised-harris-benedict"
    )
  )
})

test_that("calculate_mean_rmr works like it should", {
  expect_true(is.data.frame(
    calculate_mean_rmr(
      weight = 80,
      height = 187,
      age = 27,
      sex = "male",
      bfp = 14
    )
  ))

  expect_equal(class(
    calculate_mean_rmr(
      weight = 80,
      height = 187,
      age = 27,
      sex = "male",
      bfp = 14
    )
  ),
  c("tbl_df", "tbl", "data.frame"))

  # TODO(MJABOER): Fix test below:
  # expect_equal(
  #   calculate_mean_rmr(
  #     weight = 80,
  #     height = 187,
  #     age = 27,
  #     sex = "male",
  #     bfp = 14
  #   ),
  #   structure(list(Equation = c("mifflin", "harris-benedict", "revised-harris-benedict",
  #                               "katch-mcardle", "katch-mcardle-hybrid", "cunningham", "mean"
  #   ), RMR = c(1838.75, 1919.8331, 1904.256, 1856.08, 1873.384, 2013.6,
  #              1900.98385)), row.names = c(NA, -7L), class = c("tbl_df", "tbl",
  #                                                              "data.frame"))
  # )
})
MarijnJABoer/befitteR documentation built on April 24, 2020, 5:43 a.m.