File: generic_queue_test.go

package info (click to toggle)
golang-github-cheekybits-genny 1.0.0-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 336 kB
  • sloc: makefile: 17; sh: 3
file content (87 lines) | stat: -rw-r--r-- 1,830 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package queue

import "testing"

func TestSomethingQueue(t *testing.T) {

	var item1 *Something = new(Something)
	var item2 *Something = new(Something)
	var item3 *Something = new(Something)

	q := NewSomethingQueue()

	q.Push(item1)
	if len(q.items) != 1 {
		t.Error("Push should add the item")
	}
	q.Push(item2)
	if len(q.items) != 2 {
		t.Error("Push should add the item")
	}
	q.Push(item3)
	if len(q.items) != 3 {
		t.Error("Push should add the item")
	}

	if q.Pop() != item1 {
		t.Error("Pop should return items in the order in which they were added")
	}
	if len(q.items) != 2 {
		t.Error("Pop should remove the item")
	}
	if q.Pop() != item2 {
		t.Error("Pop should return items in the order in which they were added")
	}
	if len(q.items) != 1 {
		t.Error("Pop should remove the item")
	}
	if q.Pop() != item3 {
		t.Error("Pop should return items in the order in which they were added")
	}
	if len(q.items) != 0 {
		t.Error("Pop should remove the item")
	}

}

func TestIntQueue(t *testing.T) {

	var item1 int = 1
	var item2 int = 2
	var item3 int = 3

	q := NewIntQueue()

	q.Push(item1)
	if len(q.items) != 1 {
		t.Error("Push should add the item")
	}
	q.Push(item2)
	if len(q.items) != 2 {
		t.Error("Push should add the item")
	}
	q.Push(item3)
	if len(q.items) != 3 {
		t.Error("Push should add the item")
	}

	if q.Pop() != item1 {
		t.Error("Pop should return items in the order in which they were added")
	}
	if len(q.items) != 2 {
		t.Error("Pop should remove the item")
	}
	if q.Pop() != item2 {
		t.Error("Pop should return items in the order in which they were added")
	}
	if len(q.items) != 1 {
		t.Error("Pop should remove the item")
	}
	if q.Pop() != item3 {
		t.Error("Pop should return items in the order in which they were added")
	}
	if len(q.items) != 0 {
		t.Error("Pop should remove the item")
	}

}