Пример #1
0
        /// <summary>
        /// Processa a busca da palavra
        /// </summary>
        /// <param name="word"></param>
        private static void ProcessWord(string word)
        {
            WordSearchService service = new WordSearchService(dictRepository);

            ProcessResult processResult = service.SearchWord(word);

            FormatOutput(word, processResult);
        }
Пример #2
0
        /// <summary>
        /// Processa a busca da palavra
        /// </summary>
        /// <param name="word"></param>
        private static void ProcessWord(string word)
        {
            WordSearchService service = new WordSearchService(dictRepository);

            ProcessResult processResult = service.SearchWord(word);

            FormatOutput(word, processResult);
        }
        public void WordSearchService_SearchInvalidWord_RendersNotFound()
        {
            // arrange
            string word = "x1???zx/";
            long expectedIndex = -1;
            WordSearchService service = new WordSearchService(dictRepository);

            // act
            ProcessResult result = service.SearchWord(word);

            //assert
            Assert.AreEqual(expectedIndex, result.index, "Falha ao procurar pela palavra no dicionário");
        }
        public void WordSearchService_SearchHighestWord_RendersMaxNumberOfDeadCats()
        {
            // arrange
            string word = "may";
            long expectedDeadCats = 19;
            WordSearchService service = new WordSearchService(dictRepository);

            // act
            ProcessResult result = service.SearchWord(word);

            //assert
            Assert.AreEqual(expectedDeadCats, result.deadCats, "Número de gatos mortos incorretos");
        }
        public void WordSearchService_SearchHighestWord_RendersHighestPosition()
        {
            // arrange
            string word = "may";
            long expectedIndex = 491;
            WordSearchService service = new WordSearchService(dictRepository);

            // act
            ProcessResult result = service.SearchWord(word);

            //assert
            Assert.AreEqual(expectedIndex, result.index, "Falha ao procurar pela última palavra do dicionário");
        }
        public void ComparteAlgorithms_SearchMiddleWord()
        {
            // arrange
            string word = "exercise";
            WordSearchService serviceBin = new WordSearchService(dictRepository);
            WordFullScanSearchService serviceFull = new WordFullScanSearchService(new DictionaryRepositoryFake());

            // act
            ProcessResult resultBinarySearch = serviceBin.SearchWord(word);
            ProcessResult resultFullScan = serviceFull.FullScan(word);

            //assert
            if (resultBinarySearch.deadCats > resultFullScan.deadCats)
                Assert.Fail("Algorítmo de busca binária ineficiente: Gatos mortos (binary):{0} - Gatos mortos (full):{1}", resultBinarySearch.deadCats, resultFullScan.deadCats);
            else
                System.Diagnostics.Trace.WriteLine(string.Format("Algorítmo de busca binária eficiente: Gatos mortos (binary):{0} - Gatos mortos (full):{1}", resultBinarySearch.deadCats, resultFullScan.deadCats));
        }
Пример #7
0
        static void Main(string[] args)
        {
            var requiredWrdLength = int.Parse(args[0]);
            var searchWrd         = args[1];
            var service           = new WordSearchService();

            var task = service.GetRandomWordList();

            task.ContinueWith(t =>
            {
                var filteredList = service.FilterWords(requiredWrdLength, searchWrd, t.Result);
                foreach (var wrd in filteredList)
                {
                    Console.WriteLine(wrd);
                }
            });
            Console.ReadLine();
        }
        public void WordSearchService_SearchWordExists_RendersWordPosition()
        {
            // arrange
            string word = "and";
            long expectedIndex = 21;
            long expectedDeadCats = 11;
            WordSearchService service = new WordSearchService(dictRepository);

            // act
            ProcessResult result = service.SearchWord(word);

            //assert
            Assert.AreEqual(expectedIndex, result.index, "Falha ao procurar pela palavra no dicionário");
            Assert.AreEqual(expectedDeadCats, result.deadCats, "Número de gatos mortos incorretos");
        }
        public void WordSearchService_SearchWordCaseSensitive_RendersWordPosition()
        {
            // arrange
            string word = "alwAYs";
            long expectedIndex = 17;
            WordSearchService service = new WordSearchService(dictRepository);

            // act
            ProcessResult result = service.SearchWord(word);

            //assert
            Assert.AreEqual(expectedIndex, result.index, "Falha ao procurar pela palavra case sensitive no dicionário");
        }
        public void WordSearchService_SearchLowestWord_RendersOneCatDead()
        {
            // arrange
            string word = "a";
            int expectedDeadCats = 1;
            WordSearchService service = new WordSearchService(dictRepository);

            // act
            ProcessResult result = service.SearchWord(word);

            //assert
            Assert.AreEqual(expectedDeadCats, result.deadCats, "Número de gatos mortos incorretos");
        }