Example #1
0
        private void GeneratePermutationsBtn_Click(object sender, EventArgs e)
        {
            if (!IsInputValid(InputField.Text))
            {
                MessageBox.Show("Please populate input field by either typing or importing file");
                return;
            }

            ClearAllFields();

            Stopwatch watch = new Stopwatch();

            watch.Start();

            var permutable = InputField.Text.ToCharArray();

            var permutations = Permutations.Generate(permutable);

            permutations.ToList().ForEach(x => PermutationsField.Text += new string(x) + "\r\n");

            PermutationsCountField.Text = permutations.Count().ToString();

            Permutations.GetMatches(permutable, permutations).ToList().ForEach(x => MatchingPermutationsField.Text += new string(x) + "\r\n");

            watch.Stop();

            TimeField.Text = watch.ElapsedMilliseconds.ToString();
        }
        public void MatchingPermutationsCountTest()
        {
            char[] permutable = new char[] { 'A', 'B', 'C', 'D' };

            var permutations         = Permutations.Generate(permutable);
            var matchingPermutations = Permutations.GetMatches(permutable, permutations);

            Assert.AreEqual(2, matchingPermutations.Count());
        }
        public void MatchingPermutationsValidityCountTest()
        {
            char[] permutable = new char[] { 'A', 'B', 'C', 'D' };

            IEnumerable <char[]> permutations = new List <char[]>
            {
                new char[] { '1', '2', '3' },
                new char[] { '3', '2', '1' }
            };

            var matchingPermutations = Permutations.GetMatches(permutable, permutations);

            Assert.AreNotEqual(2, matchingPermutations.Count());
        }
        public void MatchingPermutationsTest()
        {
            char[] permutable = new char[] { '1', '2', '3' };

            IEnumerable <char[]> expectedMatches = new List <char[]>
            {
                new char[] { '1', '2', '3' },
                new char[] { '3', '2', '1' }
            };

            var permutations         = Permutations.Generate(permutable);
            var matchingPermutations = Permutations.GetMatches(permutable, permutations);

            Assert.IsTrue(matchingPermutations.SelectMany(x => x).SequenceEqual(expectedMatches.SelectMany(x => x)));
        }