Example #1
0
def test_sets():
    '''
    asd
    '''
    g = AG()
    n1 = Node("1")
    n2 = Node("2")
    n3 = Node("3")
    n4 = Node("4")
    n5 = Node("5")
    e1 = g.add_activity("1", "does", "2")
    assert e1 in g.get_activities()
    assert len(g.get_activities()) == 1
    assert n1 in g.get_nodes()
    assert n2 in g.get_nodes()
    assert len(g.get_nodes()) == 2
    e2 = g.add_activity("3", "does", "4")
    assert e1 in g.get_activities()
    assert e2 in g.get_activities()
    assert len(g.get_activities()) == 2
    assert n1 in g.get_nodes()
    assert n2 in g.get_nodes()
    assert n3 in g.get_nodes()
    assert len(g.get_nodes()) == 4
    e3 = g.add_activity("1", "does", "4")
    assert e1 in g.get_activities()
    assert e2 in g.get_activities()
    assert e3 in g.get_activities()
    assert len(g.get_activities()) == 3
    assert n1 in g.get_nodes()
    assert n2 in g.get_nodes()
    assert n3 in g.get_nodes()
    assert n4 in g.get_nodes()
    assert len(g.get_nodes()) == 4
    e4 = g.add_activity("1", "does", "5")
    assert e1 in g.get_activities()
    assert e2 in g.get_activities()
    assert e3 in g.get_activities()
    assert e4 in g.get_activities()
    assert len(g.get_activities()) == 4
    assert n1 in g.get_nodes()
    assert n2 in g.get_nodes()
    assert n3 in g.get_nodes()
    assert n4 in g.get_nodes()
    assert n5 in g.get_nodes()
    assert len(g.get_nodes()) == 5
    assert Node("1") in g.get_nodes()
    assert Node("2") in g.get_nodes()
    assert Node("3") in g.get_nodes()
    assert Node("4") in g.get_nodes()
    assert Node("5") in g.get_nodes()
Example #2
0
def test_add_activity():
    '''
    asd
    '''
    g = AG()
    activity = Edge("1", "does", "2")
    source = Node("1")
    target = Node("2")
    g.add_activity("1", "does", "2")
    assert activity in g.get_activities()
    assert source in g.get_nodes()
    assert target in g.get_nodes()
    assert len(g.get_activities()) == 1
    assert len(g.get_nodes()) == 2
Example #3
0
    def __init__(self, source: str, label: str, target: str):
        '''
        Constructor setting attributes.

        Note that this function explicitly creates Node objects from
        the source and target arguments.

        Keyword arguments:
        source -- the name of the source node
        label -- the name of the edge
        target -- the name of the target node
        '''
        self.source_node = Node(source)
        self.label = label
        self.target_node = Node(target)
Example #4
0
    def add_activity(self, source: str, activity: str, target: str):
        '''
        Add an activity to the activity graph by mapping the provided
        string arguments to nodes and edges

        Keyword arguments:
        source -- the name of the source node of the activity
        activity -- the name of the activity
        target -- the name of the target node of the activity
        '''
        edge = Edge(source, activity, target)
        self.nodes.add(Node(source))
        self.nodes.add(Node(target))
        self.edges.add(edge)
        return edge
Example #5
0
class Edge:
    '''
    An edge in a directed graph. Edges have a source and a target node.

    Attributes:
    source_node -- A resosuma.graph.node.Node, the source of the edge
    target_node -- A resosuma.graph.node.Node, the target of the edge
    label -- The label string of the edge
    '''
    def __init__(self, source: str, label: str, target: str):
        '''
        Constructor setting attributes.

        Note that this function explicitly creates Node objects from
        the source and target arguments.

        Keyword arguments:
        source -- the name of the source node
        label -- the name of the edge
        target -- the name of the target node
        '''
        self.source_node = Node(source)
        self.label = label
        self.target_node = Node(target)

    def get_source(self):
        return self.source_node

    def get_target(self):
        return self.target_node

    def get_label(self):
        return self.label

    def __str__(self):
        src = self.source_node.get_label()
        trg = self.target_node.get_label()
        return 'Edge: ' + src + ' > ' + self.label + ' > ' + trg

    def __key(self):
        return (self.source_node, self.label, self.target_node)

    def __eq__(self, other):
        return self.__key() == other.__key()

    def __hash__(self):
        return hash(self.__key())
Example #6
0
def test_read_file(csv_file):
    ag = AG()
    ag.read_csv(csv_file)
    assert len(ag.get_activities()) == 3
    e1 = Edge("1", "does", "2")
    e2 = Edge("1", "does", "3")
    e3 = Edge("2", "does", "4")
    assert e1 in ag.get_activities()
    assert e2 in ag.get_activities()
    assert e3 in ag.get_activities()
    assert len(ag.get_nodes()) == 4
    n1 = Node("1")
    n2 = Node("2")
    n3 = Node("3")
    n4 = Node("4")
    assert n1 in ag.get_nodes()
    assert n2 in ag.get_nodes()
    assert n3 in ag.get_nodes()
    assert n4 in ag.get_nodes()
Example #7
0
def test_to_string():
    n = Node("Test")
    assert str(n) == "Node: Test"
Example #8
0
def test_get_label():
    n = Node("Test")
    assert n.get_label() == "Test"
Example #9
0
def test_target():
    e = Edge("1", "does", "2")
    assert e.get_target() == Node("2")
Example #10
0
def test_source():
    e = Edge("1", "does", "2")
    assert e.get_source() == Node("1")