File: bar_test.go

package info (click to toggle)
golang-github-xorpaul-uiprogress 0.0~git20170224.d0567a9-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 1,820 kB
  • sloc: makefile: 12
file content (37 lines) | stat: -rw-r--r-- 633 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package uiprogress

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())
	}
}