github.com/songzhibin97/gkit@v1.2.13/window/init_test.go (about) 1 package window 2 3 import ( 4 "strconv" 5 "testing" 6 "time" 7 ) 8 9 func TestWindow(t *testing.T) { 10 w := NewWindow() 11 slice := []Index{ 12 {Name: "1", Score: 1}, 13 {Name: "2", Score: 2}, 14 {Name: "2", Score: 2}, 15 {Name: "3", Score: 3}, 16 {Name: "2", Score: 2}, 17 {Name: "3", Score: 3}, 18 {Name: "4", Score: 4}, 19 {Name: "3", Score: 3}, 20 {Name: "5", Score: 5}, 21 {Name: "2", Score: 2}, 22 {Name: "6", Score: 6}, 23 {Name: "5", Score: 5}, 24 } 25 /* 26 [{1 1} {2 2}] 27 [{2 4} {3 3} {1 1}] 28 [{1 1} {2 6} {3 6}] 29 [{3 9} {4 4} {1 1} {2 6}] 30 [{1 1} {2 8} {3 9} {4 4} {5 5}] 31 [{5 10} {3 9} {2 6} {4 4} {6 6}] 32 */ 33 for i := 0; i < len(slice); i += 2 { 34 w.AddIndex(slice[i].Name, slice[i].Score) 35 w.AddIndex(slice[i+1].Name, slice[i+1].Score) 36 time.Sleep(time.Second) 37 t.Log(w.Show()) 38 } 39 } 40 41 func BenchmarkWindow(b *testing.B) { 42 w := NewWindow() 43 for i := 0; i < b.N; i++ { 44 w.AddIndex(strconv.Itoa(i), uint(i)) 45 w.Show() 46 } 47 }