public void Given3Words_WhenWordsCorrect_ShouldReturnTrue()
        {
            int noOfJackpots = 0;
            var words        = new string[] { "yawls", "stout", "printout" };

            string[] listOfWordPermutationsReplacementStrings = new string[] { "{2} {0} {1}", "{2} {1} {0}" };

            var sut3 = new LoopSetsHelper(DummyPrinter, MD5.Create(), _anagramCtrlMocker3.Object, _wordlistCtrlMocker.Object);
            // Expect words to match one of the md5Hashes
            bool expected = true;
            bool actual   = sut3.LoopPermutationsAndCheckMd5RemoveFoundHash(ref noOfJackpots, words, listOfWordPermutationsReplacementStrings);

            Assert.Equal(expected, actual);

            // Other order should also succeed, but since the found hash was removed, then it can't find it twice
            words    = new string[] { "stout", "yawls", "printout" };
            expected = false;
            actual   = sut3.LoopPermutationsAndCheckMd5RemoveFoundHash(ref noOfJackpots, words, listOfWordPermutationsReplacementStrings);
            Assert.Equal(expected, actual);

            // Same as above, but this time we refresh the hashlist - and then the sentence should be found
            sut3     = new LoopSetsHelper(DummyPrinter, MD5.Create(), _anagramCtrlMocker3.Object, _wordlistCtrlMocker.Object);
            expected = true;
            actual   = sut3.LoopPermutationsAndCheckMd5RemoveFoundHash(ref noOfJackpots, words, listOfWordPermutationsReplacementStrings);
            Assert.Equal(expected, actual);

            // It should also work with auto-created permutations - we remember to refresh the hashlist by renewing sut3
            listOfWordPermutationsReplacementStrings = PermutationsCreator.CreateListOfWordPermutationsReplacementStrings(3);
            sut3   = new LoopSetsHelper(DummyPrinter, MD5.Create(), _anagramCtrlMocker3.Object, _wordlistCtrlMocker.Object);
            actual = sut3.LoopPermutationsAndCheckMd5RemoveFoundHash(ref noOfJackpots, words, listOfWordPermutationsReplacementStrings);
            Assert.Equal(expected, actual);
        }
示例#2
0
        // Pseudo:
        // A. Load Data
        // B. Decrease the dataset
        // C. Find valid words in dataset

        public ProgramTransactionScript(IConfigurationRoot config, ConsoleLogger logger,
                                        IAnagramContainer anagramContainer, IWordlistContainer wordlistContainer,
                                        LoopSetsHelper <CurrentSetOf2Pos> setsOf2WordsLooper, LoopSetsHelper <CurrentSetOf3Pos> setsOf3WordsLooper,
                                        LoopSetsHelper <CurrentSetOf4Pos> setsOf4WordsLooper, LoopSetsHelper <CurrentSetOf5Pos> setsOf5WordsLooper)
        {
            _injectedLogger = logger;
            Console.WriteLine("Hello from AnagramSolver!");
            Console.WriteLine("");

            // A. Load Data

            // A1. Show loaded anagram data
            _injectedAnagramContainer = anagramContainer;
            _injectedLogger.ConsoleWriteLine("A1_LoadAnagram()");
            _injectedLogger.ConsoleWriteLine(" This is the input anagram: '" + _injectedAnagramContainer.Anagram.RawData + "'");
            _injectedLogger.ConsoleWriteLine(" These distinct letters does the anagram contain: '" + _injectedAnagramContainer.Anagram.DistinctDataWithoutSpaceAsString + "'");
            _injectedLogger.ConsoleWriteLine(" As above, but sorted: '" + _injectedAnagramContainer.Anagram.DistinctDataWithoutSpaceSortedAsString + "' - also called TableHeader");
            Console.WriteLine("");

            // A2. Show loaded wordlistdata
            _injectedWordlistContainer = wordlistContainer;
            _injectedLogger.ConsoleWriteLine("A2_LoadWordlist()");
            _injectedLogger.ConsoleWriteLine(" The unfiltered input wordlist contains " + _injectedWordlistContainer.ListUnfiltered0_Wordlist.Count + " lines");
            Console.WriteLine("");

            _injectedSetsOf2WordsLooper = setsOf2WordsLooper;
            _injectedSetsOf3WordsLooper = setsOf3WordsLooper;
            _injectedSetsOf4WordsLooper = setsOf4WordsLooper;
            _injectedSetsOf5WordsLooper = setsOf5WordsLooper;
        }
        public void Given3Words_WhenNoMd5Hashes_ShouldReturnNoValue()
        {
            int noOfJackpots = 0;

            // Expect neither true nor false, when no md5Hashes in list (in _Sut0)
            bool expected = false;
            var  sut0     = new LoopSetsHelper(DummyPrinter, MD5.Create(), _anagramCtrlMocker0.Object, _wordlistCtrlMocker.Object);
            bool?actualQ  = sut0.checkMd5RemoveFoundHash(ref noOfJackpots, "a b c");
            bool actual   = actualQ.HasValue;

            Assert.Equal(expected, actual);
        }
        public void Given3Words_WhenWordsInCorrect_ShouldReturnFalse()
        {
            int noOfJackpots = 0;
            var words        = new string[] { "pawls", "stout", "printout" };

            // Create list with permutations for string.Format: "{0} {1} {2}" from [0,1,2] to [2,1,0] = 6 permutations
            string[] listOfWordPermutationsReplacementStrings = PermutationsCreator.CreateListOfWordPermutationsReplacementStrings(3);

            // Expect words not to match one of the md5Hashes
            bool expected = false;
            var  sut3     = new LoopSetsHelper(DummyPrinter, MD5.Create(), _anagramCtrlMocker3.Object, _wordlistCtrlMocker.Object);
            bool actual   = sut3.LoopPermutationsAndCheckMd5RemoveFoundHash(ref noOfJackpots, words, listOfWordPermutationsReplacementStrings);

            Assert.Equal(expected, actual);
        }
        public void Given3Words_WhenWordsCorrect_ButPermutationListIsWrong_ShouldReturnFalse()
        {
            int noOfJackpots = 0;
            var words        = new string[] { "yawls", "stout", "printout" };

            // Though words are correct then the selected permutations won't put sentence in right order
            string[] listOfWordPermutationsReplacementStrings = new string[] { "{0} {1} {2}", "{0} {2} {1}" };

            // Expect fail, when words are not put in right order
            bool expected = false;
            var  sut3     = new LoopSetsHelper(DummyPrinter, MD5.Create(), _anagramCtrlMocker3.Object, _wordlistCtrlMocker.Object);
            bool actual   = sut3.LoopPermutationsAndCheckMd5RemoveFoundHash(ref noOfJackpots, words, listOfWordPermutationsReplacementStrings);

            Assert.Equal(expected, actual);
        }