Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logic behind an allergies test #65

Closed
andrey-gvrd opened this issue Jan 15, 2016 · 4 comments
Closed

Logic behind an allergies test #65

andrey-gvrd opened this issue Jan 15, 2016 · 4 comments

Comments

@andrey-gvrd
Copy link

@adolfosilva

What is the logic behind this test?

#[test]
fn test_ignore_non_allergen_score_parts() {
    assert_eq!(vec![Allergen::Eggs], Allergies(257).allergies());
}

I'd understand if this test expected an empty vector since the score cannot be constructed out of a sum of Allergen values, by I can't figure out why Allergen::Eggs are expected to get through.

@adolfosilva
Copy link

I don't quite remember what this test was supposed to do due to lack of documentation and from being a translation from some other language.

The score can be the sum of all the Allergen index values (starting at 1) which would be equal to 255 and that test is covered. With a value of 257, we get a result that's essentially Allergies(1) (256 counts as 0). Allergies(258) would be Allergies(2) and so on...

Sorry that i can't be of more help than this.

@andrey-gvrd
Copy link
Author

That would make sense if your system's usize was 8 bits)

@kytrinyx
Copy link
Member

The idea behind this exercise was to introduce the idea of bitmasks. Beyond that I can't remember the details.

@andrey-gvrd
Copy link
Author

Wow, that part went completely over my head.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants