Beispiel #1
0
        public void Can_Find_One_Word()
        {
            var word   = "cold";
            var retval = board.Find(new[] { word });

            Assert.AreEqual(1, retval.Count());
        }
Beispiel #2
0
        public void UsingAMatrixOf19x19CharsTest()
        {
            var dictionary = new string[] { "mariposa", "lanza", "celtina", "lete", "juanita", "lechiguana", "yuyera", "caronte", "mosca", "cochinilla", "agavo", "marmorea", "coma" };
            var src        = new string[] { "AECYMCCOCHINILLACMN",
                                            "AOLUVLAUENCCÓLGLCAR",
                                            "ADERNDRIATLOAIORORM",
                                            "ANCCHALZIIRSMTGIOIR",
                                            "RMHIREJAPETRSUSOAPA",
                                            "UMICARONTEOILELTPOE",
                                            "CNGOAJLIYHMIVDAALSA",
                                            "EAUUMUTJTOCOALNMVAS",
                                            "ELAOBAIENAEPEEZCOSA",
                                            "EANEMNPSRELNROANDTO",
                                            "DTAADIRIHMTASETOSAA",
                                            "NLNIATECCAINDROOAUM",
                                            "GMYGRANAAUNTERGTULO",
                                            "RRAEEIIEIAACANALGRS",
                                            "OPATHUDAGAVOAAUDTAC",
                                            "DINCIOUAHASLUACAOBA",
                                            "TSRMICOMAMARMOREARA",
                                            "AOTDNLRLLMILETEENEA",
                                            "BESYUYERANVEEHASERL" };

            var wordFinder = new WordFinder(dictionary);
            var result     = wordFinder.Find(src);

            Assert.AreEqual(result.Count, dictionary.Count());
        }
Beispiel #3
0
        public void TestFindSmallMatrixShortStreamNoMatch()
        {
            var solver = new WordFinder(_matrixSmall);
            var result = (List <string>)solver.Find(_searchWordsNoMatch);

            Assert.AreEqual(0, result.Count);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            List <string> wordstream = new List <string>();

            wordstream.AddRange(WordTools.SampleWordStream);

            for (int i = 0; i < 1000000 - wordstream.Count; i++)
            {
                wordstream.Add(WordTools.GetRandomWord());
            }

            IEnumerable <string> ranking = _wordFinder.Find(wordstream);

            stopwatch.Stop();
            var elapsedTicks        = stopwatch.ElapsedTicks;
            var elapsedMilliseconds = stopwatch.ElapsedMilliseconds;

            System.Console.WriteLine();
            System.Console.WriteLine("----------------------------------------------------");
            System.Console.WriteLine("SEEDED WORDS:");
            System.Console.WriteLine("----------------------------------------------------");
            System.Console.WriteLine();

            foreach (string word in WordTools.SampleWordStream)
            {
                System.Console.WriteLine(word);
            }

            System.Console.WriteLine();
            System.Console.WriteLine("----------------------------------------------------");
            System.Console.WriteLine("MATRIX:");
            System.Console.WriteLine("----------------------------------------------------");
            System.Console.WriteLine();

            MatrixTools.PrintMatrix(MatrixTools.GetIEnumerableMatrix(_matrixSize, _matrix));

            System.Console.WriteLine();
            System.Console.WriteLine("----------------------------------------------------");
            System.Console.WriteLine("RANKING:");
            System.Console.WriteLine("----------------------------------------------------");
            System.Console.WriteLine();

            foreach (string word in ranking)
            {
                System.Console.WriteLine(word);
            }

            System.Console.WriteLine();
            System.Console.WriteLine("----------------------------------------------------");
            System.Console.WriteLine("STATS:");
            System.Console.WriteLine("----------------------------------------------------");
            System.Console.WriteLine();
            System.Console.WriteLine($"Elapsed Milliseconds: {elapsedMilliseconds}");
            System.Console.WriteLine($"Elapsed Ticks: {elapsedTicks}");
            System.Console.WriteLine();
        }
Beispiel #5
0
        public void Find_WhenNoMatchesFound_ReturnEmptyList()
        {
            WordFinder           finder = new WordFinder(_testMatrix);
            IEnumerable <string> result = finder.Find(new[] { "Lauda", "Ronaldo", "Hewwit", "Iverson" });

            Assert.That(result, Is.Empty);
        }
Beispiel #6
0
        public IActionResult Find([FromBody] string[] value, string uid)
        {
            var filename = string.Empty;
            IEnumerable <string> retval = new List <string>();

            if (value.Length == 0 || string.IsNullOrEmpty(uid))
            {
                return(BadRequest());
            }
            try
            {
                var filePath = Path.Combine(_hostingEnvironment.ContentRootPath, uid + ".txt");

                if (System.IO.File.Exists(filePath))
                {
                    var list   = System.IO.File.ReadAllLines(filePath);
                    var finder = new WordFinder(list);
                    retval = finder.Find(value);
                }
                else
                {
                    return(StatusCode((int)HttpStatusCode.NoContent, "The give uid doesn't have a valid board."));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
            return(Ok(retval));
        }
Beispiel #7
0
        public void AllDirectionsSmall()
        {
            var grid   = new WordGrid(3, 3, new string[] { "BAC", "EOO", "CKB" });
            var finder = new WordFinder(new List <string> {
                "BAC", "BOB", "BEC", "COC"
            }, grid);

            Assert.AreEqual("OK", finder.Find());
        }
Beispiel #8
0
        public void Find_WhenMatchesFound_ReturnTopTenListOfMatchesOrderedByNumberOfMatches()
        {
            WordFinder finder = new WordFinder(_testMatrix);

            IEnumerable <string> result = finder.Find(new[] { "Messi", "Jordan", "Federer", "Ginobili", "Iverson", "Bird", "Ronaldo", "Ewing", "Stockton", "Maradona", "Cruyff", "Kobe", "James" });

            Assert.That(result, Is.Unique);
            Assert.That(result, Is.EquivalentTo(new[] { "Messi", "Jordan", "Federer", "Bird", "Ewing", "Stockton", "Maradona", "Cruyff", "Kobe", "Ginobili" }));
        }
Beispiel #9
0
        public void Find_Should_Match_Horizontal_Left_To_Right_Words()
        {
            IEnumerable <string> matrix = new string[] { "one", "owt" };

            WordFinder           wordFinder = new WordFinder(matrix);
            IEnumerable <string> results    = wordFinder.Find(new string[] { "one", "two" });

            Assert.True(results.Count() == 1 && results.ElementAt(0) == "one");
        }
Beispiel #10
0
        public void Find_Should_Match_Vertical_Top_To_Bottom_Rows()
        {
            IEnumerable <string> matrix = new string[] { "oo", "nw", "et" };

            WordFinder           wordFinder = new WordFinder(matrix);
            IEnumerable <string> results    = wordFinder.Find(new string[] { "one", "two" });

            Assert.True(results.Count() == 1 && results.ElementAt(0) == "one");
        }
Beispiel #11
0
        public void VerticalWords()
        {
            var grid = new WordGrid(4, 4, new string[]
                                    { "GTRI", "LMAL", "UAGO", "ECML" });
            var finder = new WordFinder(new List <string> {
                "GLUE", "RAG", "LOL", "MAC"
            }, grid);

            Assert.AreEqual("TIM", finder.Find());
        }
Beispiel #12
0
        public void FindAllWords()
        {
            var wordFinder = new WordFinder(GetMatrix());
            var wordSteam  = GetWordStream();
            var topWord    = wordFinder.Find(wordSteam);

            var expectedResult = GetTop10Words();

            Assert.Equal(expectedResult, topWord);
        }
Beispiel #13
0
        public void UsingTheDictionaryAndSourceOfTheExerciseTest()
        {
            var dictionary = new string[] { "chill", "wind", "snow", "cold" };
            var src        = new string[] { "abcdc", "fgwio", "chill", "pqnsd", "uvdxy" };

            var wordFinder = new WordFinder(dictionary);
            var result     = wordFinder.Find(src);

            Assert.AreEqual(result.Count, 3);
        }
Beispiel #14
0
        public void FindAllWordsReturnEmptyList()
        {
            var wordFinder = new WordFinder(GetMatrix());
            var wordSteam  = GetWordsStreamTwo();
            var topWord    = wordFinder.Find(wordSteam);

            var expectedResult = new List <string>();

            Assert.Equal(expectedResult, topWord);
        }
Beispiel #15
0
        public ActionResult <IEnumerable <string> > GetMatrixQu(QuMatrixModel model)
        {
            if (!model.Valid())
            {
                return(BadRequest());
            }
            IWordFinder myMatrix = new WordFinder(model.matrix);

            return(myMatrix.Find(model.words).ToArray());
        }
Beispiel #16
0
        public void TestFindLargeMatrixLongStream()
        {
            var solver = new WordFinder(_matrixLarge);
            var result = (List <string>)solver.Find(_searchWordsLong);

            Assert.AreEqual(10, result.Count);
            Assert.AreEqual((result.GetRange(0, 3)), new List <string>()
            {
                "cold", "wind", "snow"
            });
        }
Beispiel #17
0
    public static void Main(string[] args)
    {
        var words  = new[] { "we", "wet", "enter", "enterance", "ran", "an", "rat" };
        var finder = new WordFinder(words);

        var pattern = "wenterancewet";

        foreach (var word in finder.Find(pattern))
        {
            Console.WriteLine(word);
        }
    }
Beispiel #18
0
        public void HorizontalWords()
        {
            var grid = new WordGrid(3, 3, new string[]
            {
                "BAC", "BOB", "RED"
            });
            var finder = new WordFinder(new List <string> {
                "BAC", "BOB"
            }, grid);

            Assert.AreEqual("RED", finder.Find());
        }
        public void Find_WhenValid_ReturnsList()
        {
            // Arrange
            var words  = _faker.Random.WordsArray(1000);
            var matrix = GenerateMatrix(words.Take(10));

            _wordFinder = new WordFinder(matrix);

            // Act
            var result = _wordFinder.Find(words);

            // Assert
            Assert.NotNull(result);
            Assert.NotEmpty(result);
            Assert.Equal(10, result.Count());
        }
Beispiel #20
0
        public void AllDirectionsBig()
        {
            var grid = new WordGrid(12, 12, new string[]
            {
                "VCENJUGUENTO",
                "OCORCSEERRAN",
                "SOCHASSIGNET",
                "SDRAHCUAFDND",
                "AENMALMENEES",
                "BSETINMUIDEM",
                "VOLLEYBALLTG",
                "COLATURESAUM",
                "ISEMAEGROGER",
                "SSURSITESERE",
                "TEGNITRIFIAT",
                "ENILECOUSAIS"
            });
            var finder = new WordFinder(new List <string>
            {
                "BASSOV",
                "CELINE",
                "CHASSIGNET",
                "CISTE",
                "COLATURES",
                "COUSAIS",
                "EAMES",
                "ENJUGUENT",
                "ERES",
                "ESCROC",
                "FAUCHARDS",
                "GRAUBUNDEN",
                "INSERAIENT",
                "MALMENEES",
                "MEDIUMNITES",
                "NARREES",
                "NITRIFIAT",
                "ODES",
                "REGORGEA",
                "SURSITES",
                "TUERA",
                "VOLLEYBALL"
            }, grid);

            Assert.AreEqual("CODNGAME", finder.Find());
        }
        public void Find_WhenVerticalValid_ReturnsList()
        {
            // Arrange
            var matrix = GenerateVerticalMatrix();
            var words  = new List <string> {
                "sample"
            };

            _wordFinder = new WordFinder(matrix);

            // Act
            var result = _wordFinder.Find(words);

            // Assert
            Assert.NotNull(result);
            Assert.NotEmpty(result);
            Assert.Single(result);
        }
        public IActionResult Search(ApiRequestModel model)
        {
            if (ModelState.IsValid)
            {
            }
            var apiResponse = new ApiResponseModel();
            var wFinder     = new WordFinder(model.Dictionary);

            if (wFinder.Exceed2048 || wFinder.Exceed64x64(model.Src))
            {
                apiResponse.ErrorMessage = wFinder.Exceed2048 ? "The number of items in the dictionary does not exceed 2048" : "The size of the matrix does not exceed 64x64";
                return(BadRequest(apiResponse));
            }
            else
            {
                apiResponse.Result = wFinder.Find(model.Src).ToList();
                return(Ok(apiResponse));
            }
        }
        public void Find_WhenNoWordsFound_ReturnsEmptyList()
        {
            // Arrange
            var words = new List <string> {
                "uno", "dos", "tres", "cuatro", "cinco", "seis", "siete", "ocho", "nueve", "diez"
            };
            var matrix     = GenerateMatrix(words);
            var wordstream = _faker.Random.WordsArray(1000).ToList();

            wordstream.RemoveAll(x => x.Length < 6);

            _wordFinder = new WordFinder(matrix);

            // Act
            var result = _wordFinder.Find(wordstream);

            // Assert
            Assert.NotNull(result);
            Assert.Empty(result);
        }
        public void Performance_Find()
        {
            var sw = new Stopwatch();

            var size = _faker.Random.Byte(1, 64);

            sw.Start();

            var matrix = GenerateRandomMatrix(size);

            var wordstream = GenerateWordstream(_faker.Random.Int(1, 1000000));

            var finder = new WordFinder(matrix);

            finder.Find(wordstream);

            sw.Stop();

            Assert.True(sw.ElapsedMilliseconds < 50000);
        }
Beispiel #25
0
        public void FindWords()
        {
            //arrange
            var matrix = new List <string>()
            {
                "abcdc", "fgwio", "chill", "pqnsd", "uvdxy"
            };
            var finder   = new WordFinder(matrix);
            var expected = new List <string>()
            {
                "chill", "cold", "wind"
            };
            var wordStream = new List <string>()
            {
                "cold", "wind", "snow", "chill"
            };

            //act
            var actual = finder.Find(wordStream);

            //assert
            Assert.Equal(expected, actual);
        }
Beispiel #26
0
        static void Main(string[] args)
        {
            try
            {
                var stay = true;
                // Start!
                while (stay)
                {
                    Console.Clear();
                    Console.BackgroundColor = ConsoleColor.DarkBlue;
                    Console.WriteLine("###################################################");
                    Console.WriteLine("####### Welcome to the main application ###########");
                    Console.WriteLine("###################################################");
                    Console.WriteLine("Please provide the path to the file that contains the board:");
                    var pathToFile = Console.ReadLine();
                    Console.WriteLine($"Wait until we get the file from {pathToFile}");
                    if (File.Exists(pathToFile))
                    {
                        var lines  = File.ReadAllLines(pathToFile);
                        var finder = new WordFinder(lines);
                        Console.WriteLine($"The file {pathToFile} has been processed successfully");
                        Console.WriteLine("Please provide the path to the file that contains the words stream:");
                        pathToFile = Console.ReadLine();
                        if (File.Exists(pathToFile))
                        {
                            lines = File.ReadAllLines(pathToFile);
                            var tokens = lines[0].Split(' ');
                            Console.WriteLine($"The file {pathToFile} has been processed successfully");
                            var results = finder.Find(tokens);
                            Console.WriteLine("Starting to find the words.. let's have fun");
                            Console.WriteLine("Those are the top 10 most repeated words:");
                            foreach (var item in results)
                            {
                                Console.WriteLine(item);
                            }
                            Console.WriteLine("Thanks for using the word finder tool");
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine($"The file does not exists: {pathToFile}. Please provide a valid path.");
                            Console.ResetColor();
                        }
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"The file does not exists: {pathToFile}. Please provide a valid path.");
                        Console.ResetColor();
                    }

                    Console.WriteLine("Do you want to finish (Y/N):");
                    if (Console.ReadLine().ToUpper() == "Y")
                    {
                        stay = false;
                    }
                }
            }
            catch (ArgumentNullException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Ups, something went extremily wrong. Please try again");
            }
        }
Beispiel #27
0
        public void Find_Returns_At_Most_Ten_Strings()
        {
            IEnumerable <string> results = _wordFinder.Find(WordTools.SampleWordStream);

            Assert.True(results.Count() == 10);
        }