This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is one of the coding challenges I encountered over at Dolby. This is quite straight forward.