Sha256: 284556f228dca888e8bb54e2bd2162da4a2c2bc56657191cff315143fca591bf

Contents?: true

Size: 1.93 KB

Versions: 53

Compression:

Stored size: 1.93 KB

Contents

source("./allergies.R")
library(testthat)

context("allergies")

test_that("no allergies means not allergic", {
  x <- allergy(0)
  expect_false(allergic_to(x, "peanuts"))
  expect_false(allergic_to(x, "cats"))
  expect_false(allergic_to(x, "strawberries"))
})

test_that("is allergic to eggs", {
  x <- allergy(1)
  expect_true(allergic_to(x, "eggs"))
})

test_that("allergic to eggs in addition to other stuff", {
  x <- allergy(5)
  expect_true(allergic_to(x, "eggs"))
  expect_true(allergic_to(x, "shellfish"))
  expect_false(allergic_to(x, "strawberries"))
})

test_that("no allergies at all", {
  x <- allergy(0)
  expect_equal(list_allergies(x), character())
})

test_that("allergic to just eggs", {
  x <- allergy(1)
  expect_equal(list_allergies(x), c("eggs"))
})

test_that("allergic to just peanuts", {
  x <- allergy(2)
  expect_equal(list_allergies(x), c("peanuts"))
})

test_that("allergic to just strawberries", {
  x <- allergy(8)
  expect_equal(list_allergies(x), c("strawberries"))
})

test_that("allergic to eggs and peanuts", {
  x <- allergy(3)
  expect_true(setequal(
    list_allergies(x), 
    c("eggs", "peanuts"))
  )
})

test_that("allergic to more than eggs but not peanuts", {
  x <- allergy(5)
  expect_true(setequal(
    list_allergies(x), 
    c("eggs", "shellfish"))
  )
})

test_that("allergic to lots of stuff", {
  x <- allergy(248)
  expect_true(setequal(
    list_allergies(x), 
    c("strawberries", "tomatoes", "chocolate", "pollen", "cats"))
  )
})

test_that("allergic to everything", {
  x <- allergy(255)
  expect_true(setequal(
    list_allergies(x), 
    c("eggs", "peanuts", "shellfish", "strawberries", "tomatoes", 
      "chocolate", "pollen", "cats")))
})

test_that("ignore non allergen score parts", {
  x <- allergy(509)
  expect_true(setequal(
    list_allergies(x), 
    c("eggs", "shellfish", "strawberries", "tomatoes", 
      "chocolate", "pollen", "cats"))
  )
})

message("All tests passed for exercise: allergies")

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/r/exercises/allergies/test_allergies.R
trackler-2.2.1.179 tracks/r/exercises/allergies/test_allergies.R
trackler-2.2.1.178 tracks/r/exercises/allergies/test_allergies.R
trackler-2.2.1.177 tracks/r/exercises/allergies/test_allergies.R
trackler-2.2.1.176 tracks/r/exercises/allergies/test_allergies.R
trackler-2.2.1.175 tracks/r/exercises/allergies/test_allergies.R
trackler-2.2.1.174 tracks/r/exercises/allergies/test_allergies.R
trackler-2.2.1.173 tracks/r/exercises/allergies/test_allergies.R
trackler-2.2.1.172 tracks/r/exercises/allergies/test_allergies.R
trackler-2.2.1.171 tracks/r/exercises/allergies/test_allergies.R
trackler-2.2.1.170 tracks/r/exercises/allergies/test_allergies.R
trackler-2.2.1.169 tracks/r/exercises/allergies/test_allergies.R
trackler-2.2.1.167 tracks/r/exercises/allergies/test_allergies.R
trackler-2.2.1.166 tracks/r/exercises/allergies/test_allergies.R
trackler-2.2.1.165 tracks/r/exercises/allergies/test_allergies.R
trackler-2.2.1.164 tracks/r/exercises/allergies/test_allergies.R
trackler-2.2.1.163 tracks/r/exercises/allergies/test_allergies.R
trackler-2.2.1.162 tracks/r/exercises/allergies/test_allergies.R
trackler-2.2.1.161 tracks/r/exercises/allergies/test_allergies.R
trackler-2.2.1.160 tracks/r/exercises/allergies/test_allergies.R