public void ReturnsGraphEdgeCounterObject() { int[,] array = { { 0, 1 }, { 1, 0 } }; Graph graph = new Graph(array); GraphEdgeCounter edgeCounter = new GraphEdgeCounter(graph); Assert.IsNotNull(edgeCounter); }
public void ThrowsExceptionWhenPassingGraphNullReference() { Graph graph = null; GraphEdgeCounter edgeCounter; Assert.Throws(typeof(ArgumentNullException), () => { edgeCounter = new GraphEdgeCounter(graph); }); }
public void CountsGraphEdgesConcurrentlyMoreThanOnce() { int[,] array = { { 0, 1 }, { 1, 0 } }; Graph graph = new Graph(array); GraphEdgeCounter edgeCounter = new GraphEdgeCounter(graph); edgeCounter.CountConcurrently(); Assert.DoesNotThrow(() => edgeCounter.CountConcurrently()); }
public void CountsGraphEdgesConcurrently() { int[,] array = { { 0, 1 }, { 1, 0 } }; Graph graph = new Graph(array); GraphEdgeCounter edgeCounter = new GraphEdgeCounter(graph); int numberOfEdges = edgeCounter.CountConcurrently(); Assert.AreEqual(2, numberOfEdges); }
static void Main(string[] args) { int numberOfVertices; Console.WriteLine("Enter the number of vertices: "); numberOfVertices = int.Parse(Console.ReadLine()); GraphArrayGenerator generator = new GraphArrayGenerator(); Graph graph = new Graph(generator.GenerateConcurrently(numberOfVertices)); if (numberOfVertices < 16) Console.WriteLine("Graph\n{0}\n", graph.ToString()); GraphEdgeCounter counter = new GraphEdgeCounter(graph); Stopwatch watch = new Stopwatch(); watch.Start(); int numberOfEdges = counter.Count(); watch.Stop(); Console.WriteLine("Number of edges: {0}\nTime(ms): {1}\n\n", numberOfEdges, watch.ElapsedMilliseconds); watch.Restart(); numberOfEdges = counter.CountConcurrently(); watch.Stop(); Console.WriteLine("Multi-threaded\nNumber of edges: {0}\nTime(ms): {1}", numberOfEdges, watch.ElapsedMilliseconds); Console.Read(); }