public void Runs() { var a = new [] { 2, 1, 3, 5, 3, 2 }; var firstDuplciate = FirstDuplicate.Run(a); Assert.Equal(3, firstDuplciate); }
public void firstDuplicateTest() { var f = new FirstDuplicate(); Assert.AreEqual(3, f.firstDuplicate(new[] { 2, 3, 3, 1, 5, 2 })); Assert.AreEqual(-1, f.firstDuplicate(new[] { 2, 4, 3, 5, 1 })); Assert.AreEqual(-1, f.firstDuplicate(new[] { 1 })); Assert.AreEqual(2, f.firstDuplicate(new[] { 2, 2 })); Assert.AreEqual(-1, f.firstDuplicate(new[] { 2, 1 })); Assert.AreEqual(-1, f.firstDuplicate(new[] { 2, 1, 3 })); Assert.AreEqual(3, f.firstDuplicate(new[] { 2, 3, 3 })); Assert.AreEqual(3, f.firstDuplicate(new[] { 3, 3, 3 })); Assert.AreEqual(6, f.firstDuplicate(new[] { 8, 4, 6, 2, 6, 4, 7, 9, 5, 8 })); Assert.AreEqual(-1, f.firstDuplicate(new[] { 10, 6, 8, 4, 9, 1, 7, 2, 5, 3 })); }
public static void Main(String[] args) { #region FirstDuplicateDemo FirstDuplicate firstDuplicate = new FirstDuplicate(); //int[] inputArray = new int[] { 2, 1, 3, 5, 3, 2 }; int[] inputArray = new int[] { 1, 2, 1, 2, 3, 3 }; int output = firstDuplicate.Duplicate(inputArray); Console.WriteLine("Duplicate number: " + output); output = firstDuplicate.DuplicateByDictionary(inputArray); Console.WriteLine("Duplicate number: " + output); #endregion #region NonRepeatingCharacter StringManageMent stringMangement = new StringManageMent(); string input = "aaabcccdeeef"; char ch = stringMangement.NonRepeatingCharByCountArray(input); Console.WriteLine("Expected output: " + ch); ch = stringMangement.NonRepeatingCharByDicktionary(input); Console.WriteLine("Expected output: " + ch); ch = stringMangement.NonRepeatingCharByMethod(input); Console.WriteLine("Expected output: " + ch); #endregion #region DelegateEventDemo /* var video = new Video() { Title = "Video 1" }; * var videoEncoder = new VideoEncoder(); //publisher * * var mail = new MailService(); //subscriber * var message = new MessageService(); * * videoEncoder.VideoEncoded += mail.OnVideoEncoded; * videoEncoder.VideoEncoded += message.OnVideoEncoded; * * videoEncoder.Encode(video);*/ #endregion #region RandomClassUsesDemo /* RandomGenerator generator = new RandomGenerator(); * * Random random = new Random(); * int num = random.Next(1000); //a random number. * int num2 = random.Next(1000); //a random number less than 1000. * * int rand = generator.RandomNumber(5, 100); * Console.WriteLine($"Random number between 5 and 100 is {rand}"); * * string str = generator.RandomString(10, false); * Console.WriteLine($"Random string of 10 chars is {str}"); * * string pass = generator.RandomPassword(); * Console.WriteLine($"Random string of 6 chars is {pass}"); * * Console.ReadKey();*/ #endregion }
public void Test1() { var result = FirstDuplicate.firstDuplicate(new[] { 2, 1, 3, 4, 3, 2 }); Assert.AreEqual(3, result); }
public void Test11() { var result = FirstDuplicate.firstDuplicate(new[] { 1, 1, 2, 2, 1 }); Assert.AreEqual(1, result); }
public void Test8() { var result = FirstDuplicate.firstDuplicate(new[] { 3, 3, 3 }); Assert.AreEqual(3, result); }
public void Test4() { var result = FirstDuplicate.firstDuplicate(new[] { 2, 1 }); Assert.AreEqual(-1, result); }