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); }
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)); } }
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(); }