Blood types

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!

1 Like

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!

1 Like

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.