/** * Run an experiment. * * @param \Scientist\Experiment $experiment * * @return mixed */ public function runExperiment(Experiment $experiment) { if ($experiment->shouldRun()) { $report = $this->getReport($experiment); return $report->getControl()->getValue(); } return call_user_func_array($experiment->getControl(), $experiment->getParams()); }
/** * Run trial callbacks and record their execution state. * * @param \Scientist\Experiment $experiment * * @return \Scientist\Result[] */ protected function runTrials(Experiment $experiment) { $executions = []; foreach ($experiment->getTrials() as $name => $trial) { $executions[$name] = (new Machine($trial, $experiment->getParams(), true))->execute(); } return $executions; }
/** * Run trial callbacks and record their execution state. * * @param \Scientist\Experiment $experiment * @param \Scientist\Execution $control * * @return array */ protected function runTrials(Experiment $experiment, Execution $control) { $executions = []; foreach ($experiment->getTrials() as $name => $trial) { $executions[$name] = $this->executeCallback($trial, $experiment->getParams(), $experiment->getMatcher(), $control); } return $executions; }
public function test_that_running_experiment_with_no_laboratory_executes_control() { $e = new Experiment('test experiment'); $e->control(function () { return 'foo'; }); $v = $e->run(); $this->assertEquals('foo', $v); }
public function test_that_intern_can_match_and_mismatch_control_and_trial() { $i = new Intern(); $e = new Experiment('test experiment', new Laboratory()); $e->control(function () { return 'foo'; }); $e->trial('bar', function () { return 'foo'; }); $e->trial('baz', function () { return 'baz'; }); $v = $i->run($e); $this->assertInstanceOf('\\Scientist\\Report', $v); $this->assertTrue($v->getTrial('bar')->isMatch()); $this->assertFalse($v->getTrial('baz')->isMatch()); }
public function test_that_an_experiment_matcher_can_be_set() { $e = new Experiment('test experiment'); $e->matcher(new StandardMatcher()); $this->assertInstanceOf(StandardMatcher::class, $e->getMatcher()); }