using System; using NUnit.Framework; using System.Collections.Generic; namespace Algorithms.Tests.Graph { [TestFixture] public class Dijkstra { static object[] TestCasesForDijkstra = { new object[] { 5, false, 1, 5, new List> { new Tuple(1, 2, 2), new Tuple(2, 5, 5), new Tuple(2, 3, 4), new Tuple(1, 4, 1), new Tuple(4, 3, 3), new Tuple(3, 5, 1) }, 5 }, new object[] { 5, true, 1, 5, new List> { new Tuple(1, 2, 2), new Tuple(2, 5, 8), new Tuple(2, 3, 4), new Tuple(4, 1, 1), new Tuple(3, 4, 3), new Tuple(3, 5, 1) }, 7 }, new object[] { 3, false, 1, 3, new List> { new Tuple(1, 2, 1) }, -1 }, }; [TestCaseSource(nameof(TestCasesForDijkstra))] public void TestDijkstra_ShouldGetExpectedResult(int totalNodes, bool isDirected, int source, int destination, List> edges, int expected) { var result = Algorithms.Graph.Dijkstra.RunDijkstra(totalNodes, isDirected, source, destination, edges); int distance = (int)result.GetType().GetProperty("distance").GetValue(result, null); Assert.AreEqual(expected, distance); } } }