-
-
Notifications
You must be signed in to change notification settings - Fork 546
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
Issue with Allergierss #1636
Comments
I'm not sure there's anything that can be done in this repo for this, as the problem of how to represent those values is entirely up to each language track. There is no bitfield / enum type in JSON, so we're limited to representing the values as either integers or strings; it's assumed the tracks will provide a dummy file with an appropriate enumerated type for the student to work from. |
Well yes, but the tests do enforce their values: https://github.com/exercism/problem-specifications/blob/master/exercises/allergies/canonical-data.json This means that it might make sense to have one test case for the above-mentioned combination, as I think will be several languages that implement it the same way C# did. |
Admittedly I can barely read C#, but isn't that failing test case already covered by the "more than eggs but not peanuts" test, in combination with the two tests that establish that the value of eggs is 1 and shellfish is 4? I'm happy to entertain a change here, I'm just not seeing what that proposed new test case (or test cases) would be. |
I'm not sure either :D |
The problem is that the test do not really enforce the values provided in the instruction set. At least the tests in C#.
is using 5 as input and expects a list of 2 Enum values { Allergen.Eggs, Allergen.Shellfish }
The first_test.A passed, magic numbers to enum, but first_test.B doesn't pass
Only the final test Assert.Equal(magic_number, mask); fails meaning that the 5 is really created by the folling magic 5 = 2^Allergen.Eggs + 2^Allergen.Shellfish and not 5 = Allergen.Eggs + Allergen.Shellfish. |
Somewhat ... it doesn't really clarify what we can do about it. Each of the allergen names is associated within the canonical data with a specific value, and each value is associated with a specific name ... there being no real way to store an enum any other way in JSON we've been leaving it up to the tracks to decide how to actually implement it ... so if C# would benefit from these values being explicitly locked in an Enum that needs to be provided in a an appropriate file in the track's implementation that the student either receives with instructions not to change, or responding to this will just kind of have to be a mentor issue. Or we need to figure out a way of encoding enums effectively into JSON. |
I think in this case we'll probably just have to update the C# tests then. |
Am I correct in stating that we prefer the option 34 = 2(peanuts = 2) + 32(chocolat = 32) over 34 = 2^1(peanuts = 1) + 2^5(chocolate)?
results in
This way we create a loopback from the enum value which reduces the chance to choose the more complect psoibility. |
This is where we have to get careful with terminology and operators ... the item peanuts is assigned the value 2 and chocolate is assigned the value 32. Assuming that you're using
Sorry, confused again ... it doesn't make sense for "not allergic to anything" to be False if item is "peanuts" and score is the numeric value of peanuts (2) ... you're wanting to set them both to the name of the item (ie a string)? That would seem to only make translating the canonical data to a track implementation harder, but again I'm unclear on what you're trying to communicate here.
I'm not entirely clear on how this is any different than the existing canonical test that checks item of "peanuts" and score of 2. |
In the solution I provided in the beginning of this issue, the values are as follow;
Using these value, together with the provide solution, all tests pass. In your answer you state that in none of the tests Peanuts is assigned the value 1, but in fact assigned to the value of 2. But being assigned doesn't mean being equal. To be honest the test don't really care what the value of the item peanuts is, There is a solution possible where peanuts is equal to the value 1 and chocolate has the value 5. Another solution is possible where peanuts has the value of 2 and chocolate has the value of 32. Since both solution passes all the test, either all both solutions are correct, or the tests need to be improved to guide the student to the version we prefer. |
Ok, thanks for the extra detail, that helps me better understand your issue. However I still don't think this repo is the place to address it. Essentially this repo's purpose is to provide common data that describes the tests known to be necessary to say that a solution is minimally correct ... if your user can write a solution for the tests you've created from that data that gets the correct answer (in this case Now, you're right, the tests in C# apparently don't care what the value assigned to "peanuts" actually is ... they haven't taken that knowledge and described it to the student in a way that incentivizes a powers of 2 solution as "more" correct than an index-based solution ... but that's fine, if the track doesn't hold a strong preference about the desired implementation. If they do then the simplest alternative is to provide a dummy file that has the appropriate The usual preference is to prefer a bitwise operator / bitfield solution, but that's because this is one of the few exercises that affords that opportunity to teach that concept in a concise manner ... it's not a requirement though unless the track chooses to state that it's a requirement of their students. So, to answer this point:
Yes ... both are equally correct, and if the C# track wants to move the burden of stating the track's preference from the mentor to the tests then, unless I'm missing something, the track has what it need to build those tests. However I'd still tend to leave this in the mentor / mentee space, because both approaches are roughly equivalent, logically ... I mean you're either using bitwise operations to look up the value at a particular bit in bitfield or you're using indexing and arithmetic to look up the value at a particular index in an array. A student who solves this with an array lookup is correct, they're just not very efficient. Personally I think that's the point at which a mentor's advice will come in most helpful. That said if you want to make a PR with your proposed new test(s) in it, that's fine, as I don't think it would break any other track's test generation; #1560 will block it from being merged for the moment, as it's not a bug fix, but we'd get it incorporated eventually. |
Being a C# maintainer, I think what we could do is to write an analyzer to check if the student uses bit values for the enums. I don't think this is a cross-track issue, which is why I think this issue can be closed. If anyone disagrees, feel free to re-open. |
A student posted the following solution to the Allergies exercise (or something along this lines)
I believe this solution to be incorrect, but it passes all test.
The problem i see is that the
IsAllergicTo
function works only in the case that the enum is left untouched.I believe that this is caused by not using the enum values in the test but hardcoded values. The following Test failed.
The text was updated successfully, but these errors were encountered: