We've got a base project going for us, which is nice. But let's add some proper unit tests as well as some code formatters! Note; you can find the live repository for this project here.
The refactored test in our video looks like this:
import pytest @pytest.mark.parametrize("n,expected", [(0, 0), (5, 5), (10, 10), (26, 26), (1000, 26)]) def test_headtail_size(base_clumper, n, expected): assert len(base_clumper.head(n)) == expected assert len(base_clumper.tail(n)) == expected
It totally fails. You may be able to see why when you look
at the code that was in our
class Clumper: def __init__(self, blob): self.blob = blob def __len__(self): return len(self.blob) def keep(self, *funcs): data = self.blob for func in funcs: data = [d for d in data if func(d)] return Clumper(data) def head(self, n): return Clumper([self.blob[i] for i in range(n)]) def tail(self, n): return Clumper([self.blob[-i] for i in range(1, n + 1)])
Feedback? See an issue? Something unclear? Feel free to mention it here.
If you want to be kept up to date, consider getting the newsletter.