Discussion thread for Blood types.
Hi, I think there might be a problem with one of the tests for the blood types problem. The test âLucky AB+ patientâ doesnât specify a list of donations, but instead a single string. Is this intentional? If it is, the problem description should probably be updated since it doesnât match the tests:
The personâs blood type as a string, and a list of strings with available blood types.
We can handle this in the solution code of course, but it seems a little bit unfair if the description doesnât match the test code!
Ah thanks for catching that @sharepaprika! Definitely a bug which can make for some frustrating debugging since itâs our fault.
Weâve been using the in
operator to check for blood types in donated_blood
so never noticed the bug. Just learned that "B+" in "B+"
returns True
in Python. But can be an annoying bug if coding in another language.
Hi, thanks a lot for taking care of it. Youâre right that Python can be really confusing in this situation: strings are iterables, so itâs hard to differentiate (for example to handle this I used collections.abc
to test whether the input was a non-string iterable). But for Project Lovelace it will definitely be better to just make sure the input is always a list.
If youâre interested in other feedback for the same problem, I think the test coverage could be improved a bit. It mainly tests for cases where a match is found with hardly any tests for failed matches, and this means that 7/8 tests pass with the default code.
Thanks for your help, and also sorry for not mentioning I was talking about the Python solution!
Oh lol just tried it and yeah 6/8 test cases passed with return True
so thatâs probably a good idea. Just opened an issue so we get around to it: https://github.com/project-lovelace/lovelace-problems/issues/42
Hey, i think the validation of the solutions on your side needs some reworking.
With this code:
def survive(blood_type, donated_blood):
if blood_type in donated_blood:
res = True
else:
res = False
return res
I was able to pass all 7 test cases. But as I understand I shouldnât have been able to. And after i retried it getting both âPassedâ and âFailedâ a few times Iâm certain that it shouldnât have worked.
Yeah, the test-suite is definitely not good - the following code passes:
def survive(blood_type, donated_blood):
return len(donated_blood) > 0
Thank you @Fry_Philip_J and @ashwhall for pointing this point. benallan added some new test cases to the problem in this PR so only fully correct solutions should pass now.