Пример #1
0
    def __init__(self, initial_behaviour, socket_interface, logger,
                 formula_factory, route_table):
        """
        :param func initial_behaviour: Function that define
                                       the initial_behaviour

        :param socket_interface: Communication interface of the actor
        :type socket_interface: powerapi.SocketInterface

        :param formula_factory: Factory for Formula creation.
        :type formula_factory: func((formula_id) -> powerapi.Formula)
        :param route_table: initialized route table
        :type route_table: powerapi.dispatcher.state.RouteTable
        """
        State.__init__(self, initial_behaviour, socket_interface, logger)

        #: (dict): Store the formula by id
        self.formula_dict = {}

        #: (utils.Tree): Tree store of the formula for faster
        #: DispatchRule
        self.formula_tree = Tree()

        #: (func): Factory for formula creation
        self.formula_factory = formula_factory

        self.route_table = route_table
Пример #2
0
    def test_add_val_at_root(self):
        """Test to add a leaf to a tree of depth 0"""

        tree = Tree()
        tree.add(['A'], 1)

        assert tree.get([]) == [1]
        assert tree.get(['A']) == [1]
Пример #3
0
    def test_add_child_to_empty_tree(self):
        tree = Tree()
        tree.add(['A', 'B'], 1)

        assert tree.root is not None
        assert len(tree.root.childs) == 1
        assert tree.root.label == 'A'
        assert tree.root.childs[0] == Node('B', 1)
Пример #4
0
    def test_get_from_root(self):
        tree = Tree()
        tree.add(['A', 'B'], 1)

        assert tree.get([]) == [1]
        assert tree.get(['A']) == [1]
Пример #5
0
    def get_child_to_emtpy_tree(self):
        tree = Tree()

        assert tree.get(['A', 'B']) == []