Esempio n. 1
0
        public void FactorsParanthesis()
        {
            Paranthesis target = new Paranthesis();

            string factors = "ABC";

            string[] expected =
            {
                "((AB)C)",
                "(A(BC))"
            };

            TestFactorParanthesis(target, factors, expected);

            factors  = "ABCD";
            expected = new string[]
            {
                "(((AB)C)D)",
                "((A(BC))D)",
                "(A(B(CD)))",
                "((AB)(CD))",
                "(A((BC)D))"
            };

            TestFactorParanthesis(target, factors, expected);
        }
Esempio n. 2
0
        private static void TestFactorParanthesis(Paranthesis target, string factors, string[] expected)
        {
            var actual = target.FactorParanthesis(factors);

            Assert.AreEqual(expected.Count(), actual.Count());

            foreach (var item in expected)
            {
                Assert.IsTrue(actual.Contains(item));
            }
        }
Esempio n. 3
0
        public void CatalanCountTest()
        {
            Paranthesis   target = new Paranthesis();
            StringBuilder sb     = new StringBuilder();

            //Thread thread = new Thread(
            //    () =>
            {
                for (int i = 0; i < 14; i++)
                {
                    sb.Append('A');
                    var watch = new System.Diagnostics.Stopwatch();
                    watch.Start();
                    Assert.AreEqual(Paranthesis.GetCatalanNumber(i), target.FactorParanthesis(sb.ToString()).Count);
                    watch.Stop();
                    Console.WriteLine("i = {0} watch = {1}", i, watch.Elapsed.ToString());
                }
            }
            //);

            //thread.Start();
            //Thread.Sleep(10000);
            //thread.Abort();
        }