def test_iterate_ordered_calls(self): powers_of_two = solution.iterate(lambda x: x * 2) f = next(powers_of_two) self.assertEqual(1 * 'eggs', f('eggs')) f = next(powers_of_two) self.assertEqual(2 * 'ham', f('ham')) f = next(powers_of_two) self.assertEqual(4 * 'spam', f('spam')) f = next(powers_of_two) self.assertEqual(8 * 'spameggs', f('spameggs'))
def test_iterate_out_of_order_calls(self): powers_of_two = solution.iterate(lambda x: x*2) f0 = next(powers_of_two) f1 = next(powers_of_two) f2 = next(powers_of_two) f3 = next(powers_of_two) self.assertEqual(1 * 'eggs', f0('eggs')) self.assertEqual(2 * 'ham', f1('ham')) self.assertEqual(4 * 'spam', f2('spam')) self.assertEqual(8 * 'spameggs', f3('spameggs'))
def test_iterate_start_with_identity_function(self): # there's no such word, really bracketisers = solution.iterate(lambda x: '(' + x + ')') no_brackets = next(bracketisers) self.assertEqual('hello world', no_brackets('hello world'))