示例#1
0
 /**
  * @covers ::__construct
  * @covers ::addValue
  * @covers ::getValues
  * @covers ::getVariables
  * @covers ::removeValue
  */
 public function testRemoveValue()
 {
     $phi = new Phi($r = new Variable());
     $phi->addValue($a = new Variable());
     $phi->addValue($b = new Variable());
     $this->assertSame([$a, $b], iterator_to_array($phi->getValues()));
     $this->assertSame([$r, $a, $b], $phi->getVariables());
     $phi->removeValue($a);
     $this->assertSame([$b], iterator_to_array($phi->getValues()));
     $this->assertSame([$r, $b], $phi->getVariables());
 }
示例#2
0
 public function resolve(Phi $vertex, GraphState $state)
 {
     $types = [];
     foreach ($vertex->getVariables() as $value) {
         $types[] = $value->getType()->getType();
     }
     $types = array_unique($types);
     switch (count($types)) {
         case 1:
             if ($types[0] !== Type::TYPE_UNKNOWN || 0 === count($vertex->getValues())) {
                 // resolve variables to result
                 $this->removePhi($vertex, $state);
                 return true;
             }
             break;
         case 2:
             if (in_array(Type::TYPE_NUMERIC, $types)) {
                 if (in_array(Type::TYPE_LONG, $types) || in_array(Type::TYPE_DOUBLE, $types)) {
                     $this->removePhi($vertex, $state);
                     return true;
                 } elseif (in_array(Type::TYPE_BOOLEAN, $types)) {
                     $vertex->getResult()->setType(new Type(Type::TYPE_NUMERIC));
                     $this->removePhi($vertex, $state);
                     return true;
                 }
             }
             break;
     }
     return false;
 }