MathPHP\SetTheory\Set::isSuperset PHP Method

isSuperset() public method

Superset (A ⊇ B) Is the set a superset of the other set? In other words, does the the set contain all the elements of the other set?
public isSuperset ( Set $B ) : boolean
$B Set
return boolean
    public function isSuperset(Set $B) : bool
    {
        $B_array = $B->asArray();
        $A∩B = array_intersect_key($this->A, $B_array);
        $A∖B = array_diff_key($B_array, $this->A);
        return count($A∩B) === $B->length() && empty($A∖B);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * @dataProvider dataProviderForIsSubsetSuperset
  */
 public function testIsSuperset(array $A, array $B)
 {
     $setA = new Set($B);
     $setB = new Set($A);
     $this->assertTrue($setA->isSuperset($setB));
 }