单元测试
#!/usr/bin/env python3.3 # -*- coding: utf-8 -*- # Copyright 2013 from test import support import unittest import random import sort class SortTests(unittest.TestCase): def setUp(self): self.data = [random.randint(1, 10000) for i in range(10000)] def tearDown(self): self.data = None def test_heap_sort(self): sort_result = sort.heap_sort(self.data) self.assertTrue(sort.check_result(sort_result)) def test_shell_sort(self): sort_result = sort.shell_sort(self.data) self.assertTrue(sort.check_result(sort_result)) def test_quick_sort(self): sort_result = sort.quick_sort(self.data, 0, len(self.data)-1) self.assertTrue(sort.check_result(sort_result)) def test_bucket_sort(self): sort_result = sort.bucket_sort(self.data, 1000, 100) self.assertTrue(sort.check_result(sort_result)) def test_main(): support.run_unittest(SortTests) if __name__ == '__main__': test_main()