Skip to content

Commit

Permalink
test(exp/container/queue): add example test case for All.
Browse files Browse the repository at this point in the history
  • Loading branch information
searKing committed Nov 5, 2024
1 parent b71fd81 commit ac66474
Showing 1 changed file with 36 additions and 26 deletions.
62 changes: 36 additions & 26 deletions go/exp/container/queue/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,52 @@ import (
)

func Example() {
// Create a new list and put some numbers in it.
var l queue.Queue[int]
l.PushBack(1)
l.PushBack(2)
l.PushBack(3)
l.PushBack(4)
// Create a new queue and put some numbers in it.
var l1 queue.Queue[int]
l1.PushBack(1)
l1.PushBack(2)
l1.PushBack(3)
l1.PushBack(4)

var l2 queue.Queue[int]
l2.PushBack(5)
l2.PushBack(6)
l2.PushBack(7)
l2.PushBack(8)

l.PushBackSeq(l2.Values())

l2.TrimFrontFunc(func(e int) bool {
return e%2 == 1
})
// Iterate through list and print its contents.
for e := range l.Values() {
fmt.Println(e)
l1.PushBackSeq(l2.Values())

var s []int
if cleaned := l2.TrimFrontFunc(func(e int) bool {
if e%2 == 1 {
s = append(s, e)
return true
}
return false
}); cleaned {
fmt.Printf("l2: clean leading: %v\n", s)
}
// Iterate through queue and print its contents.
for i, e := range l1.All() {
fmt.Printf("l1[%d]: %d\n", i, e)
}
var i int
for e := range l2.Values() {
fmt.Println(e)
fmt.Printf("l2[%d]: %d\n", i, e)
i++
}

// Output:
// 1
// 2
// 3
// 4
// 5
// 6
// 7
// 8
// 6
// 7
// 8
// l2: clean leading: [5]
// l1[0]: 1
// l1[1]: 2
// l1[2]: 3
// l1[3]: 4
// l1[4]: 5
// l1[5]: 6
// l1[6]: 7
// l1[7]: 8
// l2[0]: 6
// l2[1]: 7
// l2[2]: 8
}

0 comments on commit ac66474

Please sign in to comment.