public void GetNeigborsCollectionTest(string expected, int index) { Graph.Classes.Graph graph = new Graph.Classes.Graph(); Node parent = new Node(); parent.Value = "A"; LinkedList <Tuple <Node, int> > originList = new LinkedList <Tuple <Node, int> >(); Tuple <Node, int> origin = new Tuple <Node, int>(parent, 0); originList.AddFirst(origin); graph.AdjacencyList.AddFirst(originList); Node child = new Node(); child.Value = "B"; graph.AddEdge(parent, new Tuple <Node, int>(child, 5)); Node c = new Node(); c.Value = "C"; graph.AddEdge(parent, new Tuple <Node, int>(c, 4)); var nodeList = graph.GetNeighbors(parent); Assert.Equal(expected, nodeList[index].Item1.Value); }
public void SizeTest() { Graph.Classes.Graph graph = new Graph.Classes.Graph(); Node parent = new Node(); parent.Value = "A"; LinkedList <Tuple <Node, int> > originList = new LinkedList <Tuple <Node, int> >(); Tuple <Node, int> origin = new Tuple <Node, int>(parent, 0); originList.AddFirst(origin); graph.AdjacencyList.AddFirst(originList); Node child = new Node(); child.Value = "B"; graph.AddEdge(parent, new Tuple <Node, int>(child, 5)); Node c = new Node(); c.Value = "C"; graph.AddEdge(parent, new Tuple <Node, int>(c, 4)); int count = graph.Size(); Assert.Equal(3, count); }
public void NeighborsCountTest() { Graph.Classes.Graph graph = new Graph.Classes.Graph(); Node parent = new Node(); parent.Value = "A"; LinkedList <Tuple <Node, int> > originList = new LinkedList <Tuple <Node, int> >(); Tuple <Node, int> origin = new Tuple <Node, int>(parent, 0); originList.AddFirst(origin); graph.AdjacencyList.AddFirst(originList); Node child = new Node(); child.Value = "B"; graph.AddEdge(parent, new Tuple <Node, int>(child, 5)); Node c = new Node(); c.Value = "C"; graph.AddEdge(parent, new Tuple <Node, int>(c, 4)); var nodeList = graph.GetNeighbors(parent); Assert.Equal(2, nodeList.Count); }
public void GetNodesTestNull() { Graph.Classes.Graph graph = new Graph.Classes.Graph(); var nodes = graph.GetNodes(); Assert.Empty(nodes); }
static void Main(string[] args) { Console.WriteLine("Hello Graphs"); Console.WriteLine(""); List <object> listTest = new List <object>(); listTest.Add("soloNode"); Graph.Classes.Graph graph = new Graph.Classes.Graph(listTest); graph.AddEdge("Apple", "Banana", 10); graph.AddEdge("Dog", "Cat", 22); graph.AddEdge("xBox", "PlayStation", 7); Console.WriteLine("Creating a new graph with 7 nodes and 3 edges"); Console.WriteLine($"Return size of graph: {graph.Size()}"); Dictionary <object, int> toNeighbor = graph.GetNeighbors("Dog"); Dictionary <object, int> fromNeighbor = graph.GetNeighbors("xBox"); //Console.WriteLine($"Return neighbor of graph from Dog node:"); foreach (var item in toNeighbor.Values) { //Console.WriteLine(item); } Console.WriteLine("Return all vertices in the graph: "); foreach (var item in graph.Vertices) { Console.WriteLine(item.Value); } Console.ReadLine(); }
public void TestAddNode() { Graph.Classes.Graph testGraph1 = new Graph.Classes.Graph(); //GraphNode testNode1 = new GraphNode(5); testGraph1.AddNode(5); Assert.Equal(5, testGraph1.AdjList[0].Value); }
public void NullSizeTest() { Graph.Classes.Graph graph = new Graph.Classes.Graph(); int count = graph.Size(); Assert.Equal(0, count); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); Graph.Classes.Graph graph = new Graph.Classes.Graph(); Node parent = new Node(); parent.Value = "A"; LinkedList <Tuple <Node, int> > originList = new LinkedList <Tuple <Node, int> >(); Tuple <Node, int> origin = new Tuple <Node, int>(parent, 0); originList.AddFirst(origin); graph.AdjacencyList.AddFirst(originList); Node child = new Node(); child.Value = "B"; graph.AddEdge(parent, new Tuple <Node, int>(child, 5)); Node c = new Node(); c.Value = "C"; graph.AddEdge(parent, new Tuple <Node, int>(c, 4)); foreach (var item in graph.AdjacencyList) { foreach (var node in item) { Console.Write(node.Item2); Console.WriteLine(node.Item1.Value); } } var nodeList = graph.GetNodes(); foreach (var item in nodeList) { Console.Write(item.Value); } var neighbor = graph.GetNeighbors(parent); foreach (var item in neighbor) { Console.Write(item.Item1.Value); Console.WriteLine(item.Item2); } var count = graph.Size(); Console.WriteLine(count); Console.ReadKey(); }
public void GetSizeEmpty() { List <object> listTest = new List <object>(); Graph.Classes.Graph graph = new Graph.Classes.Graph(listTest); graph.Size(); Assert.Equal(0, graph.Size()); }
public void GetSizeTwo() { List <object> listTest = new List <object>(); listTest.Add("Dog"); Graph.Classes.Graph graph = new Graph.Classes.Graph(listTest); graph.Size(); Assert.Equal(1, graph.Size()); }
public void GetSizeOne() { List <object> listTest = new List <object>(); Graph.Classes.Graph graph = new Graph.Classes.Graph(listTest); graph.AddEdge("Apple", "Banana", 10); graph.Size(); Assert.Equal(2, graph.Size()); }
public void GetEdgeTestMoney() { Graph.Classes.Graph graphItinerary = new Graph.Classes.Graph(); Node Pandora = new Node(); Pandora.Value = "Pandora"; Node Arendelle = new Node(); Arendelle.Value = "Arendelle"; Node Metroville = new Node(); Metroville.Value = "Metroville"; Node Monstropolis = new Node(); Monstropolis.Value = "Monstropolis"; Node Narnia = new Node(); Narnia.Value = "Narnia"; Node Naboo = new Node(); Naboo.Value = "Naboo"; LinkedList <Tuple <Node, int> > originList = new LinkedList <Tuple <Node, int> >(); Tuple <Node, int> origin = new Tuple <Node, int>(Pandora, 0); originList.AddFirst(origin); graphItinerary.AdjacencyList.AddFirst(originList); graphItinerary.AddEdge(Pandora, new Tuple <Node, int>(Arendelle, 150)); graphItinerary.AddEdge(Pandora, new Tuple <Node, int>(Metroville, 82)); graphItinerary.AddEdge(Arendelle, new Tuple <Node, int>(Metroville, 99)); graphItinerary.AddEdge(Arendelle, new Tuple <Node, int>(Monstropolis, 42)); graphItinerary.AddEdge(Monstropolis, new Tuple <Node, int>(Metroville, 105)); graphItinerary.AddEdge(Monstropolis, new Tuple <Node, int>(Naboo, 73)); graphItinerary.AddEdge(Naboo, new Tuple <Node, int>(Metroville, 26)); graphItinerary.AddEdge(Naboo, new Tuple <Node, int>(Narnia, 250)); graphItinerary.AddEdge(Narnia, new Tuple <Node, int>(Metroville, 37)); Node[] cities = new Node[3] { Pandora, Metroville, Narnia }; var output = GetEdge(graphItinerary, cities); Assert.Equal("$119.00", output.Item2); }
public void NeighborsNullTest() { Graph.Classes.Graph graph = new Graph.Classes.Graph(); Node parent = new Node(); parent.Value = "A"; var nodeList = graph.GetNeighbors(parent); Assert.Empty(nodeList); }
public void GetNeighbots(object to, object from, int weight) { List <object> listTest = new List <object>(); Graph.Classes.Graph graph = new Graph.Classes.Graph(listTest); graph.AddEdge(to, from, weight); Dictionary <object, int> toNeighbor = graph.GetNeighbors(to); Dictionary <object, int> fromNeighbor = graph.GetNeighbors(from); Assert.True(toNeighbor.ContainsValue(weight) && fromNeighbor.ContainsValue(weight)); }
public void GetAllNodes(object one, object two, object three) { List <object> listTest = new List <object>(); listTest.Add(one); listTest.Add(two); listTest.Add(three); Graph.Classes.Graph graphTest = new Graph.Classes.Graph(listTest); List <Vertex> vertices = graphTest.GetNodes(); //Assert.Equal(graphTest.GetNodes()[two].Value, one); Assert.True(listTest[0] == vertices[0].Value && listTest[1] == vertices[1].Value && listTest[2] == vertices[2].Value); }
public void GetSizeThree() { List <object> listTest = new List <object>(); listTest.Add("Dog"); listTest.Add("Cat"); listTest.Add("Chocolate"); listTest.Add("Banana"); Graph.Classes.Graph graph = new Graph.Classes.Graph(listTest); graph.AddEdge("Peach", "Orange", 10); graph.Size(); Assert.Equal(6, graph.Size()); }
public void NullTest() { Graph.Classes.Graph graph = new Graph.Classes.Graph(); Node parent = new Node(); parent.Value = "A"; Node child = new Node(); child.Value = "B"; graph.AddEdge(parent, new Tuple <Node, int>(child, 5)); Assert.Empty(graph.AdjacencyList); }
public void AddEdgeTestBAddedtoA() { Graph.Classes.Graph graph = new Graph.Classes.Graph(); Node parent = new Node(); parent.Value = "A"; LinkedList <Tuple <Node, int> > originList = new LinkedList <Tuple <Node, int> >(); Tuple <Node, int> origin = new Tuple <Node, int>(parent, 0); originList.AddFirst(origin); graph.AdjacencyList.AddFirst(originList); Node child = new Node(); child.Value = "B"; graph.AddEdge(parent, new Tuple <Node, int>(child, 5)); Assert.Equal(parent, graph.AdjacencyList.Last.Value.Last.Value.Item1); }
/// <summary> /// checks if direct flight is possible /// </summary> /// <param name="graph">graph of cities</param> /// <param name="cities">city iternary</param> /// <returns>tuple contain bool and string in money format</returns> public static Tuple <bool, string> GetEdge(Graph.Classes.Graph graph, Node[] cities) { if (cities.Length <= 1 || graph.AdjacencyList.Count == 0) { return(new Tuple <bool, string>(false, 0.ToString("C2"))); } int money = 0; bool exists = true; Tuple <bool, string> costs = new Tuple <bool, string> (exists, money.ToString("C2")); for (int i = 0; i < cities.Length - 1; i++) { List <Tuple <Node, int> > neighborNodes = graph.GetNeighbors(cities[i]); foreach (var item in neighborNodes) { exists = false; if (item.Item1 == cities[i + 1]) { money += item.Item2; exists = true; } if (exists) { break; } } if (!exists) { break; } } if (!exists) { return(new Tuple <bool, string>(exists, 0.ToString("C2"))); } else { return(new Tuple <bool, string>(exists, money.ToString("C2"))); } }
public void SizeTestLarge() { Graph.Classes.Graph graph = new Graph.Classes.Graph(); Node parent = new Node(); parent.Value = "A"; LinkedList <Tuple <Node, int> > originList = new LinkedList <Tuple <Node, int> >(); Tuple <Node, int> origin = new Tuple <Node, int>(parent, 0); originList.AddFirst(origin); graph.AdjacencyList.AddFirst(originList); Node child = new Node(); child.Value = "B"; graph.AddEdge(parent, new Tuple <Node, int>(child, 5)); Node c = new Node(); c.Value = "C"; Node d = new Node(); d.Value = "D"; Node e = new Node(); e.Value = "E"; Node f = new Node(); f.Value = "F"; Node g = new Node(); g.Value = "G"; Node h = new Node(); h.Value = "H"; Node i = new Node(); i.Value = "I"; Node j = new Node(); j.Value = "J"; graph.AddEdge(parent, new Tuple <Node, int>(c, 4)); graph.AddEdge(parent, new Tuple <Node, int>(d, 4)); graph.AddEdge(parent, new Tuple <Node, int>(e, 4)); graph.AddEdge(parent, new Tuple <Node, int>(f, 4)); graph.AddEdge(parent, new Tuple <Node, int>(g, 4)); graph.AddEdge(parent, new Tuple <Node, int>(h, 4)); graph.AddEdge(parent, new Tuple <Node, int>(i, 4)); graph.AddEdge(parent, new Tuple <Node, int>(j, 4)); int count = graph.Size(); Assert.Equal(10, count); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); Graph.Classes.Graph graphItinerary = new Graph.Classes.Graph(); Node Pandora = new Node(); Pandora.Value = "Pandora"; Node Arendelle = new Node(); Arendelle.Value = "Arendelle"; Node Metroville = new Node(); Metroville.Value = "Metroville"; Node Monstropolis = new Node(); Monstropolis.Value = "Monstropolis"; Node Narnia = new Node(); Narnia.Value = "Narnia"; Node Naboo = new Node(); Naboo.Value = "Naboo"; LinkedList <Tuple <Node, int> > originList = new LinkedList <Tuple <Node, int> >(); Tuple <Node, int> origin = new Tuple <Node, int>(Pandora, 0); originList.AddFirst(origin); graphItinerary.AdjacencyList.AddFirst(originList); graphItinerary.AddEdge(Pandora, new Tuple <Node, int>(Arendelle, 150)); graphItinerary.AddEdge(Pandora, new Tuple <Node, int>(Metroville, 82)); graphItinerary.AddEdge(Arendelle, new Tuple <Node, int>(Metroville, 99)); graphItinerary.AddEdge(Arendelle, new Tuple <Node, int>(Monstropolis, 42)); graphItinerary.AddEdge(Monstropolis, new Tuple <Node, int>(Metroville, 105)); graphItinerary.AddEdge(Monstropolis, new Tuple <Node, int>(Naboo, 73)); graphItinerary.AddEdge(Naboo, new Tuple <Node, int>(Metroville, 26)); graphItinerary.AddEdge(Naboo, new Tuple <Node, int>(Narnia, 250)); graphItinerary.AddEdge(Narnia, new Tuple <Node, int>(Metroville, 37)); Node[] cities = new Node[3] { Pandora, Metroville, Narnia }; for (int i = 0; i < cities.Length; i++) { Console.Write($"{cities[i].Value} "); } Console.WriteLine(); var output = GetEdge(graphItinerary, cities); Console.WriteLine(output.Item1); Console.WriteLine(output.Item2); Console.ReadKey(); }