Skip to content

Commit

Permalink
allergies: remove test util function (#1972)
Browse files Browse the repository at this point in the history
[no important files changed]

part of #1824
  • Loading branch information
senekor authored Aug 15, 2024
1 parent f0cfd47 commit a7ed23c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 50 deletions.
17 changes: 1 addition & 16 deletions exercises/practice/allergies/.meta/test_template.tera
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
use 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:?}"
);
}
}

{% for test_group in cases %}
{% for test in test_group.cases %}
#[test]
Expand All @@ -35,8 +21,7 @@ fn {{ test.description | make_ident }}() {
Allergen::{{ allergen | title }},
{% endfor %}
];

compare_allergy_vectors(expected, &allergies);
assert_eq!(&allergies, expected);
{% endif -%}
}
{% endfor -%}
Expand Down
44 changes: 10 additions & 34 deletions exercises/practice/allergies/tests/allergies.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
use 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 not_allergic_to_anything_eggs() {
Expand Down Expand Up @@ -338,53 +324,47 @@ fn allergic_to_everything_cats() {
fn no_allergies() {
let allergies = Allergies::new(0).allergies();
let expected = &[];

compare_allergy_vectors(expected, &allergies);
assert_eq!(&allergies, expected);
}

#[test]
#[ignore]
fn just_eggs() {
let allergies = Allergies::new(1).allergies();
let expected = &[Allergen::Eggs];

compare_allergy_vectors(expected, &allergies);
assert_eq!(&allergies, expected);
}

#[test]
#[ignore]
fn just_peanuts() {
let allergies = Allergies::new(2).allergies();
let expected = &[Allergen::Peanuts];

compare_allergy_vectors(expected, &allergies);
assert_eq!(&allergies, expected);
}

#[test]
#[ignore]
fn just_strawberries() {
let allergies = Allergies::new(8).allergies();
let expected = &[Allergen::Strawberries];

compare_allergy_vectors(expected, &allergies);
assert_eq!(&allergies, expected);
}

#[test]
#[ignore]
fn eggs_and_peanuts() {
let allergies = Allergies::new(3).allergies();
let expected = &[Allergen::Eggs, Allergen::Peanuts];

compare_allergy_vectors(expected, &allergies);
assert_eq!(&allergies, expected);
}

#[test]
#[ignore]
fn more_than_eggs_but_not_peanuts() {
let allergies = Allergies::new(5).allergies();
let expected = &[Allergen::Eggs, Allergen::Shellfish];

compare_allergy_vectors(expected, &allergies);
assert_eq!(&allergies, expected);
}

#[test]
Expand All @@ -398,8 +378,7 @@ fn lots_of_stuff() {
Allergen::Pollen,
Allergen::Cats,
];

compare_allergy_vectors(expected, &allergies);
assert_eq!(&allergies, expected);
}

#[test]
Expand All @@ -416,8 +395,7 @@ fn everything() {
Allergen::Pollen,
Allergen::Cats,
];

compare_allergy_vectors(expected, &allergies);
assert_eq!(&allergies, expected);
}

#[test]
Expand All @@ -433,15 +411,13 @@ fn no_allergen_score_parts() {
Allergen::Pollen,
Allergen::Cats,
];

compare_allergy_vectors(expected, &allergies);
assert_eq!(&allergies, expected);
}

#[test]
#[ignore]
fn no_allergen_score_parts_without_highest_valid_score() {
let allergies = Allergies::new(257).allergies();
let expected = &[Allergen::Eggs];

compare_allergy_vectors(expected, &allergies);
assert_eq!(&allergies, expected);
}

0 comments on commit a7ed23c

Please sign in to comment.