Пример #1
0
        static int Main(string[] args)
        {
            var noOfPointsToFind = 3;

            var pointsGenerator = new TestSpaceGenerator();
            var executor        = new SearchExecutor();

            var bruteForceSearcher          = new BruteForceNearestNeighbourSearcher();
            var optimisedBruteForceSearcher = new OptimisedBruteForceNearestNeighbourSearcher();

            WriteDataTableHeader("No. of Points In the Space", "No. of Neighbours to Find", "Given Point", "BruteForce - results", "BruteForce - time", "Optmised - results", "Optmised - time");

            for (int i = 1; i <= 10; i++)
            {
                var currentNoOfPoints = i * i * 1000000;

                var randomIndex = new Random().Next(0, currentNoOfPoints);

                var points = pointsGenerator.GenerateTestSpace(currentNoOfPoints, -2000, 2000, -2000, 2000);
                var point  = points[randomIndex];


                var bruteForceResult = executor.ExecuteSearch(bruteForceSearcher, point, noOfPointsToFind, points);
                var optimisedResult  = executor.ExecuteSearch(optimisedBruteForceSearcher, point, noOfPointsToFind, points);

                WriteDataTableRow(currentNoOfPoints, noOfPointsToFind, ResultsToString(point), ResultsToString(bruteForceResult.NearestNeighbours), bruteForceResult.TimeInMilliseconds, ResultsToString(optimisedResult.NearestNeighbours), optimisedResult.TimeInMilliseconds);
            }

            Console.WriteLine("Press enter to terminate");
            Console.ReadLine();

            return(0);
        }
Пример #2
0
        public void GetSearchResults_ShouldNotReturnResultsFromAnySearchEngine()
        {
            //Arrange
            IWebRequest webRequest = new WebRequestImplementation();

            string[]       keywords       = new string[0];
            SearchExecutor searchExecutor = new SearchExecutor(webRequest, keywords);
            var            emptyList      = new List <string>();

            //Act
            var result = searchExecutor.ExecuteSearch();

            //Assert
            result.Should().Equal(emptyList);
        }
Пример #3
0
        public void GetSearchResults_ShouldReturnResultsFromYahooForJava()
        {
            //Arrange
            string[] keywords = new string[1] {
                "java"
            };

            var mockedWebRequest = new Mock <IWebRequest>();

            mockedWebRequest
            .Setup(c => c.RequestResponse("https://search.yahoo.com/search?p=java"))
            .Returns("<html><body><div class='compPagination'><span>670,000,000 resultados</span></div></body></html>");

            SearchExecutor searchExecutor = new SearchExecutor(mockedWebRequest.Object, keywords);

            //Act
            var result = searchExecutor.ExecuteSearch();

            //Assert
            result.Should().HaveElementAt(0, "java: Google: 0 Bing: 0 Yahoo: 670000000");
        }
Пример #4
0
        public void GetSearchResults_ShouldReturnResultsFromBingForJava()
        {
            //Arrange
            string[] keywords = new string[1] {
                "java"
            };

            var mockedWebRequest = new Mock <IWebRequest>();

            mockedWebRequest
            .Setup(c => c.RequestResponse("https://www.bing.com/search?q=java"))
            .Returns("<html><body><div id='b_tween'><span class='sb_count' data-bm='4'>23.400.000 results</span></div></body></html>");

            SearchExecutor searchExecutor = new SearchExecutor(mockedWebRequest.Object, keywords);

            //Act
            var result = searchExecutor.ExecuteSearch();

            //Assert
            result.Should().HaveElementAt(0, "java: Google: 0 Bing: 23400000 Yahoo: 0");
        }
Пример #5
0
        public void GetSearchResults_ShouldReturnResultsFromGoogleForJava()
        {
            //Arrange
            string[] keywords = new string[1] {
                "java"
            };

            var mockedWebRequest = new Mock <IWebRequest>();

            mockedWebRequest
            .Setup(c => c.RequestResponse("https://www.google.com/search?q=java"))
            .Returns("<html><body><div id='resultStats'>Cerca de 670,000,000 resultados</div></body></html>");

            SearchExecutor searchExecutor = new SearchExecutor(mockedWebRequest.Object, keywords);

            //Act
            var result = searchExecutor.ExecuteSearch();

            //Assert
            result.Should().HaveElementAt(0, "java: Google: 670000000 Bing: 0 Yahoo: 0");
        }