Beispiel #1
0
        public void TestParallelFindSmallMatrixShortStream()
        {
            var solver = new WordFinder(_matrixSmall);
            var result = solver.ParallelFind(_searchWordsShort);

            Assert.AreEqual(3, result.Count);
        }
Beispiel #2
0
        //=========================================================================================
        void MoveRight(MovementType movementType, bool clearSelection)
        {
            if (this.Doc.Count == 0)
            {
                this.MoveDocHome();
                return;
            }
            int    iLine = this._Point.Line, iChar, iCol;
            string sLine = this.Doc[iLine].Text;

            if (this._Point.Char >= sLine.Length)
            {
                if (iLine >= this.Doc.Count - 1)
                {
                    return;
                }
                iLine++;
                iChar = 0;
            }
            else
            {
                if (movementType == MovementType.Char)
                {
                    iChar = this._Point.Char + 1;
                }
                else
                {
                    iChar = WordFinder.GetNextWordStart(sLine, this._Point.Char);
                }
            }
            iCol = this.GetColumn(sLine, iChar);
            this.SetCaretPos(iLine, iChar, iCol, true, clearSelection);
        }
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
        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 #5
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());
        }
 public Form1()
 {
     InitializeComponent();
     _WordFinder               = new WordFinder();
     _WordFinder.WordFound    += WordFinder_WordFound;
     _WordFinder.NoWordsFound += WordFinder_NoWordsFound;
 }
Beispiel #7
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 #8
0
 public void Throw_ArgumentNullException_Wrong_Input()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         var _board = new WordFinder(null);
     });
 }
Beispiel #9
0
 public void Should_Throw_If_Matrix_Exceeds_Max_Size()
 {
     Assert.Throws <MatrixSizeExceededException>(() =>
     {
         WordFinder wordFinder = new WordFinder(new string[WordFinder.MAX_MATRIX_SIZE + 1]);
     });
 }
Beispiel #10
0
        private static void RunSearch(UnscrambleOptions options, PrefixTreeDictionary dictionary)
        {
            if (options.MinWordLength < 0)
            {
                options.MinWordLength = options.Letters.Length;
            }

            Console.WriteLine("Looking for words...");
            var foundWords = WordFinder.FindUnscrambledWords(
                options.Letters,
                options.MinWordLength,
                dictionary
                );

            if (foundWords.Count == 0)
            {
                Console.WriteLine("Sorry, we didn't find any words :(");
            }
            else
            {
                Console.WriteLine($"Done! Found {foundWords.Count} words:");
                foreach (string word in foundWords)
                {
                    Console.WriteLine(word);
                }
            }
        }
 private void DefineVariables()
 {
     if (wf is default(WordFinder))
     {
         wf = new WordFinder(Constants.ConnectionString);
     }
 }
Beispiel #12
0
        public void TestRotateMatrixLarge()
        {
            var solver      = new WordFinder(_matrixLarge);
            var rotatedMtrx = solver.RotateMatrix(_matrixLarge);

            Assert.AreEqual(rotatedMtrx[0], "yxyyyxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxv");
            Assert.AreEqual(rotatedMtrx[63], "afcpuxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxf");
        }
Beispiel #13
0
        public void TestRotateMatrixSmall()
        {
            var solver      = new WordFinder(_matrixSmall);
            var rotatedMtrx = solver.RotateMatrix(_matrixSmall);

            Assert.AreEqual(rotatedMtrx[0], "coldy");
            Assert.AreEqual(rotatedMtrx[4], "afcpu");
        }
Beispiel #14
0
    public static void Main()
    {
        var wordstream = new string[] { "chill", "wind", "cold" };
        var matrix     = new string[] { "abcdc", "fgwio", "chill", "pqnsd", "uvdxy" };
        var result     = new WordFinder(wordstream).Find(matrix);

        Console.WriteLine(string.Join(",", result));
    }
        public ActionResult CounterResult()
        {
            string     sentenceResult = Request.Form[("your-sentence")];
            string     keyWordResult  = Request.Form[("your-keyWord")];
            WordFinder newWordFinder  = new WordFinder(sentenceResult, keyWordResult);

            return(View("PageResults", newWordFinder));
        }
Beispiel #16
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 #17
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 #18
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 #19
0
        public void Should_Throw_If_Matrix_Is_Empty()
        {
            IEnumerable <string> matrix = new List <string>();

            Assert.Throws <EmptyMatrixException>(() =>
            {
                WordFinder wordFinder = new WordFinder(matrix);
            });
        }
Beispiel #20
0
        public void Should_Throw_If_At_Least_One_String_Has_A_Different_Length_Than_The_First()
        {
            IEnumerable <string> matrix = new string[] { "one", "two", "three" };

            Assert.Throws <DifferentLengthRowsException>(() =>
            {
                WordFinder wordFinder = new WordFinder(matrix);
            });
        }
Beispiel #21
0
        public void Find_Should_Count_Only_Once_A_Word_Found_Multiple_Times()
        {
            IEnumerable <string> matrix = new string[] { "one", "one", "two", "six" };

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

            Assert.True(results.ElementAt(2) == "one");
        }
Beispiel #22
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 #23
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 #24
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 #25
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 #26
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 #27
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 #28
0
    public void MyFirstTheory(GameBoard board, int minWordLength, List <string> dictionary, List <string> expected)
    {
        Dictionary wordDictionary = new Dictionary(dictionary, minWordLength);

        List <string> result = WordFinder.FindWords(board, wordDictionary).ToList();

        result.Sort();
        expected.Sort();

        Assert.Equal(result, expected);
    }
Beispiel #29
0
        static void Main(string[] args)
        {
            IConsoleWrapper           consoleWrapper           = new ConsoleWrapper();
            IFileOperations           fileOperations           = new FileOperations();
            IWordFinder               wordFinder               = new WordFinder();
            ISearchOrientationManager searchOrientationManager = new SearchOrientationManager();

            var wordSearchProgram = new WordSearchProgram(consoleWrapper, fileOperations, wordFinder, searchOrientationManager);

            wordSearchProgram.ProgramLoop("puzzles");
        }
Beispiel #30
0
    static void Main()
    {
        var dictionary = new string[] { "chill", "wind", "snow", "cold" };
        var src        = new string[] { "abcdc", "fgwio", "chill", "pqnsd", "uvdxy" };
        var result     = new WordFinder(dictionary).Find(src);

        foreach (string show in result)
        {
            Console.WriteLine(show);
        }
    }
Beispiel #31
0
        private void Run()
        {
            Stopwatch stopwatch = new Stopwatch();
            Console.Write("Constructing search tree...");
            stopwatch.Start();
            var wordFinder = new WordFinder(@"C:\Users\Daniel\Dropbox\Programming\TernarySearchTree\swedish-word-list-bigger.txt", Encoding.UTF8, Language.Swedish);
            //var wordFinder = new WordFinder(@"C:\Users\danlid\Dropbox\Programming\TernarySearchTree\english-word-list.txt", Encoding.UTF8, Language.English);
            //var wordFinder = new WordFinder(@"C:\Users\danlid\Dropbox\Programming\TernarySearchTree\swedish-english.txt", Encoding.UTF8, Language.Swedish);
            stopwatch.Stop();
            Console.WriteLine("{0} ms", stopwatch.ElapsedMilliseconds);

            Console.WriteLine("Enter word to search for. A single 'q' exits.");
            var lineEditor = new LineEditor("input");
            string input = lineEditor.Edit(": ", string.Empty);
            while (input != "q")
            {
                do
                {
                    if (string.IsNullOrWhiteSpace(input))
                        break;

                    stopwatch.Restart();
                    var matches = wordFinder.Matches(input, 2, 100);
                    stopwatch.Stop();
                    if (matches.Count > 0)
                    {
                        Console.WriteLine("Found {0} words matching '{1}':", matches.Count, input);
                        matches.ForEach(m => Console.WriteLine("{0,-7}: {1}", m.Type, m.Value));
                    }
                    else
                    {
                        Console.WriteLine("Did not find any words matching '{0}'", input);
                    }

                    Console.WriteLine("Search completed in {0:F2} ms. Visited {1} nodes.", 1000.0 * stopwatch.ElapsedTicks / Stopwatch.Frequency, wordFinder.Nodes);
                }
                while (false);
                input = lineEditor.Edit(": ", string.Empty);
            }
        }
Beispiel #32
0
 private static void LoadDictionary()
 {
     Task.Factory.StartNew(() =>
         {
             Log.Info("Loading dictionary");
             object dir = AppDomain.CurrentDomain.GetData("DataDirectory");
             string filename = Path.Combine(dir.ToString(), "words.txt");
             string language = Path.Combine(dir.ToString(), "nian.txt");
             wordFinder = new WordFinder(filename, Encoding.UTF8, Language.Swedish);
             nianFinder = new NianFinder(language, Encoding.UTF8, new CultureInfo("sv-SE"));
             LoadingEvent.Set();
             Log.Info("Dictionary loaded");
         });
 }