gitee.com/quant1x/gox@v1.21.2/progressbar/bar_test.go (about) 1 package progressbar 2 3 import ( 4 "sync" 5 "testing" 6 "time" 7 ) 8 9 func TestBar(t *testing.T) { 10 11 b := NewBar(1, "1st", 20000) 12 b2 := NewBar(2, "2st", 10000) 13 b3 := NewBar(3, "3st", 30000) 14 15 b.SetSpeedSection(900, 100) 16 b2.SetSpeedSection(900, 100) 17 b3.SetSpeedSection(900, 100) 18 b4 := NewBar(0, "4st", 4000*3) 19 var wg sync.WaitGroup 20 wg.Add(4) 21 go func() { 22 defer wg.Done() 23 for i := 0; i < 20000; i++ { 24 b.Add() 25 time.Sleep(time.Second / 2000) 26 } 27 }() 28 29 go func() { 30 defer wg.Done() 31 for i := 0; i < 10000; i++ { 32 b2.Add() 33 time.Sleep(time.Second / 1000) 34 } 35 }() 36 go func() { 37 defer wg.Done() 38 for i := 0; i < 30000; i++ { 39 b3.Add() 40 time.Sleep(time.Second / 3000) 41 } 42 }() 43 44 go func() { 45 defer wg.Done() 46 for i := 0; i < 4000; i++ { 47 b4.Add(3) 48 time.Sleep(time.Second / 300) 49 } 50 b4.Wait() 51 }() 52 wg.Wait() 53 } 54 55 func TestBar1(t *testing.T) { 56 57 b := NewBar(1, "1st", 20000) 58 59 //b.SetSpeedSection(900, 100) 60 var wg sync.WaitGroup 61 wg.Add(1) 62 go func() { 63 defer wg.Done() 64 for i := 0; i < 20000; i++ { 65 b.Add() 66 time.Sleep(time.Second / 2000) 67 } 68 }() 69 70 wg.Wait() 71 }