NsplTest\RndTest::testWeightedChoice PHP Метод

testWeightedChoice() публичный Метод

public testWeightedChoice ( )
    public function testWeightedChoice()
    {
        $weights = ['a' => 15, 'b' => 15, 'c' => 10, 'd' => 40, 'e' => 20];
        $pairs = a\pairs($weights);
        $appearances = array_fill_keys(array_keys($weights), 0);
        for ($i = 0; $i < 50000; ++$i) {
            ++$appearances[weightedChoice($pairs)];
        }
        foreach ($appearances as $item => $rate) {
            $this->assertEquals(50000 * $weights[$item] / 100, $rate, '', 300);
        }
    }