Skip to content

accumulate: fix lambda usage (see #287) #288

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

Merged
merged 1 commit into from
Jan 26, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions accumulate/accumulate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ def test_divmod(self):

def test_composition(self):
inp = [10, 17, 23]
fn1 = lambda x: divmod(x, 7)
fn2 = lambda x: 7 * x[0] + x[1]
self.assertEqual(inp, accumulate(accumulate(inp, fn1), fn2))
self.assertEqual(inp, accumulate(accumulate(inp, lambda x: divmod(x, 7)),
lambda x: 7 * x[0] + x[1]))

def test_capitalize(self):
inp = ['hello', 'world']
Expand All @@ -30,8 +29,8 @@ def test_capitalize(self):
def test_recursive(self):
inp = list('abc')
out = [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3'], ['c1', 'c2', 'c3']]
fn = lambda x: accumulate(list('123'), lambda y: x + y)
self.assertEqual(out, accumulate(inp, fn))
self.assertEqual(out, accumulate(inp, lambda x: accumulate(list('123'),
lambda y: x + y)))


if __name__ == '__main__':
Expand Down