<commit_before>package goroots

import "math"
import "testing"
//import "testing/quick" // want to use Check; unsure if it'll work with current SolveBisection for small epsilon

// Does SolveBisection correctly solve a simple linear function?
func TestLinear(t *testing.T) {
	makeLinear := func(root float64) func(float64) float64 {
		return func(x float64) float64 { return root - x }
	}
	checker := func(root float64) bool {
		scale := math.Fabs(root)
		epsilon := scale / 1e-5
		val, err := SolveBisection(makeLinear(root), root - scale, root + scale, epsilon)
		if err != nil {
			return false
		}
		return val == root
	}
	if !(checker(5) && checker(100) && checker(1e-5)) {
		t.FailNow()
	}
}

// Does BisectionFullPrecision correctly solve a simple linear function?
func TestLinearFullPrecision(t *testing.T) {
	macheps := math.Pow(2.0, -53.0)
	makeLinear := func(root float64) func(float64) float64 {
		return func(x float64) float64 { return root - x }
	}
	checker := func(root float64) bool {
		scale := math.Fabs(root)
		val, err := BisectionFullPrecision(makeLinear(root), root - scale, root + scale)
		if err != nil {
			return false
		}
		return val - root <= macheps
	}
	if !(checker(5) && checker(100) && checker(1e-5)) {
		t.FailNow()
	}
}<commit_msg>changed TestLinearFullPrecision to use quick.Check()<commit_after>package goroots

import "math"
import "testing"
import "testing/quick"

// Does SolveBisection correctly solve a simple linear function?
func TestLinear(t *testing.T) {
	makeLinear := func(root float64) func(float64) float64 {
		return func(x float64) float64 { return root - x }
	}
	checker := func(root float64) bool {
		scale := math.Fabs(root)
		epsilon := scale / 1e-5
		val, err := SolveBisection(makeLinear(root), root - scale, root + scale, epsilon)
		if err != nil {
			return false
		}
		return val == root
	}
	if !(checker(5) && checker(100) && checker(1e-5)) {
		t.FailNow()
	}
}

// Does BisectionFullPrecision correctly solve arbitrary simple linear functions?
func TestLinearFullPrecision(t *testing.T) {
	macheps := math.Pow(2.0, -53.0)
	makeLinear := func(root float64) func(float64) float64 {
		return func(x float64) float64 { return root - x }
	}
	checker := func(root float64) bool {
		scale := math.Fabs(root)
		val, err := BisectionFullPrecision(makeLinear(root), root - scale, root + scale)
		if err != nil {
			return false
		}
		return val - root <= macheps
	}
	if err := quick.Check(checker, nil); err != nil {
		t.Error(err)
	}
}
{'fraction_non_alphanumeric': 0.13253012048192772, 'fraction_numerical': 0.0321285140562249, 'mean_word_length': 3.893909626719057, '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': '4465516', 'n_tokens_mistral': 960, 'n_tokens_neox': 871, 'n_words': 248}