<commit_before>package log

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestPercentageTaskCalculuatesPercentages(t *testing.T) {
	task := NewPercentageTask("example", 10)

	assert.Equal(t, "example:   0% (0/10)", <-task.Updates())

	n := task.Count(3)
	assert.EqualValues(t, 3, n)

	assert.Equal(t, "example:  30% (3/10)", <-task.Updates())
}

func TestPercentageTaskCallsDoneWhenComplete(t *testing.T) {
	task := NewPercentageTask("example", 10)

	select {
	case v, ok := <-task.Updates():
		if ok {
			assert.Equal(t, "example:   0% (0/10)", v)
		} else {
			t.Fatal("expected channel to be open")
		}
	default:
	}

	assert.EqualValues(t, 10, task.Count(10))
	assert.Equal(t, "example: 100% (10/10)", <-task.Updates())

	if _, ok := <-task.Updates(); ok {
		t.Fatalf("expected channel to be closed")
	}
}
<commit_msg>git/githistory/log: test PercentageTask Throttle()-d<commit_after>package log

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestPercentageTaskCalculuatesPercentages(t *testing.T) {
	task := NewPercentageTask("example", 10)

	assert.Equal(t, "example:   0% (0/10)", <-task.Updates())

	n := task.Count(3)
	assert.EqualValues(t, 3, n)

	assert.Equal(t, "example:  30% (3/10)", <-task.Updates())
}

func TestPercentageTaskCallsDoneWhenComplete(t *testing.T) {
	task := NewPercentageTask("example", 10)

	select {
	case v, ok := <-task.Updates():
		if ok {
			assert.Equal(t, "example:   0% (0/10)", v)
		} else {
			t.Fatal("expected channel to be open")
		}
	default:
	}

	assert.EqualValues(t, 10, task.Count(10))
	assert.Equal(t, "example: 100% (10/10)", <-task.Updates())

	if _, ok := <-task.Updates(); ok {
		t.Fatalf("expected channel to be closed")
	}
}

func TestPercentageTaskIsThrottled(t *testing.T) {
	task := NewPercentageTask("example", 10)

	throttled := task.Throttled()

	assert.True(t, throttled,
		"git/githistory/log: expected *PercentageTask to be Throttle()-d")
}

{'fraction_non_alphanumeric': 0.1806981519507187, 'fraction_numerical': 0.03182751540041068, 'mean_word_length': 4.310626702997276, 'pattern_counts': {'":': 0, '<': 13, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4615156', 'n_tokens_mistral': 827, 'n_tokens_neox': 746, 'n_words': 155}