public function testConfigLoop() { $collection = $this->getMock(BagInterface::class); $collection->expects($this->exactly(3))->method('reset'); $collection->method('size')->will($this->returnValue(1)); $bag = new Bag($collection, ['loop' => true]); $bag->pick(); $bag->pick(); $bag->pick(); $bag->pick(); }
public function testLooping() { $values = ['a' => 'correct', 'b' => 'battery', 'c' => 'horse', 'd' => 'staple']; $bag = new Bag(new ArrayCollection($values), ['loop' => true]); $result = ['correct' => 0, 'battery' => 0, 'horse' => 0, 'staple' => 0]; $picks = 4 * pow(10, 4); for ($n = 0; $n < $picks; $n++) { $result[$bag->pick()]++; } $this->assertEquals($result['correct'], $result['battery']); $this->assertEquals($result['correct'], $result['horse']); $this->assertEquals(array_sum($result), $picks); }
public function testSingleElement() { $bag = new Bag(new RangeCollection(1, 1)); $this->assertEquals($bag->pick(), 1); }