-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender_test.go
41 lines (38 loc) · 967 Bytes
/
render_test.go
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
package main
import (
"testing"
"time"
)
func TestProgressBar(t *testing.T) {
var tests = []struct {
percent int
width int
want string
}{
{1, 10, "[ ]"},
{10, 10, "[= ]"},
{50, 10, "[===== ]"},
{80, 10, "[======== ]"},
{100, 10, "[==========]"},
}
for _, test := range tests {
if got := ProgressBar(test.percent, test.width); got != test.want {
t.Errorf("ProgressBar(%d, %d) = %v, want %v", test.percent, test.width, got, test.want)
}
}
}
func TestTimeDisplay(t *testing.T) {
var tests = []struct {
currentTime time.Duration
totalTime time.Duration
want string
}{
{time.Second, 10 * time.Second, "1s / 10s"},
{30 * time.Minute, 500 * time.Minute, "30m0s / 8h20m0s"},
}
for _, test := range tests {
if got := TimeDisplay(test.currentTime, test.totalTime); got != test.want {
t.Errorf("TimeDisplay(%d, %d) = %v, want %v", test.currentTime, test.totalTime, got, test.want)
}
}
}