public void Test_ShowFirstUnique() { FirstUnique sut = new FirstUnique(new int[] { 2, 3, 5 }); Assert.Equal(2, sut.ShowFirstUnique()); sut.Add(5); Assert.Equal(2, sut.ShowFirstUnique()); sut.Add(2); Assert.Equal(3, sut.ShowFirstUnique()); sut.Add(3); Assert.Equal(-1, sut.ShowFirstUnique()); }
public void Test_ShowFirstUnique2() { FirstUnique sut = new FirstUnique(new int[] { 7, 7, 7, 7, 7, 7 }); Assert.Equal(-1, sut.ShowFirstUnique()); sut.Add(7); sut.Add(3); sut.Add(3); sut.Add(7); sut.Add(17); Assert.Equal(17, sut.ShowFirstUnique()); }
public void FirstUniqueTest2() { FirstUnique firstUnique = new FirstUnique(new[] { 7, 7, 7, 7, 7, 7 }); Assert.Equal(-1, firstUnique.ShowFirstUnique()); firstUnique.Add(7); firstUnique.Add(3); firstUnique.Add(3); firstUnique.Add(7); firstUnique.Add(17); Assert.Equal(17, firstUnique.ShowFirstUnique()); }
public void FirstUniqueTest1() { FirstUnique firstUnique = new FirstUnique(new[] { 2, 3, 5 }); Assert.Equal(2, firstUnique.ShowFirstUnique()); firstUnique.Add(5); // the queue is now [2,3,5,5] Assert.Equal(2, firstUnique.ShowFirstUnique()); // return 2 firstUnique.Add(2); // the queue is now [2,3,5,5,2] Assert.Equal(3, firstUnique.ShowFirstUnique()); // return 3 firstUnique.Add(3); // the queue is now [2,3,5,5,2,3] Assert.Equal(-1, firstUnique.ShowFirstUnique()); // return -1 }
public void Test2() { FirstUnique firstUnique = new FirstUnique(new[] { 7, 7, 7, 7, 7, 7 }); int unique = firstUnique.ShowFirstUnique(); // return -1 unique.Should().Be(-1); firstUnique.Add(7); // the queue is now [7,7,7,7,7,7,7] firstUnique.Add(3); // the queue is now [7,7,7,7,7,7,7,3] firstUnique.Add(3); // the queue is now [7,7,7,7,7,7,7,3,3] firstUnique.Add(7); // the queue is now [7,7,7,7,7,7,7,3,3,7] firstUnique.Add(17); // the queue is now [7,7,7,7,7,7,7,3,3,7,17] unique = firstUnique.ShowFirstUnique(); unique.Should().Be(17); }
public void Test_ShowFirstUnique3() { FirstUnique sut = new FirstUnique(new int[] { 809 }); Assert.Equal(809, sut.ShowFirstUnique()); sut.Add(809); Assert.Equal(-1, sut.ShowFirstUnique()); }
public void FirstUniqueTest3() { FirstUnique firstUnique = new FirstUnique(new[] { 809 }); Assert.Equal(809, firstUnique.ShowFirstUnique()); firstUnique.Add(809); Assert.Equal(-1, firstUnique.ShowFirstUnique()); }
public void Test1() { FirstUnique firstUnique = new FirstUnique(new[] { 2, 3, 5 }); int unique = firstUnique.ShowFirstUnique(); // return 2 unique.Should().Be(2); firstUnique.Add(5); // the queue is now [2,3,5,5] unique = firstUnique.ShowFirstUnique(); // return 2 unique.Should().Be(2); firstUnique.Add(2); // the queue is now [2,3,5,5,2] unique = firstUnique.ShowFirstUnique(); // return 3 unique.Should().Be(3); firstUnique.Add(3); // the queue is now [2,3,5,5,2,3] unique = firstUnique.ShowFirstUnique(); // return -1 unique.Should().Be(-1); }
public String Test(String input1, String input2) { var actions = JsonConvert.DeserializeObject <String[]>(input1); var parameters = JsonConvert.DeserializeObject <Object[][]>(input2); var result = new List <Int32?>(); FirstUnique firstUnique = null; Console.WriteLine("FirstUnique firstUnique = null;"); for (Int32 i = 0; i < actions.Length; i++) { String action = actions[i]; switch (action) { case "FirstUnique": Int32[] nums = ((JArray)parameters[i][0]).Select(o => (Int32)o).ToArray(); Console.WriteLine("firstUnique = new FirstUnique([{0}]);", String.Join(",", nums)); firstUnique = new FirstUnique(nums); result.Add(null); break; case "showFirstUnique": Console.Write("firstUnique.showFirstUnique();"); Int32?value = firstUnique?.ShowFirstUnique(); if (value != null) { Console.WriteLine("\t\t// returns: {0}{1}", value, value == -1 ? " (not found)" : null); } else { Console.WriteLine(); } result.Add(value); break; case "add": Console.Write("firstUnique.add({0});", (Int32)(Int64)parameters[i][0]); firstUnique?.Add(value: (Int32)(Int64)parameters[i][0]); if (firstUnique != null) { Console.WriteLine("\t\t// the queue is [{0}]", String.Join(",", firstUnique)); } else { Console.WriteLine(); } result.Add(null); break; } } return(JsonConvert.SerializeObject(result)); }
public void Test3() { FirstUnique firstUnique = new FirstUnique(new[] { 809 }); int unique = firstUnique.ShowFirstUnique(); // return 809 unique.Should().Be(809); firstUnique.Add(809); // the queue is now [809,809] unique = firstUnique.ShowFirstUnique(); unique.Should().Be(-1); }