mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-06 17:38:02 +00:00
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
from nose.tools import assert_equal
|
|
|
|
|
|
class TestAddReverse(object):
|
|
|
|
def test_add_reverse(self):
|
|
print('Test: Empty list(s)')
|
|
assert_equal(MyLinkedList().add_reverse(None, None), None)
|
|
assert_equal(MyLinkedList().add_reverse(Node(5), None), None)
|
|
assert_equal(MyLinkedList().add_reverse(None, Node(10)), None)
|
|
|
|
print('Test: Add values of different lengths')
|
|
# Input 1: 6->5->None
|
|
# Input 2: 9->8->7
|
|
# Result: 5->4->8
|
|
first_list = MyLinkedList(Node(6))
|
|
first_list.append(5)
|
|
second_list = MyLinkedList(Node(9))
|
|
second_list.append(8)
|
|
second_list.append(7)
|
|
result = MyLinkedList().add_reverse(first_list, second_list)
|
|
assert_equal(result.get_all_data(), [5, 4, 8])
|
|
|
|
print('Test: Add values of same lengths')
|
|
# Input 1: 6->5->4
|
|
# Input 2: 9->8->7
|
|
# Result: 5->4->2->1
|
|
first_head = Node(6)
|
|
first_list = MyLinkedList(first_head)
|
|
first_list.append(5)
|
|
first_list.append(4)
|
|
second_head = Node(9)
|
|
second_list = MyLinkedList(second_head)
|
|
second_list.append(8)
|
|
second_list.append(7)
|
|
result = MyLinkedList().add_reverse(first_list, second_list)
|
|
assert_equal(result.get_all_data(), [5, 4, 2, 1])
|
|
|
|
print('Success: test_add_reverse')
|
|
|
|
|
|
def main():
|
|
test = TestAddReverse()
|
|
test.test_add_reverse()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main() |