public void GivenSingleSourceSingleDestinationWhenFindMaximumFlowThenWorksFine() { // arrange var source = new SimpleNode("START"); var destination = new SimpleNode("DESTINATION"); var arcs = new List <IArcWithFlow <SimpleNode> > { new SimpleArcWithFlow <SimpleNode>(source, destination, 1), }; // act & assert Assert.DoesNotThrow(() => arcs.FindMaximumFlow()); }
public void GivenCycledLoopsWhenTryToFindMaximumFlowThenThrowError() { // arrange var a = new SimpleNode("A"); var b = new SimpleNode("B"); var arcs = new List <IArcWithFlow <SimpleNode> > { new SimpleArcWithFlow <SimpleNode>(a, b, 1), new SimpleArcWithFlow <SimpleNode>(b, a, 1), }; // act & assert Assert.Throws <ArgumentException>(() => arcs.FindMaximumFlow()); }
public void GivenTwoDestinationsWhenTryToFindMaximumFlowThenThrowError() { // arrange var source = new SimpleNode("START"); var destination1 = new SimpleNode("DESTINATION_1"); var destination2 = new SimpleNode("DESTINATION_2"); var arcs = new List <IArcWithFlow <SimpleNode> > { new SimpleArcWithFlow <SimpleNode>(source, destination1, 1), new SimpleArcWithFlow <SimpleNode>(source, destination2, 1), }; // act & assert Assert.Throws <ArgumentException>(() => arcs.FindMaximumFlow()); }
public void GivenOneArcWhenFindMaximumFlowThenReturnItsFlow() { // arrange var source = new SimpleNode("START"); var destination = new SimpleNode("DESTINATION"); var arcs = new List <IArcWithFlow <SimpleNode> > { new SimpleArcWithFlow <SimpleNode>(source, destination, 123), }; // act double maxFlow = arcs.FindMaximumFlow(source, destination); // assert Assert.AreEqual(123, maxFlow); }
public void GivenNoArcsFromStartWhenFindShortestPathsThenReturnEmpty() { // arrange var start = new SimpleNode("START"); var a = new SimpleNode("A"); var b = new SimpleNode("B"); var arcs = new IArcWithLength <SimpleNode>[] { new SimpleArcWithLength <SimpleNode>(a, b, 10), }; // act var foundPaths = arcs.FindShortestPaths(start); // assert Assert.AreEqual(0, foundPaths.Count); }
public void GivenParallelArcsWhenFindMaximumFlowThenReturnTheirSummary() { // arrange var source = new SimpleNode("START"); var destination = new SimpleNode("DESTINATION"); var arcs = new List <IArcWithFlow <SimpleNode> > { new SimpleArcWithFlow <SimpleNode>(source, destination, 123), new SimpleArcWithFlow <SimpleNode>(source, destination, 456), new SimpleArcWithFlow <SimpleNode>(source, destination, 789), }; // act double maxFlow = arcs.FindMaximumFlow(source, destination); // assert Assert.AreEqual(123 + 456 + 789, maxFlow); }
public void GivenLinearChainWhenFindMaximumFlowThenReturnMinimumFlow() { // arrange var a = new SimpleNode("A"); var b = new SimpleNode("B"); var c = new SimpleNode("C"); var d = new SimpleNode("D"); var arcs = new List <IArcWithFlow <SimpleNode> > { new SimpleArcWithFlow <SimpleNode>(a, b, 567), new SimpleArcWithFlow <SimpleNode>(b, c, 123), new SimpleArcWithFlow <SimpleNode>(c, d, 234), }; // act double maxFlow = arcs.FindMaximumFlow(a, d); // assert Assert.AreEqual(123, maxFlow); }
public void GivenChainWhenFindShortestPathsThenReturnSimple() { // arrange var start = new SimpleNode("START"); var a = new SimpleNode("A"); var b = new SimpleNode("B"); var c = new SimpleNode("C"); var arcs = new IArcWithLength <SimpleNode>[] { new SimpleArcWithLength <SimpleNode>(start, a, 1), new SimpleArcWithLength <SimpleNode>(a, b, 2), new SimpleArcWithLength <SimpleNode>(b, c, 3), }; // act var foundPaths = arcs.FindShortestPaths(start); // assert Assert.AreEqual(3, foundPaths.Count); Assert.AreEqual(1, foundPaths.First(p => p.To == a).Lenght); Assert.AreEqual(3, foundPaths.First(p => p.To == b).Lenght); Assert.AreEqual(6, foundPaths.First(p => p.To == c).Lenght); }
private static ulong getWeight(SimpleNode item) { return(item.Weight); }