Skip to content
Snippets Groups Projects
Forked from Eclipse Projects / aidge / aidge_core
2433 commits behind the upstream repository.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Test_FsmMatch.cpp 2.03 KiB

#include <catch2/catch_test_macros.hpp>

#include "aidge/graph/GraphView.hpp"
#include "aidge/operator/Conv.hpp"
#include "aidge/operator/GenericOperator.hpp"
#include "aidge/operator/Producer.hpp"


#include "aidge/graphRegex/GraphFsmInterpreter.hpp"


using namespace Aidge;
TEST_CASE("FsmMatch") {

    SECTION("Construction") {
        std::map<std::string,std::shared_ptr<ConditionalInterpreter>> allTest = {
            {"A",std::make_shared<ConditionalInterpreter>("isConv($)==true")},
            {"B",std::make_shared<ConditionalInterpreter>("isConv($)==true")},
            {"C",std::make_shared<ConditionalInterpreter>("true==true")}
        };

        allTest["A"]->insertLambda("isConv",+[](NodePtr NodeOp){return NodeOp->type() == "Conv";});
        allTest["B"]->insertLambda("isConv",+[](NodePtr NodeOp){return NodeOp->type() == "Conv";});

        std::shared_ptr<GraphFsmInterpreter>  fsmGenerator = std::make_shared<GraphFsmInterpreter>("A#->B",allTest);
        std::shared_ptr<FsmGraph> fsm = fsmGenerator->interpret();


        
        //REQUIRE(fsm->getNodes().size() == 3);
        //REQUIRE(fsm->getStartNodes().size() == 1);

        

        std::shared_ptr<GraphView> g1 = std::make_shared<GraphView>("TestGraph");
        std::shared_ptr<Node> conv = GenericOperator("Conv", 1, 1, 1, "c");
        std::shared_ptr<Node> conv1 = GenericOperator("Conv", 1, 1, 1, "c1");
        std::shared_ptr<Node> conv2 = GenericOperator("Conv", 1, 1, 1, "c2");
        std::shared_ptr<Node> conv3 = GenericOperator("Conv", 1, 1, 1, "c3");
        std::shared_ptr<Node> conv3_5 = GenericOperator("Conv", 1, 1, 1, "c3.5");
        std::shared_ptr<Node> conv4 = GenericOperator("Conv", 1, 1, 1, "c4");
        std::shared_ptr<Node> conv5 = GenericOperator("Conv", 1, 1, 1, "c5");

        g1->add(conv);
        g1->addChild(conv1, "c");


        REQUIRE(allTest["A"]->test(conv) == true);
        REQUIRE(allTest["B"]->test(conv) == true);

        std::vector<std::shared_ptr<Node>> startNodes = {conv};

        fsm->test(startNodes);


        
    }





}