/**
  * @dataProvider mydataProvider
  */
 public function test_convert($expr1, $expr2)
 {
     global $typeOfVars;
     $tree1 = build_tree($expr1, $typeOfVars);
     $tree2 = build_tree($expr2, $typeOfVars);
     $tree1->ptonewchild = null;
     $tree1->convert($tree1);
     while ($tree1->ptonewchild != null) {
         $tree1 = $tree1->ptonewchild;
         $tree1->ptonewchild = null;
         $tree1->convert($tree1);
     }
     $file = fopen("tree2.gv", "w");
     fwrite($file, "digraph {\n");
     print_tree_to_dot($file, $tree2);
     fwrite($file, '}');
     fclose($file);
     $tree2->ptonewchild = null;
     $tree2->convert($tree2);
     while ($tree2->ptonewchild != null) {
         $tree2 = $tree2->ptonewchild;
         $tree2->ptonewchild = null;
         $tree2->convert($tree2);
     }
     $file = fopen("tree1.gv", "w");
     fwrite($file, "digraph {\n");
     print_tree_to_dot($file, $tree1);
     fwrite($file, '}');
     fclose($file);
     $this->assertTrue(is_tree_equal($tree1, $tree2, TRUE));
     $tree1->delete_childrens();
     $tree2->delete_childrens();
     unset($tree1);
     unset($tree2);
 }
 /**
  * @dataProvider mydataProvider
  */
 public function test_compareTree($expr1, $expr2, $result)
 {
     global $typeOfVars;
     $tree1 = build_tree($expr1, $typeOfVars);
     $tree2 = build_tree($expr2, $typeOfVars);
     $this->assertEquals($result, is_tree_equal($tree1, $tree2, FALSE));
 }
 /**
  * @dataProvider mydataProvider
  */
 public function test_openbracket($expr1, $expr2)
 {
     global $typeOfVars;
     $tree1 = build_tree($expr1, $typeOfVars);
     $tree2 = build_tree($expr2, $typeOfVars);
     $opened = $tree1->open_bracket();
     $this->assertTrue(is_tree_equal($opened, $tree2, TRUE));
 }
 /**
  * @dataProvider mydataProvider
  */
 public function test_sortchild($expr1, $expr2)
 {
     global $typeOfVars;
     $tree1 = build_tree($expr1, $typeOfVars);
     $tree2 = build_tree($expr2, $typeOfVars);
     $tree1->sort_childrens();
     $tree2->sort_childrens();
     $this->assertTrue(is_tree_equal($tree1, $tree2, FALSE));
 }
 /**
  * @dataProvider mydataProvider
  */
 public function test_sortchild($expr1, $expr2)
 {
     global $typeOfVars;
     $tree1 = build_tree($expr1, $typeOfVars);
     $tree2 = build_tree($expr2, $typeOfVars);
     $tree1->convert_quine_mc_cluskey();
     $tmp;
     if (get_class($tree2) != 'qtype_correctwriting_or_logic_operator') {
         $tmp = new qtype_correctwriting_or_logic_operator();
         array_push($tmp->childrens, $tree2);
         $tree2 = $tmp;
     }
     $this->assertTrue(is_tree_equal($tree1, $tree2, TRUE));
 }
Example #6
0
 /**
  * Найти позицию сына в полном виде функции
  * \param [in] node узказатель на сын
  * \param [in] vec вектор полного вида функции
  *
  * \return позицию сына в полном виде функции
  */
 public function pos_in_full_exp($node, $vec)
 {
     for ($i = 0; $i < count($vec); $i++) {
         if (is_tree_equal($node, $vec[$i])) {
             return $i;
         }
     }
     return -1;
 }
Example #7
0
        // печать DOT файл
        $file = fopen($filegv, "w");
        fwrite($file, "digraph {\n");
        print_tree_to_dot($file, $tree);
        fwrite($file, '}');
        fclose($file);
        return $tree;
    } catch (Exception $e) {
        echo "In file {$filename}: " . $e->getMessage() . " \n";
        return null;
    }
}
if ($argc > 3) {
    echo "Too much argument in command line\n";
} elseif ($argc < 3) {
    echo "Too few argument in command line\n";
} else {
    // преобразовать каждое выражение
    $tree1 = process_each_expression($argv[1], "tree1.gv");
    $tree2 = process_each_expression($argv[2], "tree2.gv");
    // сравнение
    if ($tree1 !== null && $tree2 !== null) {
        $file = fopen("result.txt", "w");
        if (is_tree_equal($tree1, $tree2)) {
            fwrite($file, 'Expression equals');
        } else {
            fwrite($file, 'Epression NOT equals');
        }
        fclose($file);
    }
}
Example #8
0
/**
 * \brief Функция сравнения двух деревьев
 *
 * \param [in] tree1 указатель на узел первого дерева
 * \param [in] tree2 указатель на узел второго дерева
 * \param [in] isPrintDiff флаг: печать ли разницы двух деревьев
 * \return true если два дерева равны, в противном случае false
 * 
 */
function is_tree_equal($tree1, $tree2, $isPrintDiff = FALSE)
{
    if (get_class($tree1) != get_class($tree2)) {
        // печать разницы при тестировать
        if ($isPrintDiff) {
            echo "____ type of node diff\n";
            echo "__________ result = " . get_class($tree1) . "\n";
            echo "__________ expected = " . get_class($tree2) . "\n";
        }
        return false;
    }
    if (is_a($tree1, 'qtype_correctwriting_operand')) {
        // операнд
        if ($tree1->name != $tree2->name) {
            // печать разницы при тестировать
            if ($isPrintDiff) {
                echo "____ name of operand diff\n";
                echo "__________ result = " . $tree1->name . "\n";
                echo "__________ expected = " . $tree2->name . "\n";
            }
            return false;
        }
        if ($tree1->number != $tree2->number) {
            // печать разницы при тестировать
            if ($isPrintDiff) {
                echo "____ number of operand diff\n";
                echo "__________ result = " . $tree1->number . "\n";
                echo "__________ expected = " . $tree2->number . "\n";
            }
            return false;
        }
    } elseif (is_subclass_of($tree1, 'qtype_correctwriting_one_dim_node')) {
        // унарный
        return is_tree_equal($tree1->children, $tree2->children, $isPrintDiff);
    } elseif (is_subclass_of($tree1, 'qtype_correctwriting_binary_node')) {
        // бинарный
        return is_tree_equal($tree1->left, $tree2->left, $isPrintDiff) && is_tree_equal($tree1->right, $tree2->right, $isPrintDiff);
    } elseif (is_subclass_of($tree1, 'qtype_correctwriting_k_dim_node')) {
        // k-dim
        $res = count($tree1->childrens) == count($tree2->childrens);
        $i = 0;
        while ($res && $i < count($tree1->childrens)) {
            $res = $res && is_tree_equal($tree1->childrens[$i], $tree2->childrens[$i], $isPrintDiff);
            $i++;
        }
        return $res;
    }
    return TRUE;
}