From 4311b9ac668c2fb8dc80ce10944f4fdd9f2d9bad Mon Sep 17 00:00:00 2001 From: dudaodong Date: Wed, 26 Apr 2023 14:59:45 +0800 Subject: [PATCH] test: remove t.Log() --- algorithm/sort_test.go | 1 - concurrency/channel_test.go | 1 - convertor/convertor_test.go | 1 - datastructure/hashmap/hashmap_test.go | 1 - datastructure/tree/bstree_test.go | 6 ------ datetime/conversion_test.go | 9 +++------ fileutil/file_example_test.go | 2 +- fileutil/file_test.go | 13 ++++++------- formatter/formatter_test.go | 2 -- mathutil/mathutil_test.go | 1 - netutil/http_test.go | 2 +- netutil/net_test.go | 2 +- random/random_test.go | 3 --- slice/slice_test.go | 9 +++------ 14 files changed, 15 insertions(+), 38 deletions(-) diff --git a/algorithm/sort_test.go b/algorithm/sort_test.go index 93faebd..febed28 100644 --- a/algorithm/sort_test.go +++ b/algorithm/sort_test.go @@ -200,7 +200,6 @@ func TestCountSort(t *testing.T) { } comparator := &peopleAgeComparator{} sortedPeopleByAge := CountSort(peoples, comparator) - t.Log(sortedPeopleByAge) expected := "[{d 8} {b 10} {c 17} {a 20} {e 28}]" actual := fmt.Sprintf("%v", sortedPeopleByAge) diff --git a/concurrency/channel_test.go b/concurrency/channel_test.go index cc6c56d..83df873 100644 --- a/concurrency/channel_test.go +++ b/concurrency/channel_test.go @@ -181,7 +181,6 @@ func TestBridge(t *testing.T) { index := 0 for val := range c.Bridge(ctx, genVals()) { - // t.Logf("%v ", val) //0 1 2 3 4 5 6 7 8 9 assert.Equal(index, val) index++ } diff --git a/convertor/convertor_test.go b/convertor/convertor_test.go index 08fd5f4..ba206a6 100644 --- a/convertor/convertor_test.go +++ b/convertor/convertor_test.go @@ -306,7 +306,6 @@ func TestDeepClone(t *testing.T) { for i, item := range cases { cloned := DeepClone(item) - t.Log(cloned) if &cloned == &item { t.Fatalf("[TestDeepClone case #%d failed]: equal pointer", i) } diff --git a/datastructure/hashmap/hashmap_test.go b/datastructure/hashmap/hashmap_test.go index 4320f67..6f85a0c 100644 --- a/datastructure/hashmap/hashmap_test.go +++ b/datastructure/hashmap/hashmap_test.go @@ -64,7 +64,6 @@ func TestHashMap_KeysValues(t *testing.T) { keys := hm.Keys() values := hm.Values() - t.Log(keys, values) assert.Equal(3, len(values)) assert.Equal(3, len(keys)) diff --git a/datastructure/tree/bstree_test.go b/datastructure/tree/bstree_test.go index c7de570..4711e04 100644 --- a/datastructure/tree/bstree_test.go +++ b/datastructure/tree/bstree_test.go @@ -40,7 +40,6 @@ func TestBSTree_PreOrderTraverse(t *testing.T) { bstree.Insert(4) acturl := bstree.PreOrderTraverse() - t.Log(acturl) assert.Equal([]int{6, 5, 2, 4, 7}, acturl) } @@ -55,7 +54,6 @@ func TestBSTree_PostOrderTraverse(t *testing.T) { bstree.Insert(4) acturl := bstree.PostOrderTraverse() - t.Log(acturl) assert.Equal([]int{5, 2, 4, 7, 6}, acturl) } @@ -70,7 +68,6 @@ func TestBSTree_InOrderTraverse(t *testing.T) { bstree.Insert(4) acturl := bstree.InOrderTraverse() - t.Log(acturl) assert.Equal([]int{2, 4, 5, 6, 7}, acturl) } @@ -85,7 +82,6 @@ func TestBSTree_LevelOrderTraverse(t *testing.T) { bstree.Insert(4) acturl := bstree.LevelOrderTraverse() - t.Log(acturl) assert.Equal([]int{6, 5, 7, 2, 4}, acturl) } @@ -102,14 +98,12 @@ func TestBSTree_Delete(t *testing.T) { bstree.Delete(4) acturl1 := bstree.InOrderTraverse() - t.Log(acturl1) assert.Equal([]int{2, 5, 6, 7}, acturl1) //todo // bstree.DeletetNode(6, comparator) // bstree.Print() // acturl2 := bstree.InOrderTraverse() - // t.Log(acturl2) // assert.Equal([]int{2, 5, 7}, acturl2) } diff --git a/datetime/conversion_test.go b/datetime/conversion_test.go index 57c294d..7700ca2 100644 --- a/datetime/conversion_test.go +++ b/datetime/conversion_test.go @@ -20,9 +20,8 @@ func TestToFormat(t *testing.T) { assert := internal.NewAssert(t, "TestToFormat") tm, err := NewFormat("2022-03-18 17:04:05") + assert.Equal("2022-03-18 17:04:05", tm.ToFormat()) assert.IsNil(err) - - t.Log("ToFormat -> ", tm.ToFormat()) } func TestToFormatForTpl(t *testing.T) { @@ -32,9 +31,8 @@ func TestToFormatForTpl(t *testing.T) { assert.IsNotNil(err) tm, err := NewFormat("2022-03-18 17:04:05") + assert.Equal("2022/03/18 17:04:05", tm.ToFormatForTpl("2006/01/02 15:04:05")) assert.IsNil(err) - - t.Log("ToFormatForTpl -> ", tm.ToFormatForTpl("2006/01/02 15:04:05")) } func TestToIso8601(t *testing.T) { @@ -44,7 +42,6 @@ func TestToIso8601(t *testing.T) { assert.IsNotNil(err) tm, err := NewISO8601("2006-01-02T15:04:05.999Z") + assert.Equal("2006-01-02T23:04:05+08:00", tm.ToIso8601()) assert.IsNil(err) - - t.Log("ToIso8601 -> ", tm.ToIso8601()) } diff --git a/fileutil/file_example_test.go b/fileutil/file_example_test.go index 85ab1c4..73f2390 100644 --- a/fileutil/file_example_test.go +++ b/fileutil/file_example_test.go @@ -254,7 +254,7 @@ func ExampleMTime() { fmt.Println(err) // Output: - // 1682391110 + // 1682478195 // } diff --git a/fileutil/file_test.go b/fileutil/file_test.go index 9dca0b5..d760ea8 100644 --- a/fileutil/file_test.go +++ b/fileutil/file_test.go @@ -107,7 +107,7 @@ func TestReadFileToString(t *testing.T) { _, err := f.WriteString("hello world") if err != nil { - t.Log(err) + t.Error(err) } content, _ := ReadFileToString(path) @@ -127,7 +127,7 @@ func TestClearFile(t *testing.T) { _, err := f.WriteString("hello world") if err != nil { - t.Log(err) + t.Error(err) } err = ClearFile(path) @@ -151,7 +151,7 @@ func TestReadFileByLine(t *testing.T) { _, err := f.WriteString("hello\nworld") if err != nil { - t.Log(err) + t.Error(err) } expected := []string{"hello", "world"} @@ -198,9 +198,9 @@ func TestFileMode(t *testing.T) { CreateFile(srcFile) mode, err := FileMode(srcFile) - assert.IsNil(err) - t.Log(mode) + assert.IsNotNil(mode) + assert.IsNil(err) os.Remove(srcFile) } @@ -269,7 +269,7 @@ func TestMTime(t *testing.T) { mtime, err := MTime("./testdata/test.txt") assert.IsNil(err) - assert.Equal(int64(1682391110), mtime) + assert.Equal(int64(1682478195), mtime) } func TestSha(t *testing.T) { @@ -289,7 +289,6 @@ func TestReadCsvFile(t *testing.T) { assert := internal.NewAssert(t, "TestReadCsvFile") content, err := ReadCsvFile("./testdata/test.csv") - t.Log(content) assert.IsNil(err) diff --git a/formatter/formatter_test.go b/formatter/formatter_test.go index ed31290..a92a72d 100644 --- a/formatter/formatter_test.go +++ b/formatter/formatter_test.go @@ -55,8 +55,6 @@ func TestPretty(t *testing.T) { result, err := Pretty(v) assert.IsNil(err) - - t.Log("result -> ", result) assert.Equal(expects[i], result) } } diff --git a/mathutil/mathutil_test.go b/mathutil/mathutil_test.go index b8b8e28..62bc390 100644 --- a/mathutil/mathutil_test.go +++ b/mathutil/mathutil_test.go @@ -78,7 +78,6 @@ func TestAverage(t *testing.T) { assert.Equal(Average(0, 0), 0) assert.Equal(Average(1, 1), 1) avg := Average(1.2, 1.4) - t.Log(avg) assert.Equal(1.3, RoundToFloat(avg, 1)) } diff --git a/netutil/http_test.go b/netutil/http_test.go index 2782851..757e76e 100644 --- a/netutil/http_test.go +++ b/netutil/http_test.go @@ -182,7 +182,7 @@ func TestHttpClient_Get(t *testing.T) { var todo Todo err = httpClient.DecodeResponse(resp, &todo) if err != nil { - t.Log(err) + t.FailNow() } assert.Equal(1, todo.Id) diff --git a/netutil/net_test.go b/netutil/net_test.go index 4fc2455..7e07b0e 100644 --- a/netutil/net_test.go +++ b/netutil/net_test.go @@ -103,7 +103,7 @@ func TestEncodeUrl(t *testing.T) { urlAddr := "http://www.lancet.com?a=1&b=[2]" encodedUrl, err := EncodeUrl(urlAddr) if err != nil { - t.Log(err) + t.Fail() } expected := "http://www.lancet.com?a=1&b=%5B2%5D" diff --git a/random/random_test.go b/random/random_test.go index 7e4627e..c4b693b 100644 --- a/random/random_test.go +++ b/random/random_test.go @@ -57,7 +57,6 @@ func TestRandNumeralOrLetter(t *testing.T) { reg := regexp.MustCompile(pattern) randStr := RandNumeralOrLetter(10) - t.Log(randStr) assert := internal.NewAssert(t, "TestRandNumeralOrLetter") assert.Equal(10, len(randStr)) @@ -68,7 +67,6 @@ func TestRandInt(t *testing.T) { assert := internal.NewAssert(t, "TestRandInt") r1 := RandInt(1, 10) - t.Log(r1) assert.GreaterOrEqual(r1, 1) assert.Less(r1, 10) @@ -99,7 +97,6 @@ func TestUUIdV4(t *testing.T) { uuid, err := UUIdV4() if err != nil { - t.Log(err) t.Fail() } diff --git a/slice/slice_test.go b/slice/slice_test.go index 32c5c8a..5609838 100644 --- a/slice/slice_test.go +++ b/slice/slice_test.go @@ -594,7 +594,6 @@ func TestInsertAt(t *testing.T) { assert.Equal([]string{"a", "b", "c", "1"}, InsertAt(strs, 3, "1")) assert.Equal([]string{"1", "2", "3", "a", "b", "c"}, InsertAt(strs, 0, []string{"1", "2", "3"})) assert.Equal([]string{"a", "b", "c", "1", "2", "3"}, InsertAt(strs, 3, []string{"1", "2", "3"})) - t.Log(strs) } func TestUpdateAt(t *testing.T) { @@ -821,10 +820,9 @@ func TestSortBy(t *testing.T) { return a.Age < b.Age }) - t.Logf("sort users by age: %v", users) - - // output - // [{b 15} {a 21} {c 100}] + assert.EqualValues(15, users[0].Age) + assert.EqualValues(21, users[1].Age) + assert.EqualValues(100, users[2].Age) } func TestSortByFielDesc(t *testing.T) { @@ -890,7 +888,6 @@ func TestShuffle(t *testing.T) { s := []int{1, 2, 3, 4, 5} res := Shuffle(s) - t.Log("Shuffle result: ", res) assert.Equal(5, len(res)) }