Debian Codegraph @

bar_test.go

raw
1 package uiprogress
2
3 import (
4 "math/rand"
5 "runtime"
6 "strings"
7 "sync"
8 "testing"
9 "time"
10 )
11
12 func TestBarPrepend(t *testing.T) {
13 b := NewBar(100)
14 b.PrependCompleted()
15 b.Set(50)
16 if !strings.Contains(b.String(), "50") {
17 t.Fatal("want", "50%", "in", b.String())
18 }
19 }
20
21 func TestBarIncr(t *testing.T) {
22 b := NewBar(10000)
23 runtime.GOMAXPROCS(runtime.NumCPU())
24 var wg sync.WaitGroup
25 for i := 0; i < 10000; i++ {
26 wg.Add(1)
27 go func() {
28 defer wg.Done()
29 b.Incr()
30 time.Sleep(time.Millisecond * time.Duration(rand.Intn(10)))
31 }()
32 }
33 wg.Wait()
34 if b.Current() != 10000 {
35 t.Fatal("need", 10000, "got", b.Current())
36 }
37 }