selectionSort_test

  • 2022-12-14
  • 浏览 (508)

selectionSort_test.go 源码

package sort

import (
	"fmt"
	"math/rand"
	"testing"
	"time"
)

func TestSelectionSort(t *testing.T) {
	//只有一个数据时能否正常运行
	one := []int{1}
	selectionSort(one)
	fmt.Println(one)

	//只有两个数据时能否正常运行
	two := []int{3, 1}
	selectionSort(two)
	fmt.Println(two)

	//多个数据时是否正常运行
	var data []int
	rand.Seed(time.Now().Unix())

	for i := 0; i < length; i++ {
		data = append(data, rand.Intn(1000))
	}

	selectionSort(data)
	fmt.Println(data)
}

你可能感兴趣的文章

bubbleSort

bubbleSort_test

bucket_sort

0  赞