public function test_suffle()
 {
     $this->assert_values_same([], cs_iter([])->shuffle());
     $this->assert_values_same([9], cs_iter([9])->shuffle());
     // Let grab a list of 12 elements, the number of
     // its unique permutations is d = 12! ≈ 5*10^8.
     $list = cs_iter([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
     // If we do n = 100 random draws from a set of all
     // permutations, the probability of a collision
     // p(n, d) ≈ 1 - exp(-n(n-1)/2d) ≈ 0.00001 [1]
     //
     // [1]: Search for the generalized birthday problem.
     $n = 100;
     $draws = cs_set();
     for ($i = 0; $i < $n; ++$i) {
         $draw = $list->shuffle()->to_array();
         $draws->add(implode(',', $draw));
     }
     $this->assertEqual($n, $draws->count());
 }
Exemple #2
0
 function testNullSupport()
 {
     $set = cs_set();
     $this->assertFalse($set->contains(null));
     $set->add(null);
     $this->assertTrue($set->contains(null));
     $this->assertFalse($set->contains(false));
     $this->assertFalse($set->contains(0));
     $set->remove(null);
     $this->assertFalse($set->contains(null));
 }