|
| 1 | +source("./allergies.R") |
| 2 | +library(testthat) |
| 3 | + |
| 4 | +test_that("no allergies means not allergic", { |
| 5 | + x <- allergy(0) |
| 6 | + expect_false(allergic_to(x, "peanuts")) |
| 7 | + expect_false(allergic_to(x, "cats")) |
| 8 | + expect_false(allergic_to(x, "strawberries")) |
| 9 | +}) |
| 10 | + |
| 11 | +test_that("is allergic to eggs", { |
| 12 | + x <- allergy(1) |
| 13 | + expect_true(allergic_to(x, "eggs")) |
| 14 | +}) |
| 15 | + |
| 16 | +test_that("allergic to eggs in addition to other stuff", { |
| 17 | + x <- allergy(5) |
| 18 | + expect_true(allergic_to(x, "eggs")) |
| 19 | + expect_true(allergic_to(x, "shellfish")) |
| 20 | + expect_false(allergic_to(x, "strawberries")) |
| 21 | +}) |
| 22 | + |
| 23 | +test_that("no allergies at all", { |
| 24 | + x <- allergy(0) |
| 25 | + expect_equal(list_allergies(x), character()) |
| 26 | +}) |
| 27 | + |
| 28 | +test_that("allergic to just eggs", { |
| 29 | + x <- allergy(1) |
| 30 | + expect_equal(list_allergies(x), c("eggs")) |
| 31 | +}) |
| 32 | + |
| 33 | +test_that("allergic to just peanuts", { |
| 34 | + x <- allergy(2) |
| 35 | + expect_equal(list_allergies(x), c("peanuts")) |
| 36 | +}) |
| 37 | + |
| 38 | +test_that("allergic to just strawberries", { |
| 39 | + x <- allergy(8) |
| 40 | + expect_equal(list_allergies(x), c("strawberries")) |
| 41 | +}) |
| 42 | + |
| 43 | +test_that("allergic to eggs and peanuts", { |
| 44 | + x <- allergy(3) |
| 45 | + expect_true(setequal( |
| 46 | + list_allergies(x), |
| 47 | + c("eggs", "peanuts") |
| 48 | + )) |
| 49 | +}) |
| 50 | + |
| 51 | +test_that("allergic to more than eggs but not peanuts", { |
| 52 | + x <- allergy(5) |
| 53 | + expect_true(setequal( |
| 54 | + list_allergies(x), |
| 55 | + c("eggs", "shellfish") |
| 56 | + )) |
| 57 | +}) |
| 58 | + |
| 59 | +test_that("allergic to lots of stuff", { |
| 60 | + x <- allergy(248) |
| 61 | + expect_true(setequal( |
| 62 | + list_allergies(x), |
| 63 | + c("strawberries", "tomatoes", "chocolate", "pollen", "cats") |
| 64 | + )) |
| 65 | +}) |
| 66 | + |
| 67 | +test_that("allergic to everything", { |
| 68 | + x <- allergy(255) |
| 69 | + expect_true(setequal( |
| 70 | + list_allergies(x), |
| 71 | + c( |
| 72 | + "eggs", "peanuts", "shellfish", "strawberries", "tomatoes", |
| 73 | + "chocolate", "pollen", "cats" |
| 74 | + ) |
| 75 | + )) |
| 76 | +}) |
| 77 | + |
| 78 | +test_that("ignore non allergen score parts", { |
| 79 | + x <- allergy(509) |
| 80 | + expect_true(setequal( |
| 81 | + list_allergies(x), |
| 82 | + c( |
| 83 | + "eggs", "shellfish", "strawberries", "tomatoes", |
| 84 | + "chocolate", "pollen", "cats" |
| 85 | + ) |
| 86 | + )) |
| 87 | +}) |
| 88 | + |
| 89 | +test_that("ignore non allergen score parts", { |
| 90 | + x <- allergy(257) |
| 91 | + expect_true(setequal( |
| 92 | + list_allergies(x), |
| 93 | + c("eggs") |
| 94 | + )) |
| 95 | +}) |
0 commit comments