-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue_test.go
44 lines (34 loc) · 870 Bytes
/
queue_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
package algo
import (
"bufio"
"bytes"
"testing"
)
func TestPrintManager(t *testing.T) {
input := []string{"First Document", "Second Document", "Third Document"}
printer := newPrintMgr()
for _, doc := range input {
printer.queuePrintJob(doc)
if top := printer.queue.peak(); top != input[0] {
t.Errorf("exp top %s, got %s", input[0], top)
}
endOfLine := printer.queue.data[len(printer.queue.data)-1]
if end := endOfLine; end != doc {
t.Errorf("exp end of queue %s, got %s", endOfLine, end)
}
}
var out bytes.Buffer
printer.run(&out)
scanner := bufio.NewScanner(&out)
idx := 0
for scanner.Scan() {
if scanner.Text() != input[idx] {
t.Errorf("Exp output %s, got %s", input[idx], scanner.Text())
}
idx++
}
queueLen := len(printer.queue.data)
if queueLen != 0 {
t.Errorf("Exp empyt print quue, got len %d", queueLen)
}
}