Exemplo n.º 1
0
func TestFirstOnlyCloseError(t *testing.T) {
	stream := closeErrorStream{Stream: functional.Count()}
	var value int
	if output := FirstOnly(stream, emptyError, &value); output != closeError {
		t.Errorf("Expected closeError, got %v", output)
	}
}
Exemplo n.º 2
0
func TestGrowingBufferSameSize(t *testing.T) {
	stream := &closeChecker{Stream: functional.Slice(functional.Count(), 0, 5)}
	b := NewGrowingBuffer(intSlice, 5)
	b.Consume(stream)
	verifyClosed(t, stream)
	verifyFetched(t, b, 0, 5)
}
Exemplo n.º 3
0
func TestBufferSmall(t *testing.T) {
	stream := &closeChecker{Stream: functional.Slice(functional.Count(), 0, 6)}
	b := NewBuffer(make([]int, 5))
	b.Consume(stream)
	verifyClosed(t, stream)
	verifyFetched(t, b, 0, 5)
}
Exemplo n.º 4
0
func TestPageBufferParitalFirst(t *testing.T) {
	stream := &closeChecker{
		Stream: functional.Slice(functional.Count(), 0, 1)}
	pb := NewPageBuffer(make([]int, 6), 0)
	pb.Consume(stream)
	verifyPageFetched(t, pb, 0, 1, 0, true)
}
Exemplo n.º 5
0
func TestPtrBuffer(t *testing.T) {
	stream := &closeChecker{Stream: functional.Count()}
	b := newPtrBuffer(5)
	b.Consume(stream)
	verifyClosed(t, stream)
	verifyPtrFetched(t, b, 0, 5)
}
Exemplo n.º 6
0
func TestPageBufferEmptyThirdTooHigh(t *testing.T) {
	stream := &closeChecker{
		Stream: functional.Slice(functional.Count(), 0, 6)}
	pb := NewPageBuffer(make([]int, 6), 3)
	pb.Consume(stream)
	verifyPageFetched(t, pb, 3, 6, 1, true)
}
Exemplo n.º 7
0
func TestPageBufferNegativePage(t *testing.T) {
	stream := &closeChecker{Stream: functional.Count()}
	pb := NewPageBuffer(make([]int, 6), -1)
	pb.Consume(stream)
	verifyClosed(t, stream)
	verifyPageFetched(t, pb, 0, 3, 0, false)
}
Exemplo n.º 8
0
func TestPageBufferThirdPage(t *testing.T) {
	stream := &closeChecker{Stream: functional.Count()}
	pb := NewPageBuffer(make([]int, 6), 2)
	pb.Consume(stream)
	verifyClosed(t, stream)
	verifyPageFetched(t, pb, 6, 9, 2, false)
}
Exemplo n.º 9
0
func TestPtrPageBuffer(t *testing.T) {
	stream := &closeChecker{Stream: functional.Count()}
	pb := newPtrPageBuffer(6, 0)
	pb.Consume(stream)
	verifyClosed(t, stream)
	verifyPtrPageFetched(t, pb, 0, 3, 0, false)
}
Exemplo n.º 10
0
func TestPtrGrowingBuffer(t *testing.T) {
	stream := &closeChecker{Stream: functional.Slice(functional.Count(), 0, 6)}
	b := NewPtrGrowingBuffer(intPtrSlice, 5, nil)
	var c ErrorReportingConsumer = b
	c.Consume(stream)
	verifyClosed(t, stream)
	verifyPtrFetched(t, b, 0, 6)
}
Exemplo n.º 11
0
func TestPageBufferFullSecond(t *testing.T) {
	stream := &closeChecker{
		Stream: functional.Slice(functional.Count(), 0, 6)}
	pb := NewPageBuffer(make([]int, 6), 1)
	pb.Consume(stream)
	verifyClosed(t, stream)
	verifyPageFetched(t, pb, 3, 6, 1, true)
}
Exemplo n.º 12
0
func TestGrowingBufferSmall(t *testing.T) {
	stream := &closeChecker{Stream: functional.Slice(functional.Count(), 0, 6)}
	b := NewGrowingBuffer(intSlice, 5)
	b.Consume(stream)
	verifyClosed(t, stream)
	verifyFetched(t, b, 0, 6)
	if actual := cap(b.Values().([]int)); actual != 10 {
		t.Errorf("Expected capacit of 10, got %v", actual)
	}
}
Exemplo n.º 13
0
func TestPtrGrowingBuffer2(t *testing.T) {
	stream := &closeChecker{Stream: functional.Slice(functional.Count(), 0, 6)}
	b := NewPtrGrowingBuffer(
		intPtrSlice, 1, func() interface{} { return new(int) })
	b.Consume(stream)
	verifyClosed(t, stream)
	verifyPtrFetched(t, b, 0, 6)
	if actual := cap(b.Values().([]*int)); actual != 8 {
		t.Errorf("Expected capacit of 8, got %v", actual)
	}
}
Exemplo n.º 14
0
func TestCompose(t *testing.T) {
	consumer1 := errorReportingConsumerForTesting{}
	consumer2 := errorReportingConsumerForTesting{}
	errorReportingConsumer := Compose(
		new(int), nil, &consumer1, &consumer2)
	errorReportingConsumer.Consume(
		closeErrorStream{functional.Slice(functional.Count(), 0, 5)})
	if err := errorReportingConsumer.Error(); err != closeError {
		t.Errorf("Expected closeError, got %v", err)
	}
	if output := consumer1.count; output != 5 {
		t.Errorf("Expected 5, got %v", output)
	}
	if output := consumer2.count; output != 5 {
		t.Errorf("Expected 5, got %v", output)
	}
}
Exemplo n.º 15
0
func TestCompose2(t *testing.T) {
	consumer1 := errorReportingConsumerForTesting{}
	consumer2 := errorReportingConsumerForTesting{e: consumerError}
	errorReportingConsumer := Compose(
		new(int),
		nil,
		&consumer1,
		Modify(
			&consumer2,
			func(s functional.Stream) functional.Stream {
				return functional.Slice(s, 0, 2)
			}))
	errorReportingConsumer.Consume(
		closeErrorStream{functional.Slice(functional.Count(), 0, 5)})
	if err := errorReportingConsumer.Error(); err != consumerError {
		t.Errorf("Expected consumerError, got %v", err)
	}
	if output := consumer1.count; output != 5 {
		t.Errorf("Expected 5, got %v", output)
	}
	if output := consumer2.count; output != 2 {
		t.Errorf("Expected 2, got %v", output)
	}
}
Exemplo n.º 16
0
func TestBufferBig(t *testing.T) {
	stream := functional.Slice(functional.Count(), 0, 4)
	b := NewBuffer(make([]int, 5))
	b.Consume(stream)
	verifyFetched(t, b, 0, 4)
}