make Item.Val public

This commit is contained in:
Gregory 2021-11-01 22:54:14 +02:00
parent febcffda68
commit 6be93258a4
2 changed files with 5 additions and 5 deletions

View file

@ -5,7 +5,7 @@
package queue package queue
type Item struct { type Item struct {
val interface{} Val interface{}
} }
// This type represents request for content from queue. // This type represents request for content from queue.

View file

@ -10,7 +10,7 @@ import (
func TestPut(t *testing.T) { func TestPut(t *testing.T) {
q := NewQueue() q := NewQueue()
q.Put(Item{1}) q.Put(Item{1})
if q.Get().val.(int) != 1 { if q.Get().Val.(int) != 1 {
t.Fatal("wrong item in queue") t.Fatal("wrong item in queue")
} }
} }
@ -19,7 +19,7 @@ func TestPutMultiple(t *testing.T) {
q := NewQueue() q := NewQueue()
q.Put(Item{1}) q.Put(Item{1})
q.Put(Item{2}) q.Put(Item{2})
first, second := q.Get().val.(int), q.Get().val.(int) first, second := q.Get().Val.(int), q.Get().Val.(int)
if first != 1 || second != 2 { if first != 1 || second != 2 {
t.Fatal("wrong item in queue or wrong order") t.Fatal("wrong item in queue or wrong order")
} }
@ -66,7 +66,7 @@ func TestGetMany(t *testing.T) {
select { select {
case res := <-result2(): case res := <-result2():
third, fourth := res[0].val.(int), res[1].val.(int) third, fourth := res[0].Val.(int), res[1].Val.(int)
if third != 3 || fourth != 4 { if third != 3 || fourth != 4 {
t.Fatal("wrong item in queue or wrong order") t.Fatal("wrong item in queue or wrong order")
} }
@ -92,7 +92,7 @@ func TestConcurrent(t *testing.T) {
for i := 0; i < 1000; i++ { for i := 0; i < 1000; i++ {
go func() { go func() {
defer wg.Done() defer wg.Done()
sum += q.Get().val.(int) sum += q.Get().Val.(int)
}() }()
} }