<commit_before>package algorithms

import (
	"reflect"
	"testing"
)

type test struct {
	value  []int
	result []int
}

var tests = []test{
	{[]int{0, 8, 9, 2, 1, 6, 5, 10, 3, 4, 7}, []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}},
	{[]int{82, 29, 21, 61, 18, 4, 8, 10, 1, 6, 81, 95}, []int{1, 4, 6, 8, 10, 18, 21, 29, 61, 81, 82, 95}},
	{[]int{100, 2810, 28, 1903, 839, 282}, []int{28, 100, 282, 839, 1903, 2810}},
	{[]int{-8, -19, -20, 2, 0, 5, 12, 22}, []int{-20, -19, -8, 0, 2, 5, 12, 22}},
}

func TestBubbleSort(t *testing.T) {
	for _, pair := range tests {
		arr := BubbleSort(pair.value)
		if !reflect.DeepEqual(arr, pair.result) {
			t.Error(
				"for", pair.value,
				"expected", pair.result,
				"got", arr,
			)
		}
	}
}

func TestInsertionSort(t *testing.T) {
	for _, pair := range tests {
		v := InsertionSort(pair.value)
		if !reflect.DeepEqual(v, pair.result) {
			t.Error(
				"for", pair.value,
				"expected", pair.result,
				"got", v,
			)
		}
	}
}<commit_msg>Add benchmarks to bubble and insertion sort<commit_after>package algorithms

import (
	"math/rand"
	"reflect"
	"testing"
)

type test struct {
	value  []int
	result []int
}

var tests = []test{
	{[]int{0, 8, 9, 2, 1, 6, 5, 10, 3, 4, 7}, []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}},
	{[]int{82, 29, 21, 61, 18, 4, 8, 10, 1, 6, 81, 95}, []int{1, 4, 6, 8, 10, 18, 21, 29, 61, 81, 82, 95}},
	{[]int{100, 2810, 28, 1903, 839, 282}, []int{28, 100, 282, 839, 1903, 2810}},
	{[]int{-8, -19, -20, 2, 0, 5, 12, 22}, []int{-20, -19, -8, 0, 2, 5, 12, 22}},
}

func TestBubbleSort(t *testing.T) {
	for _, pair := range tests {
		arr := BubbleSort(pair.value)
		if !reflect.DeepEqual(arr, pair.result) {
			t.Error(
				"for", pair.value,
				"expected", pair.result,
				"got", arr,
			)
		}
	}
}

func TestInsertionSort(t *testing.T) {
	for _, pair := range tests {
		v := InsertionSort(pair.value)
		if !reflect.DeepEqual(v, pair.result) {
			t.Error(
				"for", pair.value,
				"expected", pair.result,
				"got", v,
			)
		}
	}
}

// $ go test -bench=.
var hundred = generateRandomSlice(100)
var thousand = generateRandomSlice(1000)
var tenThousand = generateRandomSlice(10000)

func generateRandomSlice(count int) []int {
	var v = []int{}
	for i := 0; i < count; i++ {
		v = append(v, rand.Int())
	}
	return v
}

func BenchmarkBubbleSortHundred(b *testing.B) {
	for i := 0; i < b.N; i++ {
		BubbleSort(hundred)
	}
}

func BenchmarkBubbleSortThousand(b *testing.B) {
	for i := 0; i < b.N; i++ {
		BubbleSort(thousand)
	}
}

func BenchmarkBubbleSortTenThousand(b *testing.B) {
	for i := 0; i < b.N; i++ {
		BubbleSort(tenThousand)
	}
}

func BenchmarkInsertionSortHundred(b *testing.B) {
	for i := 0; i < b.N; i++ {
		InsertionSort(hundred)
	}
}

func BenchmarkInsertionSortThousand(b *testing.B) {
	for i := 0; i < b.N; i++ {
		InsertionSort(thousand)
	}
}

func BenchmarkInsertionSortTenThousand(b *testing.B) {
	for i := 0; i < b.N; i++ {
		InsertionSort(tenThousand)
	}
}
{'fraction_non_alphanumeric': 0.20333787465940054, 'fraction_numerical': 0.0923024523160763, 'mean_word_length': 3.3191176470588237, 'pattern_counts': {'":': 0, '<': 10, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3940203', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1269, 'n_words': 351}