@@ -30,7 +30,7 @@ func collectBatches[T any](out <-chan []T) [][]T {
3030
3131func TestBatchingFlushOnTimeout (t * testing.T ) {
3232 in := sendIntsToChan ([]int {1 , 2 }, 150 * time .Millisecond ) // delay > timeout
33- out := batchan .New (in , 5 , batchan .WithTimeout (100 * time .Millisecond ))
33+ out := batchan .New (in , 5 , batchan.WithTimeout [ int ] (100 * time .Millisecond ))
3434
3535 got := collectBatches (out )
3636
@@ -43,7 +43,7 @@ func TestBatchingFlushOnTimeout(t *testing.T) {
4343
4444func TestBatchingFlushOnSizeOrTimeout (t * testing.T ) {
4545 in := sendIntsToChan ([]int {1 , 2 , 3 , 4 }, 50 * time .Millisecond )
46- out := batchan .New (in , 2 , batchan .WithTimeout (200 * time .Millisecond ))
46+ out := batchan .New (in , 2 , batchan.WithTimeout [ int ] (200 * time .Millisecond ))
4747
4848 got := collectBatches (out )
4949 expected := [][]int {{1 , 2 }, {3 , 4 }}
@@ -55,7 +55,7 @@ func TestBatchingFlushOnSizeOrTimeout(t *testing.T) {
5555
5656func TestFlushTimeoutMultiple (t * testing.T ) {
5757 in := sendIntsToChan ([]int {1 , 2 , 3 }, 300 * time .Millisecond )
58- out := batchan .New (in , 10 , batchan .WithTimeout (200 * time .Millisecond )) // small timeout, large batch size
58+ out := batchan .New (in , 10 , batchan.WithTimeout [ int ] (200 * time .Millisecond )) // small timeout, large batch size
5959
6060 got := collectBatches (out )
6161 expected := [][]int {{1 }, {2 }, {3 }}
@@ -77,7 +77,7 @@ func TestTimeoutResetsAfterFlush(t *testing.T) {
7777 in <- 3
7878 }()
7979
80- out := batchan .New (in , 2 , batchan .WithTimeout (100 * time .Millisecond ))
80+ out := batchan .New (in , 2 , batchan.WithTimeout [ int ] (100 * time .Millisecond ))
8181
8282 got := collectBatches (out )
8383 expected := [][]int {{1 }, {2 }, {3 }}
@@ -146,6 +146,18 @@ func TestBatchSizeLargerThanInput(t *testing.T) {
146146 }
147147}
148148
149+ func TestSplitFunc (t * testing.T ) {
150+ in := sendIntsToChan ([]int {1 , 2 , 3 , 5 , 6 }, time .Microsecond )
151+ out := batchan .New (in , 5 , batchan .WithSplitFunc (func (i1 , i2 int ) bool { return i2 - i1 > 1 }))
152+
153+ expected := [][]int {{1 , 2 , 3 }, {5 , 6 }}
154+ got := collectBatches (out )
155+
156+ if ! reflect .DeepEqual (got , expected ) {
157+ t .Errorf ("Expected %v, got %v" , expected , got )
158+ }
159+ }
160+
149161// Optional: Test that the output channel closes properly
150162func TestOutputChannelClosure (t * testing.T ) {
151163 in := sendIntsToChan ([]int {1 , 2 , 3 }, time .Microsecond )
0 commit comments