library(testthat) describe("bmi() ",{ it("can generate an output",{ expect_match(bmi(45, 1.75), "14.69") expect_match(bmi(45, 1.75), "Underweight.") expect_match(bmi(60, 1.75), "19.59") expect_match(bmi(60, 1.75), "You are Normal Weight.", fixed = TRUE) expect_match(bmi(75, 1.75), "24.49") expect_match(bmi(75, 1.75), "You are Normal Weight.") # Overweight expect_match(bmi(85, 1.75), "27.76") expect_match(bmi(85, 1.75), "You are Overweight.") # Obese expect_match(bmi(100, 1.75), "32.65") expect_match(bmi(100, 1.75), "You are Obese") }) it("can handle boundary cases",{ # Boundary conditions expect_match(bmi(60, 1.84), "17.72") expect_match(bmi(60, 1.84), "You are Underweight.") expect_match(bmi(74, 1.75), "24.16") expect_match(bmi(74, 1.75), "You are Normal Weight.") expect_match(bmi(94, 1.75), "30.69") expect_match(bmi(94, 1.75), "You are Obese.") }) it("can handle edge cases", { # Edge case - zero weight or weight expect_error(bmi(0, 1.75), "height or weight cannot be zero or negative", fixed = TRUE) expect_error(bmi(0, 1.75), "height or weight cannot be zero or negative", fixed = TRUE) expect_error(bmi(70, 0), "height or weight cannot be zero or negative", fixed = TRUE) expect_error(bmi(-70, 1.75), "height or weight cannot be zero or negative", fixed = TRUE) }) it("can take only numeric values and deals with 'NA' values ", { expect_error(bmi("ki",7), "Enter numeric values", fixed = TRUE) expect_error(bmi("sed","es"), "Enter numeric values", fixed = TRUE) expect_error(bmi(NA, 85),"Entered value(s) contains NA", fixed = TRUE) }) })