<commit_before>package varis

import (
	"fmt"
	"testing"
)

func TestSum(t *testing.T) {
	elems := []float64{1.1, 2.2, 3.3}
	summa := sum(elems)
	if summa != 6.6 {
		t.Error("Sums not equal")
	}
}

func TestZeroSum(t *testing.T) {
	elems := []float64{}
	summa := sum(elems)
	if summa != 0.0 {
		t.Error("Sums not equal")
	}
}

func TestGenerateUUID(t *testing.T) {
	uuid := generate_uuid()
	if len(uuid) != 36 {
		t.Error("Len of uuid not a same:", len(uuid))
	}
}

func TestCreation(t *testing.T) {
	_ = CreateNetwork(2, 3, 1)
}

func TestDumpToJSON(t *testing.T) {
	n1 := CreateNetwork(2, 3, 1)

	dataset := Dataset{
		{[]float64{0.0, 0.0}, []float64{1.0}},
		{[]float64{1.0, 0.0}, []float64{0.0}},
		{[]float64{0.0, 1.0}, []float64{0.0}},
		{[]float64{1.0, 1.0}, []float64{1.0}},
	}

	BackPropagation(&n1, dataset, 10000)
	json := ToJSON(n1)
	n2 := FromJSON(json)

	if n1.Calculate(0.0, 0.0)[0] != n2.Calculate(0.0, 0.0)[0] {
		t.Error("Result of neural newtwork calculating not a same ")
	}

	if n1.Calculate(1.0, 0.0)[0] != n2.Calculate(1.0, 0.0)[0] {
		t.Error("Result of neural newtwork calculating not a same ")
	}

	if n1.Calculate(0.0, 1.0)[0] != n2.Calculate(0.0, 1.0)[0] {
		t.Error("Result of neural newtwork calculating not a same ")
	}

	if n1.Calculate(1.0, 1.0)[0] != n2.Calculate(1.0, 1.0)[0] {
		t.Error("Result of neural newtwork calculating not a same ")
	}
}

func BenchmarkNetwork(b *testing.B) {

	for i := 0; i < b.N; i++ {
		n := CreateNetwork(2, 3, 1)

		dataset := Dataset{
			{[]float64{0.0, 0.0}, []float64{1.0}},
			{[]float64{1.0, 0.0}, []float64{0.0}},
			{[]float64{0.0, 1.0}, []float64{0.0}},
			{[]float64{1.0, 1.0}, []float64{1.0}},
		}

		BackPropagation(&n, dataset, 10000)

		fmt.Println("After training")
		fmt.Println(0.0, 0.0, "-", n.Calculate(0.0, 0.0))
		fmt.Println(1.0, 0.0, "-", n.Calculate(1.0, 0.0))
		fmt.Println(0.0, 1.0, "-", n.Calculate(0.0, 1.0))
		fmt.Println(1.0, 1.0, "-", n.Calculate(1.0, 1.0))
	}
}

func BenchmarkLargeNetwork(b *testing.B) {

	for i := 0; i < b.N; i++ {
		n := CreateNetwork(2, 4, 8, 16, 32, 64, 64, 32, 16, 8, 4, 2, 1)

		dataset := Dataset{
			{[]float64{0.0, 0.0}, []float64{1.0}},
			{[]float64{1.0, 0.0}, []float64{0.0}},
			{[]float64{0.0, 1.0}, []float64{0.0}},
			{[]float64{1.0, 1.0}, []float64{1.0}},
		}

		BackPropagation(&n, dataset, 10)

		fmt.Println("After training")
		fmt.Println(0.0, 0.0, "-", n.Calculate(0.0, 0.0))
		fmt.Println(1.0, 0.0, "-", n.Calculate(1.0, 0.0))
		fmt.Println(0.0, 1.0, "-", n.Calculate(0.0, 1.0))
		fmt.Println(1.0, 1.0, "-", n.Calculate(1.0, 1.0))
	}
}<commit_msg>Fix tests<commit_after>package varis

import (
	"fmt"
	"testing"
)

func TestSum(t *testing.T) {
	elems := []float64{1.1, 2.2, 3.3}
	summa := sum(elems)
	if summa != 6.6 {
		t.Error("Sums not equal")
	}
}

func TestZeroSum(t *testing.T) {
	elems := []float64{}
	summa := sum(elems)
	if summa != 0.0 {
		t.Error("Sums not equal")
	}
}

func TestGenerateUUID(t *testing.T) {
	uuid := generate_uuid()
	if len(uuid) != 36 {
		t.Error("Len of uuid not a same:", len(uuid))
	}
}

func TestCreation(t *testing.T) {
	_ = CreateNetwork(2, 3, 1)
}

func TestDumpToJSON(t *testing.T) {
	n1 := CreateNetwork(2, 3, 1)

	dataset := Dataset{
		{[]float64{0.0, 0.0}, []float64{1.0}},
		{[]float64{1.0, 0.0}, []float64{0.0}},
		{[]float64{0.0, 1.0}, []float64{0.0}},
		{[]float64{1.0, 1.0}, []float64{1.0}},
	}

	BackPropagation(&n1, dataset, 10000)
	json := ToJSON(n1)
	n2 := FromJSON(json)

	if n1.Calculate([]float64{0.0, 0.0})[0] != n2.Calculate([]float64{0.0, 0.0})[0] {
		t.Error("Result of neural newtwork calculating not a same ")
	}

	if n1.Calculate([]float64{1.0, 0.0})[0] != n2.Calculate([]float64{1.0, 0.0})[0] {
		t.Error("Result of neural newtwork calculating not a same ")
	}

	if n1.Calculate([]float64{0.0, 1.0})[0] != n2.Calculate([]float64{0.0, 1.0})[0] {
		t.Error("Result of neural newtwork calculating not a same ")
	}

	if n1.Calculate([]float64{1.0, 1.0})[0] != n2.Calculate([]float64{1.0, 1.0})[0] {
		t.Error("Result of neural newtwork calculating not a same ")
	}
}

func BenchmarkNetwork(b *testing.B) {

	for i := 0; i < b.N; i++ {
		n := CreateNetwork(2, 3, 1)

		dataset := Dataset{
			{[]float64{0.0, 0.0}, []float64{1.0}},
			{[]float64{1.0, 0.0}, []float64{0.0}},
			{[]float64{0.0, 1.0}, []float64{0.0}},
			{[]float64{1.0, 1.0}, []float64{1.0}},
		}

		BackPropagation(&n, dataset, 10000)

		fmt.Println("After training")
		fmt.Println(0.0, 0.0, "-", n.Calculate([]float64{0.0, 0.0}))
		fmt.Println(1.0, 0.0, "-", n.Calculate([]float64{1.0, 0.0}))
		fmt.Println(0.0, 1.0, "-", n.Calculate([]float64{0.0, 1.0}))
		fmt.Println(1.0, 1.0, "-", n.Calculate([]float64{1.0, 1.0}))
	}
}

func BenchmarkLargeNetwork(b *testing.B) {

	for i := 0; i < b.N; i++ {
		n := CreateNetwork(2, 4, 8, 16, 32, 64, 64, 32, 16, 8, 4, 2, 1)

		dataset := Dataset{
			{[]float64{0.0, 0.0}, []float64{1.0}},
			{[]float64{1.0, 0.0}, []float64{0.0}},
			{[]float64{0.0, 1.0}, []float64{0.0}},
			{[]float64{1.0, 1.0}, []float64{1.0}},
		}

		BackPropagation(&n, dataset, 10)

		fmt.Println("After training")
		fmt.Println(0.0, 0.0, "-", n.Calculate([]float64{0.0, 0.0}))
		fmt.Println(1.0, 0.0, "-", n.Calculate([]float64{1.0, 0.0}))
		fmt.Println(0.0, 1.0, "-", n.Calculate([]float64{0.0, 1.0}))
		fmt.Println(1.0, 1.0, "-", n.Calculate([]float64{1.0, 1.0}))
	}
}
{'fraction_non_alphanumeric': 0.2518712574850299, 'fraction_numerical': 0.11601796407185629, 'mean_word_length': 3.5296610169491527, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '600318', 'n_tokens_mistral': 2892, 'n_tokens_neox': 2510, 'n_words': 481}