Exemple #1
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);
    }
        public void WordFinderShouldFindAllWordsOccurrencesInMatrix()
        {
            var matrix = new List <string>
            {
                "ASDGIELKETCHUPSNDJHY",
                "QWIDSJBPAJKHGNKIEEEN",
                "CBALKSHIUNLSJFNKKAJS",
                "EBYBVIKTHASDMLKJELKS",
                "AUIENDKZLEUNXDJHTYUB",
                "MRNTVECZXQZEXRCTCYBU",
                "AGSKDJFAGQPWOERUHYER",
                "CEBNAKJSTEAKHSDUUYGG",
                "XRIWNCHSAGDHDHGFPUHE",
                "ABURGERHBLIUJOIKDKPR"
            };

            var words = new List <string>
            {
                "ketchup",
                "burger",
                "pizza",
                "steak"
            };

            var expectedResult = new List <string>
            {
                "burger",
                "ketchup",
                "steak"
            };

            var subject = new WordFinder(matrix);

            var result = subject.FindWords(words).ToList();

            var resultLength         = result.Count;
            var expectedResultLength = expectedResult.Count;

            Assert.AreEqual(expectedResultLength, resultLength);

            for (int i = 0; i < resultLength; i++)
            {
                var item         = result[i];
                var expectedItem = expectedResult[i];

                Assert.AreEqual(expectedItem, item);
            }
        }
 private void findWordsButton_Click(object sender, EventArgs e)
 {
     _WordFinder.FindWords(/* pass file name here */);
 }
Exemple #4
0
        static async Task Main(string[] args)
        {
            // Get input from command line
            string letters    = "";
            int    lowerBound = 3;

            switch (args.Length)
            {
            case 0:
                System.Console.WriteLine(usage);
                return;

            case 1:
                letters = args[0];
                System.Console.WriteLine("Using default shortest word length of 3.");
                lowerBound = 3;
                break;

            case 2:
                letters = args[0];
                if (!int.TryParse(args[1], out lowerBound))
                {
                    System.Console.WriteLine("Unable to parse second argument as an integer.");
                    System.Console.WriteLine("Using default shortest word length of 3.");
                    lowerBound = 3;
                }
                else if (lowerBound < 1)
                {
                    System.Console.WriteLine($"Invalid shortest word length given: {lowerBound} (must be >= 1).");
                    System.Console.WriteLine("Using default shortest word length of 3.");
                    lowerBound = 3;
                }
                else
                {
                    System.Console.WriteLine($"Using shortest word length of {lowerBound}.");
                }
                break;

            default:
                System.Console.WriteLine(usage);
                return;
            }

            IWordFinder wf = new WordFinder("../wordlist.txt"); // TODO un-hardcode

            Stopwatch sw = new Stopwatch();

            sw.Start();

            var words = await Task.Run(() => wf.FindWords(letters, lowerBound));

            var last = words.LastOrDefault(); // (To force evaluation so that the stopwatch gets a valid result)

            sw.Stop();

            // Print the result
            foreach (var word in words)
            {
                System.Console.WriteLine(word);
            }

            System.Console.WriteLine($"CPU-bound (non-startup, non-IO) time: {sw.ElapsedMilliseconds}ms");
        }