mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
from nose.tools import assert_equal
|
|
|
|
|
|
class TestPartition(object):
|
|
|
|
def test_partition(self):
|
|
print('Test: Empty list')
|
|
linked_list = MyLinkedList(None)
|
|
linked_list.partition(10)
|
|
assert_equal(linked_list.get_all_data(), [])
|
|
|
|
print('Test: One element list, left list empty')
|
|
linked_list = MyLinkedList(Node(5))
|
|
linked_list.partition(0)
|
|
assert_equal(linked_list.get_all_data(), [5])
|
|
|
|
print('Test: Right list is empty')
|
|
linked_list = MyLinkedList(Node(5))
|
|
linked_list.partition(10)
|
|
assert_equal(linked_list.get_all_data(), [5])
|
|
|
|
print('Test: General case')
|
|
# Partition = 10
|
|
# Input: 4, 3, 7, 8, 10, 1, 10, 12
|
|
# Output: 4, 3, 7, 8, 1, 10, 10, 12
|
|
linked_list = MyLinkedList(Node(12))
|
|
linked_list.insert_to_front(10)
|
|
linked_list.insert_to_front(1)
|
|
linked_list.insert_to_front(10)
|
|
linked_list.insert_to_front(8)
|
|
linked_list.insert_to_front(7)
|
|
linked_list.insert_to_front(3)
|
|
linked_list.insert_to_front(4)
|
|
partitioned_list = linked_list.partition(10)
|
|
assert_equal(partitioned_list.get_all_data(),
|
|
[4, 3, 7, 8, 1, 10, 10, 12])
|
|
|
|
print('Success: test_partition')
|
|
|
|
def main():
|
|
test = TestPartition()
|
|
test.test_partition()
|
|
|
|
if __name__ == '__main__':
|
|
main() |