Esempio n. 1
0
    def test_pons_asinorum(self):
        g0 = Graph.with_features(
            Equation.make_table(range(1, 20), range(1, 20),
                                [plus, minus, times]))
        g1 = Graph.augment(PrefixedGraph(1, g0), PrefixedGraph(2, g0))
        #        print('QQ')
        #        qq = list((x1, x1.with_prefix(2))
        #            for x1 in g1.query(WithPrefix(1, OfClass(After))))
        #        print(type(qq), type(qq[0]), len(qq[0]))
        #        pts(qq)
        g = g1.add_edges(
            EnumEdges(
                Hops.from_pairs(*(
                    (p_after, PrefixedNode(2, Before(p_after.unprefixed().x)))
                    for p_after in g1.query(WithPrefix(1, OfClass(After)))))))
        #pts(g.query(WithPrefix(1, OfClass(After))))
        #pts(g.query(WithPrefix(2, OfClass(Before))))
        #pts(g.successors_of(PrefixedNode(1, After(10))))
        #print()
        #pts(g.successors_of(PrefixedNode(1, After(63))))

        self.assertTrue(
            g.find_hop(PrefixedNode(1, After(10)), PrefixedNode(2,
                                                                Before(10))))
        self.assertFalse(
            g.find_hop(PrefixedNode(1, After(63)), PrefixedNode(2,
                                                                Before(63))))
Esempio n. 2
0
    def test_augment(self):
        g1 = AlphabetGraph()
        g2 = Graph(nodes=EnumNodes(range(1, 4)),
                   edges=EnumEdges(
                       Hops.from_pairs((1, 'a'), (2, 'b'), (3, 'c'))))
        g = Graph.augment(g2, g1)

        self.assertTrue(g2.has_node(1))
        self.assertFalse(g2.has_node('a'))
        self.assertFalse(g2.find_hop(1, 'a'))
        self.assertCountEqual(g2.successors_of(2), [])
        self.assertCountEqual(g2.predecessors_of('c'), [])

        self.assertTrue(g.has_node(1))
        self.assertTrue(g.has_node('a'))
        self.assertTrue(g.find_hop(1, 'a'))
        self.assertCountEqual(g.successors_of(2), ['b'])
        self.assertCountEqual(g.predecessors_of('b'), [2, 'a'])
Esempio n. 3
0
    def test_doubled_graph(self):
        g0 = Graph(nodes=EnumNodes(['a', 'b', 'o']),
                   edges=EnumEdges(Hops.from_pairs(('a', 'b'), ('b', 'o'))))
        g = Graph.augment(PrefixedGraph(1, g0), PrefixedGraph(2, g0))

        self.assertTrue(g.has_node(PrefixedNode(1, 'a')))
        self.assertTrue(g.has_node(PrefixedNode(2, 'a')))
        self.assertFalse(g.has_node(PrefixedNode(3, 'a')))
        self.assertFalse(g.has_node('a'))
        self.assertEqual(
            g.find_hop(PrefixedNode(1, 'a'), PrefixedNode(1, 'b')),
            Hop(PrefixedNode(1, 'a'), PrefixedNode(1, 'b'), 1.0))
        self.assertEqual(
            g.find_hop(PrefixedNode(2, 'a'), PrefixedNode(2, 'b')),
            Hop(PrefixedNode(2, 'a'), PrefixedNode(2, 'b'), 1.0))
        self.assertEqual(
            g.find_hop(PrefixedNode(1, 'a'), PrefixedNode(2, 'b')), None)
        self.assertEqual(g.find_hop('a', 'b'), None)

        # .add_edges() from one PrefixedGraph to the other

        g2 = g.add_edges(
            EnumEdges(
                Hops.from_pairs((PrefixedNode(1, 'a'), PrefixedNode(2, 'a')))))
        self.assertEqual(
            g2.find_hop(PrefixedNode(1, 'a'), PrefixedNode(2, 'a')),
            Hop(PrefixedNode(1, 'a'), PrefixedNode(2, 'a'), 1.0))

        self.assertCountEqual(g2.query(OfClass(str)), [
            PrefixedNode(1, 'a'),
            PrefixedNode(1, 'b'),
            PrefixedNode(1, 'o'),
            PrefixedNode(2, 'a'),
            PrefixedNode(2, 'b'),
            PrefixedNode(2, 'o')
        ])
        self.assertCountEqual(
            g2.query(WithPrefix(2, OfClass(str))),
            [PrefixedNode(2, 'a'),
             PrefixedNode(2, 'b'),
             PrefixedNode(2, 'o')])
        self.assertCountEqual(g0.query(WithPrefix(2, OfClass(str))), [])
Esempio n. 4
0
 def fill_slipnet(self):
     #self.slipnet = eqn_graph
     self.slipnet.base_graph = \
         Graph.augment(self.slipnet.base_graph, eqn_graph)