17 Star 36 Fork 10

BarryLiao-廖显东 / goProgressor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
bar_test.go 635 Bytes
一键复制 编辑 原始数据 按行查看 历史
githubvip 提交于 2019-11-29 16:18 . commit
package goprogressor
import (
"math/rand"
"runtime"
"strings"
"sync"
"testing"
"time"
)
func TestBarPrepend(t *testing.T) {
b := NewBar(100)
b.PrependCompleted()
b.Set(50)
if !strings.Contains(b.String(), "50") {
t.Fatal("want", "50%", "in", b.String())
}
}
func TestBarIncr(t *testing.T) {
b := NewBar(10000)
runtime.GOMAXPROCS(runtime.NumCPU())
var wg sync.WaitGroup
for i := 0; i < 10000; i++ {
wg.Add(1)
go func() {
defer wg.Done()
b.Incr()
time.Sleep(time.Millisecond * time.Duration(rand.Intn(10)))
}()
}
wg.Wait()
if b.Current() != 10000 {
t.Fatal("need", 10000, "got", b.Current())
}
}
Go
1
https://gitee.com/shirdonl/goProgressor.git
git@gitee.com:shirdonl/goProgressor.git
shirdonl
goProgressor
goProgressor
master

搜索帮助