public void OneWhiteSpaceOnlyNumberTest() { var phoneNumber = "SDFD df12345678{"; Assert.IsFalse(PhoneNumberComparer.AreEqual(" ", phoneNumber, _serialComparer)); Assert.IsFalse(PhoneNumberComparer.AreEqual(" ", string.Empty, _regexComparer)); Assert.IsFalse(PhoneNumberComparer.AreEqual(phoneNumber, " ", _linqComparer)); }
public void ValidateIllegalNumbersTest() { // Exception of Argument out of Range will be thrown only in case both are at least Cosnts.Max_VALID_LENGTH // Otherwise we know the numbers are different (number of digits is different) var phoneNumber = "SDFD df1234567888888888888888888888888888888888888888{"; var phoneNumber2 = "332434444444444444444"; PhoneNumberComparer.AreEqual(phoneNumber, phoneNumber2, _regexComparer); }
public void DifferentNumbersTest() { foreach (var pair in DifferentNumbers) { Assert.IsFalse(PhoneNumberComparer.AreEqual(pair.Item1, pair.Item2, _serialComparer)); Assert.IsFalse(PhoneNumberComparer.AreEqual(pair.Item1, pair.Item2, _regexComparer)); Assert.IsFalse(PhoneNumberComparer.AreEqual(pair.Item1, pair.Item2, _linqComparer)); } }
public void EqualNumbersTest() { foreach (var pair in EqualNumbers) { Assert.IsTrue(PhoneNumberComparer.AreEqual(pair.Item1, pair.Item2, _linqComparer)); Assert.IsTrue(PhoneNumberComparer.AreEqual(pair.Item1, pair.Item2, _regexComparer)); Assert.IsTrue(PhoneNumberComparer.AreEqual(pair.Item1, pair.Item2, _serialComparer)); } }
static void Main(string[] args) { Console.WriteLine("Welcome to Switchboard!"); Console.WriteLine($"Please note, input length is unlimited, while phone number should include less than '{Consts.MAX_VALID_LENGTH}' digits"); Console.WriteLine("===================================================================================="); do { Console.WriteLine("Enter the first phone number to compare"); var phoneA = Console.ReadLine(); Console.WriteLine("enter the second number"); var phoneB = Console.ReadLine(); Console.WriteLine("Choose comparison method: l - using Linq, r - using Regex, s - using Serial string comparison"); Console.WriteLine("In case other char than('l', 'r', 's') is entered comparison method will be default (Linq)"); var compareMethod = Console.ReadLine(); IEqualityComparer <string> comparer; switch (compareMethod) { case "l": comparer = new LinqCompare(); break; case "r": comparer = new RegexCompare(); break; case "s": comparer = new SerialCompare(); break; default: comparer = new LinqCompare(); break; } Stopwatch watch = new Stopwatch(); watch.Start(); try { var resultString = PhoneNumberComparer.AreEqual(phoneA, phoneB, comparer) ? "equal" : "not equal"; Console.WriteLine($"Numbers are {resultString}, operation took: '{watch.Elapsed}'"); } // Handle ArgumentOutOfRange exception, all other will crash the application currently by design catch (ArgumentOutOfRangeException) { Console.WriteLine($"Invalid numbers where entered, please enter numbers with less than '{Consts.MAX_VALID_LENGTH}' digits"); } }while (true); }
public void BothWhiteSpacesNumbersTest() { Assert.IsTrue(PhoneNumberComparer.AreEqual(" ", " ", _serialComparer)); Assert.IsTrue(PhoneNumberComparer.AreEqual(" ", " ", _regexComparer)); Assert.IsTrue(PhoneNumberComparer.AreEqual(" ", " ", _linqComparer)); }
public void BothEmptyNumbersTest() { Assert.IsTrue(PhoneNumberComparer.AreEqual(string.Empty, string.Empty, _serialComparer)); Assert.IsTrue(PhoneNumberComparer.AreEqual(string.Empty, string.Empty, _regexComparer)); Assert.IsTrue(PhoneNumberComparer.AreEqual(string.Empty, string.Empty, _linqComparer)); }