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 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");
        }
        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_SearchNullWord_RendersNotFound()
        {
            // arrange
            string            word          = null;
            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_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 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));
        }
Exemplo n.º 8
0
        public void CanGetSearchWords()
        {
            var request = new WordSearchRequest("s", "");

            request.ExcludePartsOfSpeech = new List <PartOfSpeech>()
            {
                PartOfSpeech.ProperNoun, PartOfSpeech.ProperNounPlural, PartOfSpeech.ProperNounPossesive, PartOfSpeech.Suffix, PartOfSpeech.FamilyName, PartOfSpeech.GivenName, PartOfSpeech.Idiom, PartOfSpeech.Affix, PartOfSpeech.NounPlural, PartOfSpeech.NounPossessive
            };
            request.IncludePartsOfSpeech = new List <PartOfSpeech>()
            {
                PartOfSpeech.Noun
            };
            request.MaximumLength = 10;

            var service  = new WordSearchService(new GetWordnikBaseUrlQuery());
            var response = service.SearchWords(request);

            Console.WriteLine("Num Results = " + response.TotalNumberOfResults + ", " + string.Join(", ", response.SearchResultList.Select(w => w.Word)));
        }
        public void Test()
        {
            #region Arrange

            var dbContextMock = new DbContextMock <FakeContext>();

            var mockSetGuild = dbContextMock.CreateDbSetMock(x => x.Guilds, GetTestGuilds());

            CancellationTokenSource source = new CancellationTokenSource();
            CancellationToken       token  = source.Token;
            var mock = new Mock <FakeContext>();
            mock.Setup(c => c.Guilds).Returns(mockSetGuild.Object);

            SaveChangesInFakeContext(mock, token, SaveFakeDbSets, mockSetGuild);

            var services = new ServiceCollection()
                           .AddScoped <IEFContext>(provider => mock.Object)
                           .BuildServiceProvider();

            var wordSearchesService = new WordSearchService(services);
            var searchText          = "Test";
            var reply = "Test passed";
            #endregion

            #region Act
            wordSearchesService.AddSearchWord(1, reply, searchText);
            var answer     = wordSearchesService.SearchWord(1, searchText);
            var nullAnswer = wordSearchesService.SearchWord(1, "randomtexthere");
            #endregion

            #region Assert
            Assert.NotNull(answer);
            Assert.Equal(answer, reply);
            Assert.Null(nullAnswer);
            #endregion

            SetTestOutput("WordSearchService test passed");
        }