Exemplo n.º 1
0
 /**
  * Make a new experiment with given variants
  *
  * @since 0.1.0
  *
  * @param array $variants
  * @param int|string $id Experiment (group) ID
  * @param \MaBandit\MaBandit $bandit MaBandit object
  */
 public function __construct(array $variants, $id, \MaBandit\MaBandit $bandit)
 {
     $this->experiment = $bandit->createExperiment((string) $id, $variants);
     if (method_exists($bandit->getPersistor(), 'save_levers')) {
         $bandit->getPersistor()->batchSave($this->experiment->getLevers(), $id);
     }
 }
Exemplo n.º 2
0
 public function chooseLever(\MaBandit\Experiment $experiment, $increment = true)
 {
     $levers = $experiment->getLevers();
     if (1 == count($levers)) {
         $lever = $levers[0];
     } else {
         $lever = $this->getStrategy()->chooseLever($experiment);
     }
     if ($increment) {
         $lever->incrementDenominator();
         return $this->validateLever($this->getPersistor()->saveLever($lever));
     } else {
         return $lever;
     }
 }
Exemplo n.º 3
0
 public function testGetExperimentLoadsPersistedExperimentAndReturns()
 {
     $levers = \MaBandit\Lever::createBatchFromValues(array('blue', 'green'));
     $ex = \Mabandit\Experiment::withName('testGetExperiment')->forLevers($levers);
     $bandit = $this->getBandit();
     foreach ($levers as $l) {
         $bandit->getPersistor()->saveLever($l);
     }
     $this->assertEquals($bandit->getExperiment('testGetExperiment')->getLevers(), $ex->getLevers());
 }
Exemplo n.º 4
0
 public function testForLeversReturnsExperimentWithSpecifiedLeversSet()
 {
     $levers = \MaBandit\Lever::createBatchFromValues(array('blue', 'green'));
     $experiment = \MaBandit\Experiment::withName('test')->forLevers($levers);
     $taggedLevers = array();
     foreach ($levers as $l) {
         $nl = clone $l;
         $nl->experiment = 'test';
         $taggedLevers[] = $nl;
     }
     $this->assertEquals($taggedLevers, $experiment->getLevers());
     $this->assertEquals('test', $experiment->name);
 }
Exemplo n.º 5
0
 public function chooseLever(\MaBandit\Experiment $experiment)
 {
     $levers = $experiment->getLevers();
     return $this->shouldExplore($levers) ? $this->chooseExploratoryLever($levers) : $this->getWinner($levers);
 }
Exemplo n.º 6
0
 public function testChooseLeverAddsToDenominatorPersistsAndReturnsLever()
 {
     $bandit = $this->getBandit();
     $levers = \MaBandit\Lever::createBatchFromValues(array('yes', 'no'));
     $ex = \MaBandit\Experiment::withName('testchoosepersist')->forLevers($levers);
     $chosen = $bandit->chooseLever($ex);
     $this->assertEquals(1, $chosen->getDenominator());
     $f = new \MaBandit\Persistence\PersistedLever($chosen->getValue(), $ex->name);
     $this->assertEquals($chosen, $bandit->getPersistor()->loadLever($f));
 }