public function saveLever(\MaBandit\Lever $lever)
 {
     if (!array_key_exists($lever->experiment, $this->_levers) or !is_array($this->_levers[$lever->experiment])) {
         $this->_levers[$lever->experiment] = array();
     }
     $this->_levers[$lever->experiment][$lever->getValue()] = $lever;
     return $lever;
 }
 public function testLoadsLeversForExperiment()
 {
     $p = new \MaBandit\Persistence\ArrayPersistor();
     $l = \MaBandit\Lever::forValue('x')->inflate(new \MaBandit\Persistence\PersistedLever('foo', 'y', 1, 2));
     $l1 = \MaBandit\Lever::forValue('x')->inflate(new \MaBandit\Persistence\PersistedLever('bar', 'y', 3, 4));
     $p->saveLever($l);
     $p->saveLever($l1);
     $f = new \MaBandit\Persistence\PersistedLever('we', 'y');
     $actual = $p->loadLeversForExperiment($f);
     $expected = array('foo' => $l, 'bar' => $l1);
     $this->assertEquals($expected, $actual);
 }
 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);
 }
Beispiel #4
0
 /**
  * Calculate stats for one lever
  *
  * @since 0.4.0
  *
  * @access protected
  *
  * @param \MaBandit\Lever $lever
  */
 protected function lever_stats($lever)
 {
     $this->stats['variants'][$lever->getValue()] = new stats($lever->getDenominator(), $lever->getNumerator(), $lever->getConversionRate());
 }
Beispiel #5
0
 public function registerConversion(\MaBandit\Lever $lever)
 {
     $lever->incrementNumerator();
     return $this->validateLever($this->getPersistor()->saveLever($lever));
 }
 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));
 }
Beispiel #7
0
 /**
  * @expectedException \MaBandit\Exception\LeverNumeratorTooHighException
  */
 public function testIncrementNumeratorRaisesIf100PercentConversionRate()
 {
     $l = \MaBandit\Lever::forValue('foo');
     $l->incrementNumerator();
 }