<commit_before>package isitrandom

import (
	"io"
	"testing"
)

type test interface {
	next(b byte)
	p() float64
}

func buildTest(t test) func(c chan byte) float64 {
	return func(c chan byte) float64 {
		for b := range c {
			t.next(b)
		}
		return t.p()
	}
}

func buildIOReaderTest(t test) func(r io.Reader) float64 {
	return func(r io.Reader) float64 {
		p := make([]byte, 1)
		var err error
		for err != nil {
			_, err = r.Read(p)
			t.next(p[0])
		}
		return t.p()
	}
}

var tests = []struct {
	name string
	t    test
}{
	{"frequency", &frequency{}},
	// {"serial", &serial{}},
}

// TestRNG tests all the tests available and fails if any p-value is too low.
// This runs all tests in paraellel. That might not be good for reading.........
func TestRNG(t *testing.T, rng io.Reader) {
	c := readerToChannel(rng)
	s := split(c, len(tests))
	for i, a := range tests {
		rngt := buildTest(a.t)
		t.Run(a.name, func(t *testing.T) {
			p := rngt(s[i])
			if p < 0.05 {
				t.Errorf("Fail %s: expected p-value > 0.05, got %f", a.name, p)
			}
		})
	}
}

type channelReader struct {<commit_msg>tests fail with multiple tests (goroutines deadlock)<commit_after>package isitrandom

import (
	"io"
	"testing"
)

type test interface {
	next(b byte)
	p() float64
}

func buildTest(t test) func(c chan byte) float64 {
	return func(c chan byte) float64 {
		for b := range c {
			t.next(b)
		}
		return t.p()
	}
}

func buildIOReaderTest(t test) func(r io.Reader) float64 {
	return func(r io.Reader) float64 {
		p := make([]byte, 1)
		var err error
		for err != nil {
			_, err = r.Read(p)
			t.next(p[0])
		}
		return t.p()
	}
}

var tests = []struct {
	name string
	t    test
}{
	{"frequency", &frequency{}},
	{"serial", &serial{}},
}

// TestRNG tests all the tests available and fails if any p-value is too low.
// This runs all tests in paraellel. That might not be good for reading.........
func TestRNG(t *testing.T, rng io.Reader) {
	c := readerToChannel(rng)
	s := split(c, len(tests))
	for i, a := range tests {
		rngt := buildTest(a.t)
		t.Run(a.name, func(t *testing.T) {
			p := rngt(s[i])
			if p < 0.05 {
				t.Errorf("Fail %s: expected p-value > 0.05, got %f", a.name, p)
			}
		})
	}
}

type channelReader struct {
{'fraction_non_alphanumeric': 0.162016201620162, 'fraction_numerical': 0.016201620162016202, 'mean_word_length': 2.9555160142348753, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4237258', 'n_tokens_mistral': 963, 'n_tokens_neox': 883, 'n_words': 266}