Example #1
0
        public void Valid_Path_Found_BFS()
        {
            DictionaryGraph dictionaryGraph = new DictionaryGraph(_simpleDictionary, 3, new BreadthFirstSearch());
            string          searchResult    = dictionaryGraph.GetShortestPath("dog", "hot");

            Assert.AreEqual(searchResult, "dog,hog,hot");
        }
Example #2
0
        public void Word_Not_In_Dictionary_BFS()
        {
            DictionaryGraph dictionaryGraph = new DictionaryGraph(_simpleDictionary, 3, new BreadthFirstSearch());
            string          searchResult    = dictionaryGraph.GetShortestPath("dog", "cat");

            Assert.AreEqual(searchResult, "cat was not found in the dictionary");
        }
Example #3
0
 public void AddToQueue(string name)
 {
     if (DictionaryGraph.ContainsKey(name))
     {
         DictionaryGraph[name].ForEach(delegate(String element)
         {
             SearchQueue.Enqueue(element);
         });
         return;
     }
 }
Example #4
0
        public void Valid_Graph_Created()
        {
            DictionaryGraph dictionaryGraph = new DictionaryGraph(_simpleDictionary, 3, new BreadthFirstSearch());
            Node            dogNode         = dictionaryGraph.Graph.FirstOrDefault(n => n.Value == "dog");
            Node            hogNode         = dictionaryGraph.Graph.FirstOrDefault(n => n.Value == "hog");
            Node            hotNode         = dictionaryGraph.Graph.FirstOrDefault(n => n.Value == "hot");
            Node            joyNode         = dictionaryGraph.Graph.FirstOrDefault(n => n.Value == "joy");

            Assert.True(dogNode.ConnectedNodes.Count == 1);
            Assert.True(hogNode.ConnectedNodes.Count == 2);
            Assert.True(hotNode.ConnectedNodes.Count == 1);
            Assert.True(joyNode.ConnectedNodes.Count == 0);
        }
        public void WriteDictionaryTest()
        {
            var graph = new DictionaryGraph {
                Value = new Dictionary <int, string> {
                    { 2, "Test" }
                }
            };
            var actual = _context.SerializeAndDeserialize(graph);

            Assert.NotNull(actual.Value);
            Assert.Equal(1, actual.Value.Count);

            var firstActual = actual.Value.First();

            Assert.Equal(2, firstActual.Key);
            Assert.Equal("Test", firstActual.Value);
        }