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

Wrong ENUMS in Allergies #142

Open
ysf opened this issue Nov 8, 2021 · 5 comments
Open

Wrong ENUMS in Allergies #142

ysf opened this issue Nov 8, 2021 · 5 comments

Comments

@ysf
Copy link

ysf commented Nov 8, 2021

I think there is a bug in https://exercism.org/tracks/x86-64-assembly/exercises/allergies - the README states that the values defined in the enum are powers of 2, but the C file that tests against is not defining them as such. They are defined sequentially.

@bergjohan
Copy link
Contributor

Hi,

I can see why you'd think this is a bug, however it's actually not. I'll try to explain.

The exercise it taken from https://github.com/exercism/problem-specifications/blob/main/exercises/allergies/canonical-data.json where we can see that each test case takes an item and a score as input.

The item is a string in the specification. This might be fine for languages that has good support for string handling, but for languages like C and assembly, dealing with strings is not that much fun, and we'd instead prefer to use enum values.

The values for the items in the description (https://github.com/exercism/problem-specifications/blob/main/exercises/allergies/description.md) does not correspond to the enum values, but are instead just used to test if a person is allergic to a specific item or not.

So if we pass the enum value for PEANUTS and the score of 2, we would get true since the value 2 tells us that there's a peanut allergy, and the item passed was PEANUTS.

If you think about it, it's actually a bit field, where different bits mark different allgeries.

I hope this makes sense, I would also like to add that this is how other languages do it as well, e.g. C and C#. See:
https://github.com/exercism/c/blob/main/exercises/practice/allergies/allergies.h
https://github.com/exercism/csharp/blob/main/exercises/practice/allergies/Allergies.cs

Let me know if anything is unclear, or if you have any further questions!

@SleeplessByte
Copy link
Member

Using bitfields is exactly what I've seen in many tracks. This comment is merely to support this implementation. Powers of two encoded in a single number are (usually) bit flags in a bit field :)

@ysf
Copy link
Author

ysf commented Nov 12, 2021

Thanks for your quick reply!

I completely understand your point and know how bitfields work and what is meant to be the exercise. However, I have a mentee trying to solve this and she says that the values in the corresponding C file are not defined as specified in the readme. And I have to say that she is right. I think that either we have to adapt the tests to show that the ENUMS values are used to shift bits into place instead of ASSERTING with "magic" numbers OR adapt the readme/specification stating this. I think that everyone agrees that the exercise is not to find out what could be meant but working with bitfields in assembler instead.

@bergjohan
Copy link
Contributor

Hm, maybe I'm wrong, the C# example solution actually uses the values in the specifications for the enum: https://github.com/exercism/csharp/blob/main/exercises/practice/allergies/.meta/Example.cs

@ErikSchierboom
Copy link
Member

FYI The allergies exercise is currently causing the build to fail: https://github.com/exercism/x86-64-assembly/runs/4321821043?check_suite_focus=true

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

4 participants