static void Main(string[] args) { Console.WriteLine("Please enter a sentence"); string input = Console.ReadLine(); Action actionToCheckPalindrome = () => { Container container = new Container(); string palindromeStrategyValue = ConfigUtils.GetValueByKey("PalindromeStrategyType"); PalindromeStrategyType palindromeStrategyType = StringUtils.ToEnum(palindromeStrategyValue, PalindromeStrategyType.Recursive); IPalindromeFactory palindromeProcessor = container.GetInstance <IPalindromeFactory>(); IPalindromeStrategy palindromeStrategy = palindromeProcessor.GetPalindromeStrategy(palindromeStrategyType); bool isInputPalindrome = palindromeStrategy.CheckIfInputIsPalindrome(input); Console.WriteLine(string.Format("Your input is {0} Palindrome", (isInputPalindrome ? "a" : "not a"))); }; Action <Exception> actionToLogException = excpetion => Console.WriteLine(excpetion.Message); ExceptionHandler.TryCatch(actionToCheckPalindrome, actionToLogException); Console.ReadLine(); }
public void ReturnPalindromeStrategyIfStrategyTypeIsImplemented() { PalindromeStrategyType strategyType = PalindromeStrategyType.Recursive; IPalindromeStrategy strategy = factory.GetPalindromeStrategy(strategyType); Assert.IsType<RecursivePalindromeStrategy>(strategy); }
public PalindromeValidator(IPalindromeStrategy validatorStrategy) { if (validatorStrategy == null) throw new ArgumentNullException(); this.validatorStrategy = validatorStrategy; }
public PalindromeValidator(IPalindromeStrategy validatorStrategy) { if (validatorStrategy == null) { throw new ArgumentNullException(); } this.validatorStrategy = validatorStrategy; }
// Summary: // Create a strategy instance base on required strategy type. // // Parameters: // strategyType: // The enum represents the type of target strategy. // // Returns: // The palindrome strategy instance. // // Exceptions: // PalindromeStrategyNotImplementedException: // When cannot initialize an instance meets target strategy type. public IPalindromeStrategy GetPalindromeStrategy(PalindromeStrategyType strategyType) { IPalindromeStrategy palindromeStrategy = palindromeStrategies.SingleOrDefault(p => p.StategyType == strategyType); if (palindromeStrategy == null) { throw new PalindromeStrategyNotImplementedException(strategyType.ToString()); } return(palindromeStrategy); }
private void RunValidation(IPalindromeStrategy strategy) { PalindromeValidator validator = new PalindromeValidator(strategy); Stopwatch sw = new Stopwatch(); sw.Start(); int timesToRun = Convert.ToInt32(numTimesToRun.Value); bool result = false; for (int i = 0; i <= timesToRun; i++) { result = validator.IsValid(txtWord.Text); } sw.Stop(); lblResult.Text = string.Format("{0}. Took {1} ms", result ? "Palindrome word" : "Just another word", sw.ElapsedMilliseconds); }