-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstack_test.go
More file actions
46 lines (43 loc) · 990 Bytes
/
stack_test.go
File metadata and controls
46 lines (43 loc) · 990 Bytes
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
package main
import (
"net/url"
"testing"
)
func pushAll(s *Stack, data []*url.URL) {
for _, x := range data {
s.Push(Site{URL: x})
}
}
func TestStack(t *testing.T) {
testData := []string{
"google.com",
"helpme.com",
"github.com",
"other",
"testme:8080",
}
urls := make([]*url.URL, len(testData))
for x := range testData {
urls[x], _ = url.Parse(testData[x])
}
s := NewStack(2)
if want, got := 0, s.Len(); got != want {
t.Errorf("Wanted %v, got %v", want, got)
}
pushAll(s, urls)
if want, got := 2, s.Len(); got != want {
t.Errorf("Wanted %v, got %v", want, got)
}
if want, got := urls[4], s.Pop().URL; got != want {
t.Errorf("Wanted %v, got %v", want, got)
}
if want, got := urls[3], s.Pop().URL; got != want {
t.Errorf("Wanted %v, got %v", want, got)
}
if want, got := (*Site)(nil), s.Pop(); got != want {
t.Errorf("Wanted %v, got %v", want, got)
}
if want, got := 0, s.Len(); got != want {
t.Errorf("Wanted %v, got %v", want, got)
}
}