forked from myzhan/boomer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
taskset_test.go
92 lines (82 loc) · 1.75 KB
/
taskset_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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package boomer
import "testing"
func TestWeighingTaskSetWithSingleTask(t *testing.T) {
ts := NewWeighingTaskSet()
taskAIsRun := false
taskA := &Task{
Name: "A",
Weight: 1,
Fn: func() {
taskAIsRun = true
},
}
ts.AddTask(taskA)
if ts.GetTask(0).Name != "A" {
t.Error("Expecting A, but got ", ts.GetTask(0).Name)
}
if ts.GetTask(1) != nil {
t.Error("Out of bound, should return nil")
}
if ts.GetTask(-1) != nil {
t.Error("Out of bound, should return nil")
}
ts.Run()
if !taskAIsRun {
t.Error("Task A should be run")
}
}
func TestWeighingTaskSetWithTwoTasks(t *testing.T) {
ts := NewWeighingTaskSet()
taskA := &Task{
Name: "A",
Weight: 1,
}
taskB := &Task{
Name: "B",
Weight: 2,
}
ts.AddTask(taskA)
ts.AddTask(taskB)
if ts.GetTask(0).Name != "A" {
t.Error("Expecting A, but got ", ts.GetTask(0).Name)
}
if ts.GetTask(1).Name != "B" {
t.Error("Expecting B, but got ", ts.GetTask(1).Name)
}
}
func TestWeighingTaskSetGetTaskWithThreeTasks(t *testing.T) {
ts := NewWeighingTaskSet()
taskA := &Task{
Name: "A",
Weight: 1,
}
taskB := &Task{
Name: "B",
Weight: 2,
}
taskC := &Task{
Name: "C",
Weight: 3,
}
ts.AddTask(taskA)
ts.AddTask(taskB)
ts.AddTask(taskC)
if ts.GetTask(0).Name != "A" {
t.Error("Expecting A, but got ", ts.GetTask(0).Name)
}
if ts.GetTask(1).Name != "B" {
t.Error("Expecting B, but got ", ts.GetTask(1).Name)
}
if ts.GetTask(2).Name != "B" {
t.Error("Expecting B, but got ", ts.GetTask(2).Name)
}
if ts.GetTask(3).Name != "C" {
t.Error("Expecting C, but got ", ts.GetTask(3).Name)
}
if ts.GetTask(4).Name != "C" {
t.Error("Expecting C, but got ", ts.GetTask(4).Name)
}
if ts.GetTask(5).Name != "C" {
t.Error("Expecting C, but got ", ts.GetTask(5).Name)
}
}