<commit_before>package lfs

import (
	"testing"

	"github.com/github/git-lfs/vendor/_nuts/github.com/technoweenie/assert"
)

func TestBatcherSizeMet(t *testing.T) {
	b := NewBatcher(2)

	for i := 0; i < 4; i++ {
		b.Add(&Downloadable{})
	}

	group := b.Next()
	assert.Equal(t, 2, len(group))

	group = b.Next()
	assert.Equal(t, 2, len(group))
}

func TestBatcherExit(t *testing.T) {
	b := NewBatcher(4)

	for i := 0; i < 2; i++ {
		b.Add(&Downloadable{})
	}

	b.Exit()

	group := b.Next()
	assert.Equal(t, 2, len(group))
}<commit_msg>lfs/batcher: introduce test cases<commit_after>package lfs

import (
	"testing"

	"github.com/github/git-lfs/vendor/_nuts/github.com/technoweenie/assert"
)

func TestBatcherSizeMet(t *testing.T) {
	assertAll([]batcherTestCase{
		{2, 4, false},
		{3, 5, false},
		{0, 0, false},
	}, t)
}

func TestBatcherExit(t *testing.T) {
	assertAll([]batcherTestCase{
		{2, 4, true},
		{3, 5, true},
		{0, 0, true},
	}, t)
}

// Type batcherTestCase specifies information about how to run a particular test
// around the type lfs.Batcher.
type batcherTestCase struct {
	BatchSize  int
	ItemCount  int
	ShouldExit bool
}

// Func Batcher makes and retunrs a lfs.Batcher according to the specification
// given in this instance of batcherTestCase. When returned, it is filled with
// the given amount of items, and has exited if it was told to.
func (b batcherTestCase) Batcher() *Batcher {
	batcher := NewBatcher(b.BatchSize)
	for i := 0; i < b.ItemCount; i++ {
		batcher.Add(&Downloadable{})
	}

	if b.ShouldExit {
		batcher.Exit()
	}

	return batcher
}

// Func Batches returns the number of individual batches expected to be
// processed by the batcher under test.
func (b batcherTestCase) Batches() int {
	if b.BatchSize == 0 {
		return 0
	}

	return b.ItemCount / b.BatchSize
}

// Func assertAll processes all test cases, throwing assertion errors if they
// fail.
func assertAll(cases []batcherTestCase, t *testing.T) {
	for _, c := range cases {
		b := c.Batcher()

		items := c.ItemCount
		for i := 0; i < c.Batches(); i++ {
			group := b.Next()
			assert.Equal(t, c.BatchSize, len(group))
			items -= c.BatchSize
		}
	}
}
{'fraction_non_alphanumeric': 0.14504881450488144, 'fraction_numerical': 0.011622501162250116, 'mean_word_length': 3.588486140724947, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6569761', 'n_tokens_mistral': 854, 'n_tokens_neox': 792, 'n_words': 228}