From 8643efece96023cec959d24df6856491c4043ac9 Mon Sep 17 00:00:00 2001 From: chenshilong Date: Wed, 7 Dec 2022 18:38:12 +0800 Subject: [PATCH] 1.bubble sort using go 2.test edited --- .../bubble_sort/bubble_sort_test.go | 32 ++++--------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/codes/go/chapter_sorting/bubble_sort/bubble_sort_test.go b/codes/go/chapter_sorting/bubble_sort/bubble_sort_test.go index 51b8915..bab8513 100644 --- a/codes/go/chapter_sorting/bubble_sort/bubble_sort_test.go +++ b/codes/go/chapter_sorting/bubble_sort/bubble_sort_test.go @@ -10,31 +10,11 @@ import ( ) func TestBubbleSort(t *testing.T) { - var ( - arr = []int{5, 4, 3, 2, 1} - ) - fmt.Println("冒泡排序前的数组:", arr) - bubbleSort(arr) - for i := 1; i < len(arr); i++ { - if arr[i] < arr[i-1] { - t.Errorf("排序不正确") - break - } - } - fmt.Println("冒泡排序后的数组:", arr) -} + nums := []int{4, 1, 3, 1, 5, 2} + bubbleSort(nums) + fmt.Println("冒泡排序完成后 nums = ", nums) -func TestBubbleSortWithFlag(t *testing.T) { - var ( - arr = []int{5, 4, 3, 2, 1} - ) - fmt.Println("冒泡排序前的数组:", arr) - bubbleSortWithFlag(arr) - for i := 1; i < len(arr); i++ { - if arr[i] < arr[i-1] { - t.Errorf("排序不正确") - break - } - } - fmt.Println("冒泡排序后的数组:", arr) + nums1 := []int{4, 1, 3, 1, 5, 2} + bubbleSortWithFlag(nums1) + fmt.Println("冒泡排序完成后 nums1 = ", nums) }