Exemplo n.º 1
0
func TestAppendTo2(t *testing.T) {
	values := []int{1, 2}
	c := AppendTo(&values)
	stream := functional.Slice(functional.Count(), 3, 7)
	doConsume(t, c, stream, nil)
	stream = functional.Slice(functional.Count(), 7, 11)
	doConsume(t, c, stream, nil)
	verifyValues(t, values, 1, 11)
	if actual := cap(values); actual != 11 {
		t.Errorf("Expected capacity of 11, got %v", actual)
	}
}
Exemplo n.º 2
0
func TestGrowingBufferBig(t *testing.T) {
	stream := functional.Slice(functional.Count(), 0, 4)
	b := NewGrowingBuffer(intSlice, 5)
	doConsume(t, b, stream, nil)
	verifyFetched(t, b, 0, 4)
	if actual := cap(b.Values().([]int)); actual != 6 {
		t.Errorf("Expected capacity of 6, got %v", actual)
	}
}
Exemplo n.º 3
0
func TestAppendTo(t *testing.T) {
	var values []int
	stream := functional.Slice(functional.Count(), 0, 7)
	doConsume(t, AppendTo(&values), stream, nil)
	verifyValues(t, values, 0, 7)
	if actual := cap(values); actual != 15 {
		t.Errorf("Expected capacity of 15, got %v", actual)
	}
}
Exemplo n.º 4
0
func TestPtrGrowingBuffer2(t *testing.T) {
	stream := functional.Slice(functional.Count(), 0, 6)
	b := NewPtrGrowingBuffer(intPtrSlice, 0, intCreater)
	doConsume(t, b, stream, nil)
	verifyPtrFetched(t, b, 0, 6)
	if actual := cap(b.Values().([]*int)); actual != 7 {
		t.Errorf("Expected capacity of 7, got %v", actual)
	}
}
Exemplo n.º 5
0
func ExampleAppendTo() {
	values := []int{5}
	stream := functional.Slice(functional.Count(), 0, 2)
	AppendTo(&values).Consume(stream)
	for i := range values {
		fmt.Println(values[i])
	}
	// Output:
	// 5
	// 0
	// 1
}
Exemplo n.º 6
0
func ExampleAppendPtrsTo() {
	var values []*int
	stream := functional.Slice(functional.Count(), 0, 3)
	AppendPtrsTo(&values, nil).Consume(stream)
	for i := range values {
		fmt.Println(*values[i])
	}
	// Output:
	// 0
	// 1
	// 2
}
Exemplo n.º 7
0
func TestAppendPtrsTo2(t *testing.T) {
	var values []*int
	stream := functional.Slice(functional.Count(), 0, 3)
	var x int
	// Our creater returns a pointer to the same variable.
	creater := func() interface{} {
		return &x
	}
	doConsume(t, AppendPtrsTo(&values, creater), stream, nil)
	// We should have a slice of length 3 with all pointers being the same.
	if len(values) != 3 || values[0] != values[1] || values[0] != values[2] {
		t.Error("Failure")
	}
}
Exemplo n.º 8
0
func TestPtrGrowingBufferPointersPreserved(t *testing.T) {
	stream := functional.Slice(functional.Count(), 0, 3)
	b := NewPtrGrowingBuffer(intPtrSlice, 4, nil)
	b.Consume(stream)
	values := b.Values().([]*int)
	zeroToThree := make([]*int, len(values))
	copy(zeroToThree, values)

	stream = functional.Slice(functional.Count(), 10, 15)
	b.Consume(stream)
	values = b.Values().([]*int)
	tenToFifteen := make([]*int, len(values))
	copy(tenToFifteen, values)

	stream = functional.Slice(functional.Count(), 20, 22)
	b.Consume(stream)
	values = b.Values().([]*int)
	twentyToTwentyTwo := make([]*int, len(values))
	copy(twentyToTwentyTwo, values)

	verifyPtrValues(t, zeroToThree, 0, 3)
	verifyPtrValues(t, tenToFifteen, 10, 15)
	verifyPtrValues(t, twentyToTwentyTwo, 20, 22)
}
Exemplo n.º 9
0
func TestStartAtUntilNested(t *testing.T) {
	hourly := recurring.OnTheHour()
	thanksgiving9 := time.Date(2013, 11, 28, 9, 0, 0, 0, time.Local)
	thanksgiving10 := time.Date(2013, 11, 28, 10, 0, 0, 0, time.Local)
	thanksgiving12 := time.Date(2013, 11, 28, 12, 0, 0, 0, time.Local)
	thanksgiving13 := time.Date(2013, 11, 28, 13, 0, 0, 0, time.Local)
	thanksgiving10and11 := recurring.Until(
		recurring.StartAt(
			recurring.Until(
				recurring.StartAt(hourly, thanksgiving10),
				thanksgiving13),
			thanksgiving9),
		thanksgiving12)
	verifyTimes(
		t,
		thanksgiving10and11.ForTime(kNow),
		time.Date(2013, 11, 28, 10, 0, 0, 0, time.Local),
		time.Date(2013, 11, 28, 11, 0, 0, 0, time.Local))
	thanksgiving10and11again := recurring.Until(
		recurring.StartAt(
			recurring.Until(
				recurring.StartAt(hourly, thanksgiving9),
				thanksgiving12),
			thanksgiving10),
		thanksgiving13)
	verifyTimes(
		t,
		thanksgiving10and11again.ForTime(kNow),
		time.Date(2013, 11, 28, 10, 0, 0, 0, time.Local),
		time.Date(2013, 11, 28, 11, 0, 0, 0, time.Local))
	thanksgiving9On := recurring.StartAt(hourly, thanksgiving9)
	verifyTimes(
		t,
		functional.Slice(thanksgiving9On.ForTime(kNow), 0, 3),
		time.Date(2013, 11, 28, 9, 0, 0, 0, time.Local),
		time.Date(2013, 11, 28, 10, 0, 0, 0, time.Local),
		time.Date(2013, 11, 28, 11, 0, 0, 0, time.Local))
}
Exemplo n.º 10
0
func TestBufferBig(t *testing.T) {
	stream := functional.Slice(functional.Count(), 0, 4)
	b := NewBuffer(make([]int, 5))
	doConsume(t, b, stream, nil)
	verifyFetched(t, b, 0, 4)
}
Exemplo n.º 11
0
func TestPageBufferParitalFirst(t *testing.T) {
	stream := functional.Slice(functional.Count(), 0, 1)
	pb := NewPageBuffer(make([]int, 6), 0)
	doConsume(t, pb, stream, nil)
	verifyPageFetched(t, pb, 0, 1, 0, true)
}
Exemplo n.º 12
0
func TestPageBufferFullSecond(t *testing.T) {
	stream := functional.Slice(functional.Count(), 0, 6)
	pb := NewPageBuffer(make([]int, 6), 1)
	doConsume(t, pb, stream, nil)
	verifyPageFetched(t, pb, 3, 6, 1, true)
}
Exemplo n.º 13
0
func TestPageBufferEmptyThirdTooHigh(t *testing.T) {
	stream := functional.Slice(functional.Count(), 0, 6)
	pb := NewPageBuffer(make([]int, 6), 3)
	doConsume(t, pb, stream, nil)
	verifyPageFetched(t, pb, 3, 6, 1, true)
}
Exemplo n.º 14
0
func TestPageBufferParitalThirdToHigh(t *testing.T) {
	stream := functional.Slice(functional.Count(), 0, 7)
	pb := NewPageBuffer(make([]int, 6), 3)
	doConsume(t, pb, stream, nil)
	verifyPageFetched(t, pb, 6, 7, 2, true)
}
Exemplo n.º 15
0
func TestPtrGrowingBuffer(t *testing.T) {
	stream := functional.Slice(functional.Count(), 0, 6)
	b := NewPtrGrowingBuffer(intPtrSlice, 5, nil)
	doConsume(t, b, stream, nil)
	verifyPtrFetched(t, b, 0, 6)
}
Exemplo n.º 16
0
func TestAppendPtrsTo(t *testing.T) {
	var values []*int
	stream := functional.Slice(functional.Count(), 0, 7)
	doConsume(t, AppendPtrsTo(&values, nil), stream, nil)
	verifyPtrValues(t, values, 0, 7)
}