<commit_before>package hof

import "testing"
import "reflect"

func TestIntMap(t *testing.T) {
	var mapper func (func (int) int, []int) []int
	MakeMap(&mapper)

	in := []int{1,2,3,4,5}
	f := func(x int) int { return x*2 }
	exp := []int{2,4,6,8,10}

	out := mapper(f, in)
	if !reflect.DeepEqual(exp, out) {
		t.Fatal("expected", exp, ", got", out)
	}
}

func TestStringIntMap(t *testing.T) {
	var mapper func (func (string) int, []string) []int
	MakeMap(&mapper)

	in := []string{"try", "this", "thing"}
	f := func(x string) int { return len(x) }
	exp := []int{3, 4, 5}

	out := mapper(f, in)

	if !reflect.DeepEqual(exp, out) {
		t.Fatal("expected", exp, ", got", out)
	}
}

func TestIntStringMap(t *testing.T) {
	var mapper func (func (int) string, []int) []string
	MakeMap(&mapper)

	in := []int{1, 2, 3}
	exp := []string{"x", "xx", "xxx"}
	f := func(x int) string {
		out := ""
		for i := 0; i < x; i++ {
			out += "x"
		}
		return out
	}

	out := mapper(f, in)

	if !reflect.DeepEqual(exp, out) {
		t.Fatal("expected", exp, ", got", out)
	}
}

func TestEmptyMap(t *testing.T) {
	var mapper func (func (int) int, []int) []int
	MakeMap(&mapper)

	in := []int{}
	f := func(x int) int { return x*2 }
	exp := []int{}

	out := mapper(f, in)
	if !reflect.DeepEqual(exp, out) {
		t.Fatal("expected", exp, ", got", out)
	}
}

func TestFilter(t *testing.T) {
	var filter func (func (int) bool, []int) []int
	MakeFilter(&filter)

	in := []int{1,2,3,4,5,6,7,8,9,10}
	f := func(x int) bool { return x % 2 == 0 }
	exp := []int{2,4,6,8,10}

	out := filter(f, in)
	if !reflect.DeepEqual(exp, out) {
		t.Fatal("expected", exp, ", got", out)
	}
}

func TestReduce(t *testing.T) {
	var reduce func (func (int, int) int, []int) int
	MakeReduce(&reduce)

	in := []int{1,2,3,4,5,6,7,8,9,10}
	f := func(x, y int) int { return x + y }
	exp := 55

	out := reduce(f, in)
	if exp != out {
		t.Fatal("expected", exp, ", got", out)
	}
}

func TestReduceInit(t *testing.T) {
	var reduce func (func (int, int) int, []int, int) int
	MakeReduce(&reduce)

	in := []int{1,2,3,4,5,6,7,8,9,10}
	f := func(x, y int) int { return x + y }
	init := 45
	exp := 100

	out := reduce(f, in, init)
	if exp != out {
		t.Fatal("expected", exp, ", got", out)
	}
}<commit_msg>add a test for reduce using two types and an initial value<commit_after>package hof

import "testing"
import "reflect"

func TestIntMap(t *testing.T) {
	var mapper func (func (int) int, []int) []int
	MakeMap(&mapper)

	in := []int{1,2,3,4,5}
	f := func(x int) int { return x*2 }
	exp := []int{2,4,6,8,10}

	out := mapper(f, in)
	if !reflect.DeepEqual(exp, out) {
		t.Fatal("expected", exp, ", got", out)
	}
}

func TestStringIntMap(t *testing.T) {
	var mapper func (func (string) int, []string) []int
	MakeMap(&mapper)

	in := []string{"try", "this", "thing"}
	f := func(x string) int { return len(x) }
	exp := []int{3, 4, 5}

	out := mapper(f, in)

	if !reflect.DeepEqual(exp, out) {
		t.Fatal("expected", exp, ", got", out)
	}
}

func TestIntStringMap(t *testing.T) {
	var mapper func (func (int) string, []int) []string
	MakeMap(&mapper)

	in := []int{1, 2, 3}
	exp := []string{"x", "xx", "xxx"}
	f := func(x int) string {
		out := ""
		for i := 0; i < x; i++ {
			out += "x"
		}
		return out
	}

	out := mapper(f, in)

	if !reflect.DeepEqual(exp, out) {
		t.Fatal("expected", exp, ", got", out)
	}
}

func TestEmptyMap(t *testing.T) {
	var mapper func (func (int) int, []int) []int
	MakeMap(&mapper)

	in := []int{}
	f := func(x int) int { return x*2 }
	exp := []int{}

	out := mapper(f, in)
	if !reflect.DeepEqual(exp, out) {
		t.Fatal("expected", exp, ", got", out)
	}
}

func TestFilter(t *testing.T) {
	var filter func (func (int) bool, []int) []int
	MakeFilter(&filter)

	in := []int{1,2,3,4,5,6,7,8,9,10}
	f := func(x int) bool { return x % 2 == 0 }
	exp := []int{2,4,6,8,10}

	out := filter(f, in)
	if !reflect.DeepEqual(exp, out) {
		t.Fatal("expected", exp, ", got", out)
	}
}

func TestReduce(t *testing.T) {
	var reduce func (func (int, int) int, []int) int
	MakeReduce(&reduce)

	in := []int{1,2,3,4,5,6,7,8,9,10}
	f := func(x, y int) int { return x + y }
	exp := 55

	out := reduce(f, in)
	if exp != out {
		t.Fatal("expected", exp, ", got", out)
	}
}

func TestReduceInit(t *testing.T) {
	var reduce func (func (int, int) int, []int, int) int
	MakeReduce(&reduce)

	in := []int{1,2,3,4,5,6,7,8,9,10}
	f := func(x, y int) int { return x + y }
	init := 45
	exp := 100

	out := reduce(f, in, init)
	if exp != out {
		t.Fatal("expected", exp, ", got", out)
	}
}

func TestReduceTwoTypes(t *testing.T) {
	var reduce func (func (string, int) string, []int, string) string
	MakeReduce(&reduce)

	in := []int{0,1,2,3,4,5,6,7,8,9}
	f := func(x string, y int) string { return x + string('0' + y) }
	init := ""
	exp := "0123456789"

	out := reduce(f, in, init)
	if exp != out {
		t.Fatal("expected", exp, ", got", out)
	}
}
{'fraction_non_alphanumeric': 0.2191358024691358, 'fraction_numerical': 0.03230452674897119, 'mean_word_length': 3.7011605415860735, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1241570', 'n_tokens_mistral': 2224, 'n_tokens_neox': 2101, 'n_words': 569}