<commit_before><?php
/******************************************************************************
 * An implementation of dicto (scg.unibe.ch/dicto) in and for PHP.
 *
 * Copyright (c) 2016, 2015 <NAME> <<EMAIL>>
 *
 * This software is licensed under The MIT License. You should have received
 * a copy of the license along with the code.
 */

use Lechimp\Dicto\Graph\Graph;
use Lechimp\Dicto\Graph\Query;

class GraphQueryTest extends PHPUnit_Framework_TestCase {
    public function setUp() {
        $this->g = new Graph(); 
    }

    public function test_match_all() {
        $n1 = $this->g->create_node("a_type", []);
        $n2 = $this->g->create_node("b_type", []);

        $query = (new Query())
            ->with_condition(function($_) {
                return true;
            });
        $res = $query->execute_on($this->g);

        $this->assertEquals([[$n1],[$n2]], $res);
    }

    public function test_match_none() {
        $n1 = $this->g->create_node("a_type", []);
        $n2 = $this->g->create_node("b_type", []);

        $query = (new Query())
            ->with_condition(function($_) {
                return false;
            });
        $res = $query->execute_on($this->g);

        $this->assertEquals([], $res);
    }

    public function test_path() {
        $n1 = $this->g->create_node("a_type", []);
        $n2 = $this->g->create_node("b_type", []);
        $rel = $this->g->add_relation($n1, "rel_type", [], $n2);

        $all = function($_) { return true; };

        $query = (new Query())
            ->with_condition($all)
            ->with_condition($all)
            ->with_condition($all);
        $res = $query->execute_on($this->g);
        $this->assertEquals([[$n1,$rel,$n2]], $res);
    }
}<commit_msg>implemented tests with real matching.<commit_after><?php
/******************************************************************************
 * An implementation of dicto (scg.unibe.ch/dicto) in and for PHP.
 *
 * Copyright (c) 2016, 2015 <NAME> <<EMAIL>>
 *
 * This software is licensed under The MIT License. You should have received
 * a copy of the license along with the code.
 */

use Lechimp\Dicto\Graph\Graph;
use Lechimp\Dicto\Graph\Query;

class GraphQueryTest extends PHPUnit_Framework_TestCase {
    public function setUp() {
        $this->g = new Graph(); 
    }

    public function test_match_all() {
        $n1 = $this->g->create_node("a_type", []);
        $n2 = $this->g->create_node("b_type", []);

        $query = (new Query())
            ->with_condition(function($_) {
                return true;
            });
        $res = $query->execute_on($this->g);

        $this->assertEquals([[$n1],[$n2]], $res);
    }

    public function test_match_none() {
        $n1 = $this->g->create_node("a_type", []);
        $n2 = $this->g->create_node("b_type", []);

        $query = (new Query())
            ->with_condition(function($_) {
                return false;
            });
        $res = $query->execute_on($this->g);

        $this->assertEquals([], $res);
    }

    public function test_path() {
        $n1 = $this->g->create_node("a_type", []);
        $n2 = $this->g->create_node("b_type", []);
        $rel = $this->g->add_relation($n1, "rel_type", [], $n2);

        $all = function($_) { return true; };

        $query = (new Query())
            ->with_condition($all)
            ->with_condition($all)
            ->with_condition($all);
        $res = $query->execute_on($this->g);
        $this->assertEquals([[$n1,$rel,$n2]], $res);
    }

    public function test_path2() {
        $n1 = $this->g->create_node("a_type", []);
        $n2 = $this->g->create_node("b_type", []);
        $n3 = $this->g->create_node("c_type", []);
        $r1 = $this->g->add_relation($n1, "rel_A", [], $n2);
        $r2 = $this->g->add_relation($n2, "rel_B", [], $n3);

        $all = function($_) { return true; };

        $query = (new Query())
            ->with_condition($all)
            ->with_condition(function($e) {
                return $e->type() == "rel_B";
            })
            ->with_condition($all);
        $res = $query->execute_on($this->g);
        $this->assertEquals([[$n2,$r2,$n3]], $res);
    }

    public function test_paths() {
        $n1 = $this->g->create_node("a_type", []);
        $n2 = $this->g->create_node("b_type", []);
        $n3 = $this->g->create_node("c_type", []);
        $r1 = $this->g->add_relation($n1, "rel_A", [], $n2);
        $r2 = $this->g->add_relation($n2, "rel_A", [], $n3);

        $all = function($_) { return true; };

        $query = (new Query())
            ->with_condition($all)
            ->with_condition($all)
            ->with_condition($all);
        $res = $query->execute_on($this->g);
        $this->assertEquals([[$n1,$r1,$n2],[$n2,$r2,$n3]], $res);
    }
}
{'fraction_non_alphanumeric': 0.22795031055900622, 'fraction_numerical': 0.014078674948240166, 'mean_word_length': 2.3901754385964913, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 100, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1845599', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1557, 'n_words': 289}