Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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 GivenANumberOfWords_ShouldCreateAListOfPermutationsWithAnExpectedNumber()
        {
            var actual = PermutationsCreator.CreateListOfWordPermutationsReplacementStrings(2).Length;
            //Expect 2 permutations of 2 words
            var expected = 2;

            Assert.Equal(expected, actual);

            actual   = PermutationsCreator.CreateListOfWordPermutationsReplacementStrings(3).Length;
            expected = expected * 3;
            Assert.Equal(expected, actual);

            actual   = PermutationsCreator.CreateListOfWordPermutationsReplacementStrings(4).Length;
            expected = expected * 4;
            Assert.Equal(expected, actual);

            actual   = PermutationsCreator.CreateListOfWordPermutationsReplacementStrings(5).Length;
            expected = expected * 5;
            Assert.Equal(expected, actual);
        }