Testing QuickSort Algorithm Variants in hello-algo
A comprehensive test suite for validating QuickSort algorithm implementations in Go, covering standard QuickSort along with median pivot and tail recursion optimizations. The tests verify correct sorting behavior and optimization effectiveness across different input scenarios.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
krahets/hello-algo
codes/go/chapter_sorting/quick_sort_test.go
// File: quick_sort_test.go
// Created Time: 2022-12-12
// Author: msk397 ([email protected])
package chapter_sorting
import (
"fmt"
"testing"
)
// 快速排序
func TestQuickSort(t *testing.T) {
q := quickSort{}
nums := []int{4, 1, 3, 1, 5, 2}
q.quickSort(nums, 0, len(nums)-1)
fmt.Println("快速排序完成后 nums = ", nums)
}
// 快速排序(中位基准数优化)
func TestQuickSortMedian(t *testing.T) {
q := quickSortMedian{}
nums := []int{4, 1, 3, 1, 5, 2}
q.quickSort(nums, 0, len(nums)-1)
fmt.Println("快速排序(中位基准数优化)完成后 nums = ", nums)
}
// 快速排序(尾递归优化)
func TestQuickSortTailCall(t *testing.T) {
q := quickSortTailCall{}
nums := []int{4, 1, 3, 1, 5, 2}
q.quickSort(nums, 0, len(nums)-1)
fmt.Println("快速排序(尾递归优化)完成后 nums = ", nums)
}