本文整理汇总了C#中Graph.ContainsEdges方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.ContainsEdges方法的具体用法?C# Graph.ContainsEdges怎么用?C# Graph.ContainsEdges使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph.ContainsEdges方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestArguments
public void TestArguments()
{
using (var graph = new Graph<Edge>(new MemoryMappedStream(new MemoryStream()), 1000,
Edge.MapFromDelegate, Edge.MapToDelegate, Edge.SizeUints))
{
uint vertex1 = graph.AddVertex(0, 0);
uint vertex2 = graph.AddVertex(0, 0);
uint vertex3 = 3;
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.AddEdge(vertex3, vertex1, new Edge(), null);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.AddEdge(vertex1, vertex3, new Edge(), null);
});
Assert.Catch<ArgumentException>(() =>
{
graph.AddEdge(vertex1, vertex1, new Edge(), null);
});
Assert.Catch<ArgumentException>(() =>
{
graph.AddEdge(vertex1, vertex1, new Edge(), null);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.ContainsEdges(vertex3, vertex1);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.ContainsEdges(vertex1, vertex3);
});
Edge edge;
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.GetEdge(vertex3, vertex1, out edge);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.GetEdge(vertex1, vertex3, out edge);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.GetEdges(vertex3);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.SetVertex(vertex3, 10, 10);
});
}
}
示例2: TestGraphArguments
public void TestGraphArguments()
{
// create graph with one vertex and start adding vertex2.
var graph = new Graph<Edge>();
uint vertex1 = graph.AddVertex(0, 0);
uint vertex2 = graph.AddVertex(0, 0);
uint vertex3 = 3;
Assert.Catch<ArgumentOutOfRangeException>(() => {
graph.AddEdge(vertex3, vertex1, new Edge(), null);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.AddEdge(vertex1, vertex3, new Edge(), null);
});
Assert.Catch<ArgumentException>(() =>
{
graph.AddEdge(vertex1, vertex1, new Edge(), null);
});
Assert.Catch<ArgumentException>(() =>
{
graph.AddEdge(vertex1, vertex1, new Edge(), null);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.ContainsEdges(vertex3, vertex1);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.ContainsEdges(vertex1, vertex3);
});
Edge edge;
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.GetEdge(vertex3, vertex1, out edge);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.GetEdge(vertex1, vertex3, out edge);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.GetEdges(vertex3);
});
Assert.Catch<ArgumentOutOfRangeException>(() =>
{
graph.SetVertex(vertex3, 10, 10);
});
}
示例3: TestGraphCompressEdges
public void TestGraphCompressEdges()
{
var graph = new Graph<Edge>();
var vertex1 = graph.AddVertex(51, 1);
var vertex2 = graph.AddVertex(51, 2);
var vertex3 = graph.AddVertex(51, 3);
var vertex4 = graph.AddVertex(51, 3);
graph.AddEdge(vertex1, vertex2, new Edge()
{
Forward = true,
Tags = 1
}, null);
graph.AddEdge(vertex2, vertex3, new Edge()
{
Forward = true,
Tags = 2
}, null);
graph.AddEdge(vertex3, vertex4, new Edge()
{
Forward = true,
Tags = 3
}, null);
graph.AddEdge(vertex4, vertex2, new Edge()
{
Forward = true,
Tags = 4
}, null);
graph.RemoveEdge(vertex2, vertex3);
graph.Compress();
Assert.IsFalse(graph.ContainsEdges(vertex2, vertex3));
Assert.IsFalse(graph.ContainsEdges(vertex3, vertex2));
Assert.AreEqual(graph.GetEdges(vertex1).ToKeyValuePairs().Length, 1);
Assert.AreEqual(graph.GetEdges(vertex2).ToKeyValuePairs().Length, 2);
Assert.AreEqual(graph.GetEdges(vertex3).ToKeyValuePairs().Length, 1);
Assert.AreEqual(graph.GetEdges(vertex4).ToKeyValuePairs().Length, 2);
graph = new Graph<Edge>();
vertex1 = graph.AddVertex(51, 1);
vertex2 = graph.AddVertex(51, 2);
vertex3 = graph.AddVertex(51, 3);
vertex4 = graph.AddVertex(51, 3);
graph.AddEdge(vertex1, vertex2, new Edge()
{
Forward = true,
Tags = 1
}, null);
graph.AddEdge(vertex2, vertex3, new Edge()
{
Forward = true,
Tags = 2
}, null);
graph.AddEdge(vertex3, vertex4, new Edge()
{
Forward = true,
Tags = 3
}, null);
graph.AddEdge(vertex4, vertex2, new Edge()
{
Forward = true,
Tags = 4
}, null);
graph.RemoveEdge(vertex3, vertex4);
graph.Compress();
Assert.IsFalse(graph.ContainsEdges(vertex3, vertex4));
Assert.IsFalse(graph.ContainsEdges(vertex4, vertex3));
Assert.AreEqual(graph.GetEdges(vertex1).ToKeyValuePairs().Length, 1);
Assert.AreEqual(graph.GetEdges(vertex2).ToKeyValuePairs().Length, 3);
Assert.AreEqual(graph.GetEdges(vertex3).ToKeyValuePairs().Length, 1);
Assert.AreEqual(graph.GetEdges(vertex4).ToKeyValuePairs().Length, 1);
Edge edge;
Assert.IsTrue(graph.GetEdge(vertex1, vertex2, out edge));
Assert.AreEqual(1, edge.Tags);
Assert.IsTrue(graph.GetEdge(vertex2, vertex3, out edge));
Assert.AreEqual(2, edge.Tags);
Assert.IsTrue(graph.GetEdge(vertex4, vertex2, out edge));
Assert.AreEqual(4, edge.Tags);
}
示例4: TestGraphRemoveAllOneVertex
public void TestGraphRemoveAllOneVertex()
{
var graph = new Graph<Edge>();
var vertex1 = graph.AddVertex(51, 1);
var vertex2 = graph.AddVertex(51, 2);
var vertex3 = graph.AddVertex(51, 3);
var vertex4 = graph.AddVertex(51, 3);
graph.AddEdge(vertex1, vertex2, new Edge()
{
Forward = true,
Tags = 1
});
graph.AddEdge(vertex2, vertex3, new Edge()
{
Forward = true,
Tags = 2
});
graph.AddEdge(vertex3, vertex4, new Edge()
{
Forward = true,
Tags = 3
});
graph.AddEdge(vertex4, vertex2, new Edge()
{
Forward = true,
Tags = 4
});
graph.RemoveEdges(vertex2);
Assert.IsFalse(graph.ContainsEdges(vertex2, vertex1));
Assert.IsFalse(graph.ContainsEdges(vertex2, vertex3));
Assert.IsFalse(graph.ContainsEdges(vertex4, vertex2));
Assert.IsTrue(graph.ContainsEdges(vertex3, vertex4));
}
示例5: TestGraphRemoveBegin
public void TestGraphRemoveBegin()
{
var graph = new Graph<Edge>();
var vertex1 = graph.AddVertex(51, 1);
var vertex2 = graph.AddVertex(51, 2);
var vertex3 = graph.AddVertex(51, 3);
var vertex4 = graph.AddVertex(51, 3);
graph.AddEdge(vertex1, vertex2, new Edge()
{
Forward = true,
Tags = 1
}, null);
graph.AddEdge(vertex2, vertex3, new Edge()
{
Forward = true,
Tags = 2
}, null);
graph.AddEdge(vertex3, vertex4, new Edge()
{
Forward = true,
Tags = 3
}, null);
graph.AddEdge(vertex4, vertex2, new Edge()
{
Forward = true,
Tags = 4
}, null);
graph.RemoveEdge(vertex2, vertex1);
Assert.IsFalse(graph.ContainsEdges(vertex2, vertex1));
Assert.IsFalse(graph.ContainsEdges(vertex1, vertex2));
Assert.AreEqual(graph.GetEdges(vertex1).ToKeyValuePairs().Length, 0);
Assert.AreEqual(graph.GetEdges(vertex2).ToKeyValuePairs().Length, 2);
Assert.AreEqual(graph.GetEdges(vertex3).ToKeyValuePairs().Length, 2);
Assert.AreEqual(graph.GetEdges(vertex4).ToKeyValuePairs().Length, 2);
}
示例6: TestCompressEdges
public void TestCompressEdges()
{
using (var graph = new Graph<Edge>(new MemoryMappedStream(new MemoryStream()), 1000,
Edge.MapFromDelegate, Edge.MapToDelegate, Edge.SizeUints))
{
var vertex1 = graph.AddVertex(51, 1);
var vertex2 = graph.AddVertex(51, 2);
var vertex3 = graph.AddVertex(51, 3);
var vertex4 = graph.AddVertex(51, 3);
graph.AddEdge(vertex1, vertex2, new Edge()
{
Forward = true,
Tags = 1
}, null);
graph.AddEdge(vertex2, vertex3, new Edge()
{
Forward = true,
Tags = 2
}, null);
graph.AddEdge(vertex3, vertex4, new Edge()
{
Forward = true,
Tags = 3
}, null);
graph.AddEdge(vertex4, vertex2, new Edge()
{
Forward = true,
Tags = 4
}, null);
graph.RemoveEdge(vertex2, vertex3);
graph.Compress();
Assert.IsFalse(graph.ContainsEdges(vertex2, vertex3));
Assert.IsFalse(graph.ContainsEdges(vertex3, vertex2));
Assert.AreEqual(graph.GetEdges(vertex1).ToKeyValuePairs().Length, 1);
Assert.AreEqual(graph.GetEdges(vertex2).ToKeyValuePairs().Length, 2);
Assert.AreEqual(graph.GetEdges(vertex3).ToKeyValuePairs().Length, 1);
Assert.AreEqual(graph.GetEdges(vertex4).ToKeyValuePairs().Length, 2);
}
using (var graph = new Graph<Edge>(new MemoryMappedStream(new MemoryStream()), 1000,
Edge.MapFromDelegate, Edge.MapToDelegate, Edge.SizeUints))
{
uint vertex1 = graph.AddVertex(51, 1);
uint vertex2 = graph.AddVertex(51, 2);
uint vertex3 = graph.AddVertex(51, 3);
uint vertex4 = graph.AddVertex(51, 3);
graph.AddEdge(vertex1, vertex2, new Edge()
{
Forward = true,
Tags = 1
}, null);
graph.AddEdge(vertex2, vertex3, new Edge()
{
Forward = true,
Tags = 2
}, null);
graph.AddEdge(vertex3, vertex4, new Edge()
{
Forward = true,
Tags = 3
}, null);
graph.AddEdge(vertex4, vertex2, new Edge()
{
Forward = true,
Tags = 4
}, null);
graph.RemoveEdge(vertex3, vertex4);
graph.Compress();
Assert.IsFalse(graph.ContainsEdges(vertex3, vertex4));
Assert.IsFalse(graph.ContainsEdges(vertex4, vertex3));
Assert.AreEqual(graph.GetEdges(vertex1).ToKeyValuePairs().Length, 1);
Assert.AreEqual(graph.GetEdges(vertex2).ToKeyValuePairs().Length, 3);
Assert.AreEqual(graph.GetEdges(vertex3).ToKeyValuePairs().Length, 1);
Assert.AreEqual(graph.GetEdges(vertex4).ToKeyValuePairs().Length, 1);
Edge edge;
Assert.IsTrue(graph.GetEdge(vertex1, vertex2, out edge));
Assert.AreEqual(1, edge.Tags);
Assert.IsTrue(graph.GetEdge(vertex2, vertex3, out edge));
Assert.AreEqual(2, edge.Tags);
Assert.IsTrue(graph.GetEdge(vertex4, vertex2, out edge));
Assert.AreEqual(4, edge.Tags);
}
}
示例7: TestRemoveAllOneVertex
public void TestRemoveAllOneVertex()
{
using (var graph = new Graph<Edge>(new MemoryMappedStream(new MemoryStream()), 1000,
Edge.MapFromDelegate, Edge.MapToDelegate, Edge.SizeUints))
{
var vertex1 = graph.AddVertex(51, 1);
var vertex2 = graph.AddVertex(51, 2);
var vertex3 = graph.AddVertex(51, 3);
var vertex4 = graph.AddVertex(51, 3);
graph.AddEdge(vertex1, vertex2, new Edge()
{
Forward = true,
Tags = 1
});
graph.AddEdge(vertex2, vertex3, new Edge()
{
Forward = true,
Tags = 2
});
graph.AddEdge(vertex3, vertex4, new Edge()
{
Forward = true,
Tags = 3
});
graph.AddEdge(vertex4, vertex2, new Edge()
{
Forward = true,
Tags = 4
});
graph.RemoveEdges(vertex2);
Assert.IsFalse(graph.ContainsEdges(vertex2, vertex1));
Assert.IsFalse(graph.ContainsEdges(vertex2, vertex3));
Assert.IsFalse(graph.ContainsEdges(vertex4, vertex2));
Assert.IsTrue(graph.ContainsEdges(vertex3, vertex4));
}
}