Example #1
0
 public function testAddAllAddsUnique()
 {
     $setA = new BasicSet(new SimpleComparator());
     $setA->add('foo');
     $collectionB = new BasicCollection();
     $collectionB->add('foo');
     self::assertFalse($setA->addAll($collectionB));
 }
Example #2
0
 /**
  * @param mixed $element
  * @return boolean
  */
 public function contains($element)
 {
     if (!$element instanceof Comparable) {
         return parent::contains($element);
     }
     foreach ($this->elements as $el) {
         if ($this->comparator->equals($el, $element)) {
             return true;
         }
     }
     return false;
 }
 public function testConvertToArray()
 {
     $collection = new BasicCollection();
     $collection->add('foo');
     $collection->add('bar');
     $collection->add('baz');
     $collection->remove('bar');
     // this call should not create a gap in the index sequence
     $actual = $collection->toArray();
     $expected = [0 => 'foo', 1 => 'baz'];
     self::assertEquals($expected, $actual);
 }