Skip to content

Instantly share code, notes, and snippets.

@dudepare
Created October 21, 2015 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dudepare/633f11386aacfb65289e to your computer and use it in GitHub Desktop.
Save dudepare/633f11386aacfb65289e to your computer and use it in GitHub Desktop.
import unittest
def next_bigger(l):
"""
This function returns a modified list
by appending a new element that is
bigger than the max element of the list
l = [], returns l[0]
l = [1,2,3], returns [1,2,3,4]
l = [6,5,9], returns [6,5,9,10]
"""
if len(l) == 0:
l.append(0)
else:
max_element = max(l)
l.append(max_element+1)
return l
class TestNextBigger(unittest.TestCase):
def test_empty(self):
self.assertEqual(next_bigger([]), [0])
def test_negative(self):
self.assertEqual(next_bigger([-2, -4, -1]), [-2, -4, -1, 0])
def test_positive(self):
self.assertEqual(next_bigger([4, 7, 9, 11, 31, 55, 33, 22]),
[4, 7, 9, 11, 31, 55, 33, 22, 56])
def test_mixed(self):
self.assertEqual(next_bigger([-2, 53, 0, -3, -99]),
[-2, 53, 0, -3, -99, 54])
if __name__ == '__main__':
unittest.main()
@dudepare
Copy link
Author

This is one of the coding challenges I encountered over at Dolby. This is quite straight forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment