Matchers allow you to alter the success criteria of an experiment.
Esempio n. 1
0
 /**
  * Determine whether trial results match the control.
  *
  * @param \Scientist\Matchers\Matcher $matcher
  * @param \Scientist\Result           $control
  * @param \Scientist\Result[]         $trials
  */
 protected function determineMatches(Matcher $matcher, Result $control, array $trials = [])
 {
     foreach ($trials as $trial) {
         if ($matcher->match($control->getValue(), $trial->getValue())) {
             $trial->setMatch(true);
         }
     }
 }
Esempio n. 2
0
 /**
  * Execute a callback and record an execution.
  *
  * @param callable                    $callable
  * @param array                       $params
  * @param \Scientist\Matchers\Matcher $matcher
  * @param \Scientist\Execution|null   $control
  *
  * @return \Scientist\Execution
  */
 protected function executeCallback(callable $callable, array $params, Matcher $matcher, Execution $control = null)
 {
     /**
      * We'll execute the provided callable between two
      * recorded timestamps, so that we can calculate
      * the execution time of the code.
      */
     $exception = null;
     $before = microtime(true);
     if ($control) {
         try {
             $value = call_user_func_array($callable, $params);
         } catch (Exception $ex) {
             $value = null;
             $exception = $ex;
         }
     } else {
         $value = call_user_func_array($callable, $params);
     }
     $after = microtime(true);
     /**
      * A control value is provided for trail executions.
      */
     $compare = $control ? $control->getValue() : null;
     return new Execution($value, $after - $before, $matcher->match($value, $compare), $exception);
 }