tests/testthat/test-r-convert.R

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

test_that("conversion functions work correctly", {
  expect_equal(lbs_to_kg(10), 4.54, tolerance = 0.01)
  expect_equal(inch_to_cm(10), 25.40)
  expect_equal(fluidounce_to_liter(70), 2.07, tolerance = 0.01)
  expect_equal(kcal_to_fat(100), 11.1, tolerance = 0.01)
  expect_equal(kcal_to_protein(100), 25)
  expect_equal(kcal_to_carbs(100), 25)
  expect_equal(kcal_to_joule(100), 418400)
  expect_equal(fat_to_kcal(100), 770)

  expect_error(lbs_to_kg("10"))
  expect_error(inch_to_cm("10"))
  expect_error(fluidounce_to_liter("70"))
  expect_error(kcal_to_fat("100"))
  expect_error(kcal_to_protein("100"))
  expect_error(kcal_to_carbs("100"))
  expect_error(kcal_to_joule("100"))
  expect_error(fat_to_kcal("100"))
})
MarijnJABoer/befitteR documentation built on April 24, 2020, 5:43 a.m.