public function testCompositesWithoutIntersection()
 {
     // (x > 999) or ((x > 7) and (x <= 42))
     $comp1 = new ConditionComposite();
     // (x > 999)
     $comp1_1 = new ValueGreaterThan(999);
     // ()
     $comp1_2 = new ConditionComposite();
     $comp1->addOR($comp1_1)->addOR($comp1_2);
     // (x > 7)
     $comp1_2_1 = new ValueGreaterThan(7);
     // (x <= 42)
     $comp1_2_2 = new ValueGreaterThan(42);
     $comp1_2_2->negate();
     $comp1_2->addAND($comp1_2_1)->addAND($comp1_2_2);
     // (x > 100) and (x <= 999)
     $comp2 = new ConditionComposite();
     // (x > 100)
     $comp2_1 = new ValueGreaterThan(100);
     // (x <= 999)
     $comp2_2 = new ValueGreaterThan(999);
     $comp2_2->negate();
     $comp2->addAND($comp2_1)->addAND($comp2_2);
     $this->assertFalse($this->detector->intersectExists($comp1, $comp2));
 }
Ejemplo n.º 2
0
 /**
  * Takes an array of Condition objects and returns a ConditionComposite
  * containing all given conditions as AND nodes.
  * 
  * @param \lukaszmakuch\LmCondition\Condition[] $ANDConditions
  * @return ConditionComposite
  */
 protected function getANDCompositeOfConditions(array $ANDConditions)
 {
     $composite = new ConditionComposite();
     foreach ($ANDConditions as $condition) {
         $composite->addAND($condition);
     }
     return $composite;
 }
 /**
  * Checks whether intersection exsits among all AND conditions within
  * these composites.
  * 
  * @param ConditionComposite $ANDComposite1
  * @param ConditionComposite $ANDComposite2
  * 
  * @throws ImpossibleToLookForIntersection
  * @return boolean if intersection exist among all AND conditions
  * withing these composites
  */
 protected function intersectionExistsBetween(ConditionComposite $ANDComposite1, ConditionComposite $ANDComposite2)
 {
     $setOfANDConditions1 = $ANDComposite1->getANDConditions();
     $setOfANDConditions2 = $ANDComposite2->getANDConditions();
     foreach ($setOfANDConditions1 as $ANDCondition1) {
         foreach ($setOfANDConditions2 as $ANDCondition2) {
             if (false === $this->leafIntersectDetector->intersectExists($ANDCondition1, $ANDCondition2)) {
                 return false;
             }
         }
     }
     return true;
 }
Ejemplo n.º 4
0
 protected function decomposeRow(ConditionComposite $c)
 {
     if (false === empty($c->getORConditions())) {
         throw new InvalidArgumentException("in this test there should be no OR conditions");
     }
     $result = [];
     foreach ($c->getANDConditions() as $c) {
         if ($c instanceof ConditionComposite) {
             throw new InvalidArgumentException("in this test there should be no composite");
         }
         $result[] = $c;
     }
     return $result;
 }
 /**
  * Compares composites that contain only AND conditions (that are not composites).
  * 
  * @param ConditionComposite $comp1
  * @param ConditionComposite $comp2
  * 
  * @throws IncomparableConditions when it's not possible to compare leaves
  * @return boolean
  */
 protected function ANDCompositesAreEqual(ConditionComposite $comp1, ConditionComposite $comp2)
 {
     return ArrayComparator::arraysHoldEqualElements($comp1->getANDConditions(), $comp2->getANDConditions(), function (Condition $c1, Condition $c2) {
         return $this->leafEqualityComparator->equal($c1, $c2);
     });
 }
Ejemplo n.º 6
0
 /**
  * Gets all OR conditions of a composite and processes them through decompose(Condition).
  * 
  * @param ConditionComposite $c
  * 
  * @return array
  */
 protected function decomposeORConditionsOf(ConditionComposite $c)
 {
     return array_reduce($c->getORConditions(), function (array $decomposed, Condition $c) {
         return array_merge($decomposed, $this->decompose($c));
     }, []);
 }
Ejemplo n.º 7
0
 /**
  * (A AND (B OR (C AND D AND (E OR F))))
  * 
  * should be decomposed to:
  * 
  * [
  *     [A, B],
  *     [A, C, D, E]
  *     [A, C, D, F]
  * ]
  * 
  */
 public function testComplexStructureWithManyLevels()
 {
     //leaves
     $A = new FakeCondition("A");
     $B = new FakeCondition("B");
     $C = new FakeCondition("C");
     $D = new FakeCondition("D");
     $E = new FakeCondition("E");
     $F = new FakeCondition("F");
     //E OR F
     $comp1 = new ConditionComposite();
     $comp1->addOR($E)->addOR($F);
     //C AND D AND (E OR F)
     $comp2 = new ConditionComposite();
     $comp2->addAND($C)->addAND($D)->addAND($comp1);
     //B OR (C AND D AND (E OR F))
     $comp3 = new ConditionComposite();
     $comp3->addOR($B)->addOR($comp2);
     //A AND (B OR (C AND D AND (E OR F)))
     $composite = new ConditionComposite();
     $composite->addAND($A)->addAND($comp3);
     $expected = [[$A, $B], [$A, $C, $D, $E], [$A, $C, $D, $F]];
     $decompositionResult = $this->decomposer->decompose($composite);
     $this->assertTrue($this->decomposedStructuresAreIdentical($expected, $decompositionResult));
 }
 public function testComparingDifferentComposites()
 {
     // (x > 7) and (!(x > 42) or (x > 99))
     $comp1 = new ConditionComposite();
     // (x > 7)
     $comp1_1 = new ValueGreaterThan(7);
     // ()
     $comp1_2 = new ConditionComposite();
     // !(x > 42)
     $comp1_2_1 = new ValueGreaterThan(42);
     $comp1_2_1->negate();
     // (x > 99)
     $comp1_2_2 = new ValueGreaterThan(99);
     //(!(x > 42) or (x > 99))
     $comp1_2->addOR($comp1_2_1)->addOR($comp1_2_2);
     //// (x > 7) and (!(x > 42) or (x > 99))
     $comp1->addAND($comp1_1)->addAND($comp1_2);
     // (!(x > 42) and (x > 7)) or ((x > 7) and !(x > 99))
     $comp2 = new ConditionComposite();
     // ()
     $comp2_1 = new ConditionComposite();
     // ()
     $comp2_2 = new ConditionComposite();
     $comp2->addOR($comp2_1)->addOR($comp2_2);
     // !(x > 42)
     $comp2_1_1 = new ValueGreaterThan(42);
     $comp2_1_1->negate();
     // (x > 7)
     $comp2_1_2 = new ValueGreaterThan(7);
     // !(x > 42) and (x > 7))
     $comp2_1->addAND($comp2_1_1)->addAND($comp2_1_2);
     // (x > 7)
     $comp2_2_1 = new ValueGreaterThan(7);
     // (x > 99)
     $comp2_2_2 = new ValueGreaterThan(99);
     $comp2_2_2->negate();
     // ((x > 7) and (x > 99))
     $comp2_2->addAND($comp2_2_1)->addAND($comp2_2_2);
     $this->assertFalse($this->cmp->equal($comp1, $comp2));
 }