Beispiel #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)
	}
}
Beispiel #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)
}
Beispiel #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)
}
Beispiel #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)
}
Beispiel #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)
}
Beispiel #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)
}
Beispiel #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)
}
Beispiel #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)
}
Beispiel #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)
}
Beispiel #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)
}
Beispiel #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)
}
Beispiel #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)
	}
}
Beispiel #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)
	}
}
Beispiel #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)
	}
}
Beispiel #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)
	}
}
Beispiel #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)
}