This is the tests I have extracted from the given samples.
def test_provided_1(self):
self.assertEqual('Low', solution('Heelo Codevval | Hello Codeeval'))
def test_provided_2(self):
self.assertEqual('Critical', solution('hELLO cODEEVAL | Hello Codeeval'))
def test_provided_3(self):
self.assertEqual('Done', solution('Hello Codeeval | Hello Codeeval'))
Notice that the two versions have the same length, and that the error checking is case sensitive.After splitting the input line on ' | ' I simply count the bugs comparing the elements in the same position for the two components in the list:
bugs = 0
for i in range(len(data[0])):
if data[0][i] != data[1][i]:
bugs += 1
Then it is just a matter of swithing on the bugs and returning an appropriated message. However, for some obscure reason, Python does not have a switch statement. So the better I could think of, was a if/elif/else structure:if bugs == 0:
return 'Done'
elif bugs < 3:
return 'Low'
elif bugs < 5:
return 'Medium'
elif bugs < 7:
return 'High'
else:
return 'Critical'
That's it. Submitted to CodeEval, than pushed to GitHub, both test case and python script.
No comments:
Post a Comment