当前位置: 首页>>代码示例>>Python>>正文


Python Graph.clear方法代码示例

本文整理汇总了Python中Graph.Graph.clear方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.clear方法的具体用法?Python Graph.clear怎么用?Python Graph.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Graph.Graph的用法示例。


在下文中一共展示了Graph.clear方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_remove_vertex

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import clear [as 别名]
  def test_remove_vertex(self):
    g = Graph()
    v = Vertex('v')
    w = Vertex('w')
    x = Vertex('x')
    e1 = Edge(v,w)
    e2 = Edge(w,x)
    e3 = Edge(v,x)

    # Test removal of only vertex
    g.add_vertex(v)
    g.remove_vertex(v)
    self.assertEqual(g, {})

    # Test removal of vertex with no edges incident on it
    g.clear()
    g.add_vertex(v)
    g.add_edge(e2)
    g.remove_vertex(v)
    self.assertEqual(g, {w:{x:e2}, x:{w:e2}})

    # Test removal of vertex with edges incident on it.
    g.clear()
    g.add_edge(e1)
    g.add_edge(e2)
    g.add_edge(e3)
    g.remove_vertex(v)
    self.assertEqual(g, {w:{x:e2}, x:{w:e2}})
开发者ID:shubhamgupta30,项目名称:think_bayes,代码行数:30,代码来源:Graph_test.py

示例2: test_add_all_edges

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import clear [as 别名]
  def test_add_all_edges(self):
    g = Graph()
    v = Vertex('v')
    w = Vertex('w')
    x = Vertex('x')
    e1 = Edge(v,w)
    e2 = Edge(w,x)
    e3 = Edge(v,x)

    # Test on a empty graph
    g.add_all_edges()
    self.assertEqual(g, {})

    # Test on a non-edgeless graph
    g.add_edge(e1)
    g.add_vertex(x)
    g.add_all_edges()
    self.assertEqual(g, {v:{w:e1}, w:{v:e1}, x:{}})

    # Test on a edgeless graph
    g.clear()
    g.add_vertex(v)
    g.add_vertex(w)
    g.add_vertex(x)
    g.add_all_edges()
    self.assertEqual(g, {v:{w:e1, x:e3}, w:{v:e1, x:e2}, x:{w:e2, v:e3}})
开发者ID:shubhamgupta30,项目名称:think_bayes,代码行数:28,代码来源:Graph_test.py

示例3: test_remove_edge

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import clear [as 别名]
  def test_remove_edge(self):
    g = Graph()
    v = Vertex('v')
    w = Vertex('w')
    x = Vertex('x')
    e1 = Edge(v,w)
    e2 = Edge(w,x)
    e3 = Edge(v,x)

    # Remove edge from an empty graph
    g.remove_edge(e1)
    self.assertEqual(g, {})

    # Remove a non existent edge with one vertex present
    g.clear()
    g.add_vertex(v)
    g.remove_edge(e1)
    self.assertEqual(g, {v:{}})

    # Remove a non existent edge with both vertices present
    g.clear()
    g.add_vertex(v)
    g.add_vertex(w)
    g.remove_edge(e1)
    self.assertEqual(g, {v:{}, w:{}})

    # Remove an existent edge
    g.clear()
    g.add_edge(e1)
    g.add_edge(e2)
    g.remove_edge(e1)
    self.assertEqual(g, {v:{}, w:{x:e2}, x:{w:e2}})
开发者ID:shubhamgupta30,项目名称:think_bayes,代码行数:34,代码来源:Graph_test.py

示例4: test_get_edge

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import clear [as 别名]
  def test_get_edge(self):
    g = Graph()
    v = Vertex('v')
    w = Vertex('w')
    x = Vertex('x')
    e1 = Edge(v,w)
    e2 = Edge(w,x)
    e3 = Edge(v,x)

    # Query for edge from an empty graph
    self.assertEqual(g.get_edge(v, w), None)

    # Query for a non existent edge with one vertex present
    g.clear()
    g.add_vertex(v)
    self.assertEqual(g.get_edge(v, w), None)

    # Query for a non existent edge with both vertices present
    g.clear()
    g.add_vertex(v)
    g.add_vertex(w)
    self.assertEqual(g.get_edge(v, w), None)

    # Query for an existent edge
    g.clear()
    g.add_edge(e1)
    g.add_edge(e2)
    self.assertEqual(g.get_edge(v,w), e1)
开发者ID:shubhamgupta30,项目名称:think_bayes,代码行数:30,代码来源:Graph_test.py

示例5: test_add_edge

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import clear [as 别名]
  def test_add_edge(self):
    g = Graph()
    v = Vertex('label1')
    w = Vertex('label2')
    e = Edge(v,w)

    # Without adding both vertices
    g.add_edge(e)
    self.assertEqual(g, {v:{w:e}, w:{v:e}})
    g.clear();

    # Without adding one vertex
    g.add_vertex(v)
    g.add_edge(e)
    self.assertEqual(g, {v:{w:e}, w:{v:e}})
    g.clear();

    # After Adding both vertices
    g.add_vertex(v)
    g.add_vertex(w)
    g.add_edge(e)
    self.assertEqual(g, {v:{w:e}, w:{v:e}})
开发者ID:shubhamgupta30,项目名称:think_bayes,代码行数:24,代码来源:Graph_test.py


注:本文中的Graph.Graph.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。