context("test-r-goalweight.R")
test_that("check_weight_goal works for males, per sentence, per weight loss/gain", {
expect_equal(
evaluate_promise(
check_weight_goal(
weight = 70,
bfp = 15,
goal = 10,
sex = "male"
),
print = TRUE
)$message[1],
"Your goal is to change your weight with 10 kg, from 70 kg to 80 kg.\nYour current body fat percentage is 15% which results in 59.5 kg of lean mass.\nWith the new weight of 80 kg you will have 20.5 kg of body fat, which is 25.62% body fat percentage.\nAttention: as a male, this percentage of body fat is dangerously high and categorized as obese!\n"
)
expect_equal(
evaluate_promise(
check_weight_goal(
weight = 70,
bfp = 15,
goal = 5,
sex = "male"
),
print = TRUE
)$message[1],
"Your goal is to change your weight with 5 kg, from 70 kg to 75 kg.\nYour current body fat percentage is 15% which results in 59.5 kg of lean mass.\nWith the new weight of 75 kg you will have 15.5 kg of body fat, which is 20.67% body fat percentage.\nAs a male, this percentage of body fat is categorized as normal and acceptable.\n"
)
expect_equal(
evaluate_promise(
check_weight_goal(
weight = 70,
bfp = 15,
goal = 0,
sex = "male"
),
print = TRUE
)$message[1],
"Your goal is to change your weight with 0 kg, from 70 kg to 70 kg.\nYour current body fat percentage is 15% which results in 59.5 kg of lean mass.\nWith the new weight of 70 kg you will have 10.5 kg of body fat, which is 15% body fat percentage.\nAs a male, this percentage of body fat is categorized as being fit.\n"
)
expect_equal(
evaluate_promise(
check_weight_goal(
weight = 70,
bfp = 15,
goal = -5,
sex = "male"
),
print = TRUE
)$message[1],
"Your goal is to change your weight with -5 kg, from 70 kg to 65 kg.\nYour current body fat percentage is 15% which results in 59.5 kg of lean mass.\nWith the new weight of 65 kg you will have 5.5 kg of body fat, which is 8.46% body fat percentage.\nAs a male, this percentage of body fat is categorized as being athletic!\n"
)
expect_equal(
evaluate_promise(
check_weight_goal(
weight = 70,
bfp = 15,
goal = -10,
sex = "male"
),
print = TRUE
)$message[1],
"Your goal is to change your weight with -10 kg, from 70 kg to 60 kg.\nYour current body fat percentage is 15% which results in 59.5 kg of lean mass.\nWith the new weight of 60 kg you will have 0.5 kg of body fat, which is 0.83% body fat percentage.\nAttention: as a male, this percentage of body fat is dangerously low as it is your essential fat!\n"
)
})
test_that("check_weight_goal works for females, per sentence, per weight loss/gain", {
expect_equal(
evaluate_promise(
check_weight_goal(
weight = 70,
bfp = 15,
goal = 20,
sex = "female"
),
print = TRUE
)$message[1],
"Your goal is to change your weight with 20 kg, from 70 kg to 90 kg.\nYour current body fat percentage is 15% which results in 59.5 kg of lean mass.\nWith the new weight of 90 kg you will have 30.5 kg of body fat, which is 33.89% body fat percentage.\nAttention: as a female, this percentage of body fat is dangerously high and categorized as obese!\n"
)
expect_equal(
evaluate_promise(
check_weight_goal(
weight = 70,
bfp = 15,
goal = 10,
sex = "female"
),
print = TRUE
)$message[1],
"Your goal is to change your weight with 10 kg, from 70 kg to 80 kg.\nYour current body fat percentage is 15% which results in 59.5 kg of lean mass.\nWith the new weight of 80 kg you will have 20.5 kg of body fat, which is 25.62% body fat percentage.\nAs a female, this percentage of body fat is categorized as normal and acceptable.\n"
)
expect_equal(
evaluate_promise(
check_weight_goal(
weight = 70,
bfp = 15,
goal = 7,
sex = "female"
),
print = TRUE
)$message[1],
"Your goal is to change your weight with 7 kg, from 70 kg to 77 kg.\nYour current body fat percentage is 15% which results in 59.5 kg of lean mass.\nWith the new weight of 77 kg you will have 17.5 kg of body fat, which is 22.73% body fat percentage.\nAs a female, this percentage of body fat is categorized as being fit.\n"
)
expect_equal(
evaluate_promise(
check_weight_goal(
weight = 70,
bfp = 15,
goal = 1,
sex = "female"
),
print = TRUE
)$message[1],
"Your goal is to change your weight with 1 kg, from 70 kg to 71 kg.\nYour current body fat percentage is 15% which results in 59.5 kg of lean mass.\nWith the new weight of 71 kg you will have 11.5 kg of body fat, which is 16.2% body fat percentage.\nAs a female, this percentage of body fat is categorized as being athletic!\n"
)
expect_equal(
evaluate_promise(
check_weight_goal(
weight = 70,
bfp = 15,
goal = -10,
sex = "female"
),
print = TRUE
)$message[1],
"Your goal is to change your weight with -10 kg, from 70 kg to 60 kg.\nYour current body fat percentage is 15% which results in 59.5 kg of lean mass.\nWith the new weight of 60 kg you will have 0.5 kg of body fat, which is 0.83% body fat percentage.\nAttention: as a female, this percentage of body fat is dangerously low as it is your essential fat!\n"
)
})
test_that("calculate_ideal_weight works", {
expect_equal(
calculate_ideal_weight(
height = 180,
sex = "male",
equation = "robinson"
),
72.6,
tolerance = 0.01
)
expect_equal(
calculate_ideal_weight(
height = 180,
sex = "male",
equation = "devine"
),
74.9,
tolerance = 0.01
)
expect_equal(
calculate_ideal_weight(
height = 180,
sex = "male",
equation = "hamwi"
),
77.6,
tolerance = 0.01
)
expect_equal(
calculate_ideal_weight(
height = 180,
sex = "male",
equation = "miller"
),
71.5,
tolerance = 0.01
)
expect_equal(
calculate_ideal_weight(
height = 180,
sex = "male",
equation = "hammond"
),
81
)
expect_equal(calculate_ideal_weight(height = 180, equation = "broca"), 80)
expect_equal(
calculate_ideal_weight(
height = 180,
desired_bmi = 22,
equation = "peterson"
),
71.5
)
expect_equal(
calculate_ideal_weight(
height = 170,
sex = "female",
equation = "robinson"
),
60.7,
tolerance = 0.01
)
expect_equal(
calculate_ideal_weight(
height = 170,
sex = "female",
equation = "devine"
),
61.4,
tolerance = 0.01
)
expect_equal(
calculate_ideal_weight(
height = 170,
sex = "female",
equation = "hamwi"
),
61.0,
tolerance = 0.01
)
expect_equal(
calculate_ideal_weight(
height = 170,
sex = "female",
equation = "miller"
),
62.,
tolerance = 0.01
)
expect_equal(
calculate_ideal_weight(
height = 170,
sex = "female",
equation = "hammond"
),
63
)
expect_error(calculate_ideal_weight(
height = "180",
sex = "male",
equation = "robinson"
))
expect_error(calculate_ideal_weight(
height = 180,
sex = "sex",
equation = "robinson"
))
expect_error(calculate_ideal_weight(
height = 180,
sex = "male",
equation = "equation"
))
})
test_that("calculate_healthy_weight works", {
expect_equal(length(calculate_healthy_weight(180)), 2)
expect_equal(calculate_healthy_weight(180), c(59.94, 80.68))
expect_error(calculate_healthy_weight("180"))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.