-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
pub struct Allergies; | ||
|
||
#[derive(Debug, PartialEq, Eq)] | ||
pub enum Allergen { | ||
Eggs, | ||
Peanuts, | ||
Shellfish, | ||
Strawberries, | ||
Tomatoes, | ||
Chocolate, | ||
Pollen, | ||
Cats, | ||
} | ||
|
||
impl Allergies { | ||
pub fn new(score: u32) -> Self { | ||
todo!("Given the '{score}' score, construct a new Allergies struct."); | ||
} | ||
|
||
pub fn is_allergic_to(&self, allergen: &Allergen) -> bool { | ||
todo!("Determine if the patient is allergic to the '{allergen:?}' allergen."); | ||
} | ||
|
||
pub fn allergies(&self) -> Vec<Allergen> { | ||
todo!("Return the list of allergens contained within the score with which the Allergies struct was made."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
use exercism::allergies::*; | ||
fn compare_allergy_vectors(expected: &[Allergen], actual: &[Allergen]) { | ||
for element in expected { | ||
if !actual.contains(element) { | ||
panic!("Allergen missing\n {element:?} should be in {actual:?}"); | ||
} | ||
} | ||
if actual.len() != expected.len() { | ||
panic!( | ||
"Allergy vectors are of different lengths\n expected {expected:?}\n got {actual:?}" | ||
); | ||
} | ||
} | ||
#[test] | ||
fn is_not_allergic_to_anything() { | ||
let allergies = Allergies::new(0); | ||
assert!(!allergies.is_allergic_to(&Allergen::Peanuts)); | ||
assert!(!allergies.is_allergic_to(&Allergen::Cats)); | ||
assert!(!allergies.is_allergic_to(&Allergen::Strawberries)); | ||
} | ||
#[test] | ||
#[ignore] | ||
fn is_allergic_to_eggs() { | ||
assert!(Allergies::new(1).is_allergic_to(&Allergen::Eggs)); | ||
} | ||
#[test] | ||
#[ignore] | ||
fn is_allergic_to_eggs_and_shellfish_but_not_strawberries() { | ||
let allergies = Allergies::new(5); | ||
assert!(allergies.is_allergic_to(&Allergen::Eggs)); | ||
assert!(allergies.is_allergic_to(&Allergen::Shellfish)); | ||
assert!(!allergies.is_allergic_to(&Allergen::Strawberries)); | ||
} | ||
#[test] | ||
#[ignore] | ||
fn no_allergies_at_all() { | ||
let expected = &[]; | ||
let allergies = Allergies::new(0).allergies(); | ||
compare_allergy_vectors(expected, &allergies); | ||
} | ||
#[test] | ||
#[ignore] | ||
fn allergic_to_just_eggs() { | ||
let expected = &[Allergen::Eggs]; | ||
let allergies = Allergies::new(1).allergies(); | ||
compare_allergy_vectors(expected, &allergies); | ||
} | ||
#[test] | ||
#[ignore] | ||
fn allergic_to_just_peanuts() { | ||
let expected = &[Allergen::Peanuts]; | ||
let allergies = Allergies::new(2).allergies(); | ||
compare_allergy_vectors(expected, &allergies); | ||
} | ||
#[test] | ||
#[ignore] | ||
fn allergic_to_just_strawberries() { | ||
let expected = &[Allergen::Strawberries]; | ||
let allergies = Allergies::new(8).allergies(); | ||
compare_allergy_vectors(expected, &allergies); | ||
} | ||
#[test] | ||
#[ignore] | ||
fn allergic_to_eggs_and_peanuts() { | ||
let expected = &[Allergen::Eggs, Allergen::Peanuts]; | ||
let allergies = Allergies::new(3).allergies(); | ||
compare_allergy_vectors(expected, &allergies); | ||
} | ||
#[test] | ||
#[ignore] | ||
fn allergic_to_eggs_and_shellfish() { | ||
let expected = &[Allergen::Eggs, Allergen::Shellfish]; | ||
let allergies = Allergies::new(5).allergies(); | ||
compare_allergy_vectors(expected, &allergies); | ||
} | ||
#[test] | ||
#[ignore] | ||
fn allergic_to_many_things() { | ||
let expected = &[ | ||
Allergen::Strawberries, | ||
Allergen::Tomatoes, | ||
Allergen::Chocolate, | ||
Allergen::Pollen, | ||
Allergen::Cats, | ||
]; | ||
let allergies = Allergies::new(248).allergies(); | ||
compare_allergy_vectors(expected, &allergies); | ||
} | ||
#[test] | ||
#[ignore] | ||
fn allergic_to_everything() { | ||
let expected = &[ | ||
Allergen::Eggs, | ||
Allergen::Peanuts, | ||
Allergen::Shellfish, | ||
Allergen::Strawberries, | ||
Allergen::Tomatoes, | ||
Allergen::Chocolate, | ||
Allergen::Pollen, | ||
Allergen::Cats, | ||
]; | ||
let allergies = Allergies::new(255).allergies(); | ||
compare_allergy_vectors(expected, &allergies); | ||
} | ||
#[test] | ||
#[ignore] | ||
fn scores_over_255_do_not_trigger_false_positives() { | ||
let expected = &[ | ||
Allergen::Eggs, | ||
Allergen::Shellfish, | ||
Allergen::Strawberries, | ||
Allergen::Tomatoes, | ||
Allergen::Chocolate, | ||
Allergen::Pollen, | ||
Allergen::Cats, | ||
]; | ||
let allergies = Allergies::new(509).allergies(); | ||
compare_allergy_vectors(expected, &allergies); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,4 @@ mod parallel_letter_frequency; | |
mod rna_transcription; | ||
mod binary_search; | ||
mod spiral_matrix; | ||
mod allergies; |