예제 #1
0
def test_connect():
    """
    This test assures that a connection is being made from Edge 1 to 2.
    """
    graph = Graph('')
    e1 = graph.add(Edge('', 1, 1))
    e2 = graph.add(Edge('', 2, 1))
    graph.connect(e1, e2)
    assert graph[e2] == []
    assert graph[e1] == [e2]
예제 #2
0
def test_connect():
    """
    This test assures that a connection is being made from Edge 1 to 2.
    """
    graph = Graph("")
    e1 = graph.add(Edge("", 1, 1))
    e2 = graph.add(Edge("", 2, 1))
    graph.connect(e1, e2)
    assert graph[e2] == []
    assert graph[e1] == [e2]
예제 #3
0
def test_can_t_connect_twice():
    """
    This test assures that edges which already have been connected will
    not result in an additional edge again.
    """
    graph = Graph('')
    e1 = Edge('', 1, 1)
    e2 = Edge('', 1, 2)
    for i in range(5):
        graph.connect(e1, e2)

    assert graph[e1] == [e2]
예제 #4
0
def test_can_t_connect_twice():
    """
    This test assures that edges which already have been connected will
    not result in an additional edge again.
    """
    graph = Graph("")
    e1 = Edge("", 1, 1)
    e2 = Edge("", 1, 2)
    for i in range(5):
        graph.connect(e1, e2)

    assert graph[e1] == [e2]
예제 #5
0
class TestGraph(unittest.TestCase):
    def setUp(self):
        self.graph = Graph('foo')

    def test_graph_add(self):
        e1 = self.graph.add(Edge('', 1, 1))
        self.assertListEqual([e1], self.graph.edges)

        e2 = self.graph.add(Edge('', 3, 1))
        self.assertEqual(2, len(self.graph))
        self.assertListEqual([e1, e2], self.graph.edges)

        self.graph.add(Edge('', 3, 1))
        self.assertEqual(2, len(self.graph))

    def test_graph_in(self):
        data = ('n', 1, 1)
        self.graph.add(Edge(*data))
        e2 = Edge(*data)
        self.assertTrue(e2 in self.graph)

    def test_graph__getitem__(self):
        data = ('n', 1, 1)
        self.graph.add(Edge(*data))
        self.assertListEqual([], self.graph[Edge(*data)])
예제 #6
0
class TestGraph(unittest.TestCase):
    def setUp(self):
        self.graph = Graph("foo")

    def test_graph_add(self):
        e1 = self.graph.add(Edge("", 1, 1))
        self.assertListEqual([e1], self.graph.edges)

        e2 = self.graph.add(Edge("", 3, 1))
        self.assertEqual(2, len(self.graph))
        self.assertListEqual([e1, e2], self.graph.edges)

        self.graph.add(Edge("", 3, 1))
        self.assertEqual(2, len(self.graph))

    def test_graph_in(self):
        data = ("n", 1, 1)
        self.graph.add(Edge(*data))
        e2 = Edge(*data)
        self.assertTrue(e2 in self.graph)

    def test_graph__getitem__(self):
        data = ("n", 1, 1)
        self.graph.add(Edge(*data))
        self.assertListEqual([], self.graph[Edge(*data)])
예제 #7
0
    def test_slice_with_graph(self):
        graph2 = Graph()
        graph2.add(4)
        graph2.add(5)
        graph2.add(6)
        graph2.connect(4, 5)
        graph2.connect(5, 6)

        self.graph.add(3)
        self.graph.add(4)
        self.graph.add(graph2)
        self.graph.connect(4, graph2)

        result = self.graph.slice_forward(4)
        self.assertEqual([4, 5, 6], result)
예제 #8
0
 def setUp(self):
     self.graph = Graph('foo')
예제 #9
0
class TestGraph(unittest.TestCase):

    def setUp(self):
        self.graph = Graph('foo')

    def test_repr(self):
        self.assertEqual('<Graph foo>', repr(self.graph))

    def test_first_last(self):
        self.graph.add(3)
        self.graph.add(1)
        self.graph.add(5)
        self.assertEqual(1, self.graph.first)
        self.assertEqual(5, self.graph.last)

    def test_add(self):
        self.graph.add(1)
        self.graph.add(2)
        self.assertEqual([1, 2], self.graph.edges)

        self.graph.add(3)
        self.assertEqual(3, len(self.graph))
        self.assertEqual([1, 2, 3], self.graph.edges)

    def test_connect(self):
        self.graph.add(1)
        self.graph.add(2)
        self.graph.connect(1, 2)
        self.assertEqual([2], self.graph[1])

        self.graph.connect(2, 1)
        self.assertEqual([1], self.graph[2])

    def test_edges(self):
        self.graph.add(1)
        self.graph.add(2)

        result = self.graph.edges
        self.assertEqual([1, 2], result)

    def test_slice_forward(self):
        for i in range(1, 12):
            self.graph.add(i)

        self.graph.connect(1, 10)
        self.graph.connect(1, 6)
        self.graph.connect(2, 11)
        self.graph.connect(2, 7)
        self.graph.connect(2, 3)
        self.graph.connect(3, 5)
        self.graph.connect(3, 8)
        self.graph.connect(3, 4)
        self.graph.connect(4, 5)
        self.graph.connect(6, 6)
        self.graph.connect(6, 10)
        self.graph.connect(7, 7)
        self.graph.connect(8, 8)
        self.graph.connect(8, 5)
        self.graph.connect(8, 7)

        result = self.graph.slice_forward(2)
        self.assertEqual([2, 3, 4, 5, 7, 8, 11], result)

    def test_slice_with_graph(self):
        graph2 = Graph()
        graph2.add(4)
        graph2.add(5)
        graph2.add(6)
        graph2.connect(4, 5)
        graph2.connect(5, 6)

        self.graph.add(3)
        self.graph.add(4)
        self.graph.add(graph2)
        self.graph.connect(4, graph2)

        result = self.graph.slice_forward(4)
        self.assertEqual([4, 5, 6], result)
예제 #10
0
 def setUp(self):
     self.graph = Graph('foo')
예제 #11
0
def test_repr():
    graph = Graph('foo')
    graph.add(Edge('o', 3, 4))
    expected = '<Graph foo [(<Edge o at #3@4>, [])]>'
    assert expected == repr(graph)
예제 #12
0
 def setUp(self):
     self.graph = Graph("foo")
예제 #13
0
def test_repr():
    graph = Graph("foo")
    graph.add(Edge("o", 3, 4))
    expected = "<Graph foo [(<Edge o at #3@4>, [])]>"
    assert expected == repr(graph)