-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathexample_helper_test.go
More file actions
38 lines (30 loc) · 864 Bytes
/
example_helper_test.go
File metadata and controls
38 lines (30 loc) · 864 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
package queue_test
import (
"fmt"
"github.com/adrianbrad/queue"
)
// runExampleDemo exercises a queue through a shared sequence of operations
// used by ExampleLinked and ExamplePriority. The logical output differs per
// implementation (e.g. clear order for priority vs. FIFO), so each Example
// keeps its own // Output: block.
func runExampleDemo(q queue.Queue[int]) {
fmt.Println("Contains 2:", q.Contains(2))
fmt.Println("Size:", q.Size())
if err := q.Offer(3); err != nil {
fmt.Println("Offer err: ", err)
return
}
fmt.Println("Empty before clear:", q.IsEmpty())
fmt.Println("Clear:", q.Clear())
fmt.Println("Empty after clear:", q.IsEmpty())
if err := q.Offer(5); err != nil {
fmt.Println("Offer err: ", err)
return
}
elem, err := q.Get()
if err != nil {
fmt.Println("Get err: ", err)
return
}
fmt.Println("Get:", elem)
}