Testing Sorting Algorithm Implementation in Python-100-Days
This test suite validates sorting algorithms implementation in Python, specifically testing merge sort and selection sort functionality. The test cases verify correct ordering and edge cases for both sorting methods using unittest framework.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
jackfrued/python-100-days
Day16-20/code/test_example02.py
from unittest import TestCase
from example02 import select_sort, merge
class TestExample02(TestCase):
"""测试排序函数的测试用例"""
def setUp(self):
self.data1 = [35, 97, 12, 68, 55, 73, 81, 40]
self.items1 = [12, 35, 68, 97]
self.items2 = [40, 55, 73, 81]
def test_merge(self):
items = merge(self.items1, self.items2)
for i in range(len(items) - 1):
self.assertLessEqual(items[i], items[i + 1])
def test_select_sort(self):
"""测试顺序查找"""
items = select_sort(self.data1)
for i in range(len(items) - 1):
self.assertLessEqual(items[i], items[i + 1])