An experiment allows us to implement our code in a new way without risking the introduction of bugs or regressions.
Esempio n. 1
0
 /**
  * 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());
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
 /**
  * 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;
 }
Esempio n. 4
0
 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);
 }
Esempio n. 5
0
 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());
 }
Esempio n. 6
0
 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());
 }