File: progressbar_test.go

package info (click to toggle)
golang-code.rocketnine-tslocum-cview 1.5.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 3,396 kB
  • sloc: makefile: 40
file content (68 lines) | stat: -rw-r--r-- 2,121 bytes parent folder | download
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package cview

import (
	"testing"
)

func TestProgressBar(t *testing.T) {
	t.Parallel()

	// Initialize

	p := NewProgressBar()
	if p.GetProgress() != 0 {
		t.Errorf("failed to initialize ProgressBar: incorrect initial state: expected 0 progress, got %d", p.GetProgress())
	} else if p.GetMax() != 100 {
		t.Errorf("failed to initialize ProgressBar: incorrect initial state: expected 100 max, got %d", p.GetMax())
	} else if p.Complete() {
		t.Errorf("failed to initialize ProgressBar: incorrect initial state: expected incomplete, got complete")
	}

	// Add progress

	p.AddProgress(25)
	if p.GetProgress() != 25 {
		t.Errorf("failed to update ProgressBar: incorrect state: expected 25 progress, got %d", p.GetProgress())
	} else if p.Complete() {
		t.Errorf("failed to update ProgressBar: incorrect state: expected incomplete, got complete")
	}

	p.AddProgress(25)
	if p.GetProgress() != 50 {
		t.Errorf("failed to update ProgressBar: incorrect state: expected 50 progress, got %d", p.GetProgress())
	} else if p.Complete() {
		t.Errorf("failed to update ProgressBar: incorrect state: expected incomplete, got complete")
	}

	p.AddProgress(25)
	if p.GetProgress() != 75 {
		t.Errorf("failed to update ProgressBar: incorrect state: expected 75 progress, got %d", p.GetProgress())
	} else if p.Complete() {
		t.Errorf("failed to update ProgressBar: incorrect state: expected incomplete, got complete")
	}

	p.AddProgress(25)
	if p.GetProgress() != 100 {
		t.Errorf("failed to update ProgressBar: incorrect state: expected 100 progress, got %d", p.GetProgress())
	} else if !p.Complete() {
		t.Errorf("failed to update ProgressBar: incorrect state: expected complete, got incomplete")
	}

	// Reset progress

	p.SetProgress(0)
	if p.GetProgress() != 0 {
		t.Errorf("failed to update ProgressBar: incorrect state: expected 0 progress, got %d", p.GetProgress())
	} else if p.Complete() {
		t.Errorf("failed to update ProgressBar: incorrect state: expected incomplete, got complete")
	}

	// Draw

	app, err := newTestApp(p)
	if err != nil {
		t.Errorf("failed to initialize Application: %s", err)
	}

	p.Draw(app.screen)
}