<commit_before>package experiment

type (
	// Result represents the result from running all the observations and comparing
	// them with the given compare method.
	Result interface {
		// Mismatches represent the observations on which the given `Compare`
		// option returned false.
		Mismatches() []Observation
		// Candidates represents all the observations which are not the control.
		Candidates() []Observation
		// Control represents the observation of the results from the control
		// function.
		Control() Observation
	}

	experimentResult struct {
		mismatches []Observation
		candidates []Observation
		control    Observation
		experiment *Experiment
	}
)

// NewResult will take an experiment and go over all the observations to find
// if the observation is a match or a mismatch.
func NewResult(e *Experiment) Result {
	rs := &experimentResult{
		mismatches: []Observation{},
		candidates: []Observation{},
		experiment: e,
	}

	for _, o := range e.observations {
		if o.Name() == "control" {
			rs.control = o
		} else {
			rs.candidates = append(rs.candidates, o)
		}
	}

	if rs.experiment.opts.comparison != nil {
		rs.evaluate()
	}

	return rs
}

func (r *experimentResult) Mismatches() []Observation {
	return r.mismatches
}

func (r *experimentResult) Candidates() []Observation {
	return r.candidates
}

func (r *experimentResult) Control() Observation {
	return r.control
}

// evaluate does the hard work of going through all the result Candidates and
// calls the compare method given to the experiment with the Control and the
// candidate value. If no comparison method is given in the options, evaluate
// is skipped.
func (r *experimentResult) evaluate() {
	for _, c := range r.candidates {
		if !r.experiment.opts.comparison(r.control, c) {
			r.mismatches = append(r.mismatches, c)
		}
	}
}<commit_msg>Result: panic on mismatched data in test mode.<commit_after>package experiment

import "fmt"

type (
	// Result represents the result from running all the observations and comparing
	// them with the given compare method.
	Result interface {
		// Mismatches represent the observations on which the given `Compare`
		// option returned false.
		Mismatches() []Observation
		// Candidates represents all the observations which are not the control.
		Candidates() []Observation
		// Control represents the observation of the results from the control
		// function.
		Control() Observation
	}

	experimentResult struct {
		mismatches []Observation
		candidates []Observation
		control    Observation
		experiment *Experiment
	}
)

// NewResult will take an experiment and go over all the observations to find
// if the observation is a match or a mismatch.
func NewResult(e *Experiment) Result {
	rs := &experimentResult{
		mismatches: []Observation{},
		candidates: []Observation{},
		experiment: e,
	}

	for _, o := range e.observations {
		if o.Name() == "control" {
			rs.control = o
		} else {
			rs.candidates = append(rs.candidates, o)
		}
	}

	if rs.experiment.opts.comparison != nil {
		rs.evaluate()
	}

	return rs
}

func (r *experimentResult) Mismatches() []Observation {
	return r.mismatches
}

func (r *experimentResult) Candidates() []Observation {
	return r.candidates
}

func (r *experimentResult) Control() Observation {
	return r.control
}

// evaluate does the hard work of going through all the result Candidates and
// calls the compare method given to the experiment with the Control and the
// candidate value. If no comparison method is given in the options, evaluate
// is skipped.
func (r *experimentResult) evaluate() {
	for _, c := range r.candidates {
		if !r.experiment.opts.comparison(r.control, c) {
			r.mismatches = append(r.mismatches, c)

			if r.experiment.opts.testMode {
				panic(fmt.Sprintf("Data mismatch in %v", c))
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.09734280452512496, 'fraction_numerical': 0.0, 'mean_word_length': 3.728855721393035, 'pattern_counts': {'":': 0, '<': 3, '<?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': '552985', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1108, 'n_words': 414}