[TestMethod] // Поиск несуществующего элемента public void FindNotExistItemTest() { int n = 2; ArrayList<object> data = new ArrayList<object>(n); data.Append(8); data.Append(10); data.Find(3); }
[TestMethod] // Поиск существующего элемента public void FindItemTest() { int n = 2; ArrayList<object> data = new ArrayList<object>(n); data.Append(6); data.Append(11); data.Find(11); }
public void Play(string name) { sounds s = ArrayList.Find(sounds, sounds => sounds.name == name); if (s == null) { Debug.LogWarning("sound: " + name + " not found!"); return; } s.source.Play(); }
public void Test() { // Arrange var words = new ArrayList <string>(); // Act && Assert Assert.Equal(0, words.Count()); Assert.Equal(0, words.Capacity()); words.Add("hello"); Assert.Equal(1, words.Count()); Assert.Equal(1, words.Capacity()); Assert.Equal("hello", words.First()); Assert.Equal("hello", words.Last()); var found = words.Find(w => w == "hello"); Assert.Equal("hello", found); words[0] = "world"; Assert.Equal("world", words[0]); Assert.Equal(1, words.Count()); Assert.Equal(1, words.Capacity()); Assert.False(words.IsEmpty()); foreach (var word in words) { Assert.Equal("world", words[0]); Assert.Equal(1, words.Count()); Assert.Equal(1, words.Capacity()); Assert.False(words.IsEmpty()); } var removed = words.Remove("world"); Assert.True(removed); Assert.Equal(0, words.Count()); Assert.Equal(1, words.Capacity()); Assert.False(words.IsEmpty()); words.Clear(); Assert.Equal(0, words.Count()); Assert.Equal(0, words.Capacity()); Assert.True(words.IsEmpty()); }
public Fingerprint <T> Find(ulong pf) { return(fps.Find(delegate(Fingerprint <T> fp) { return fp.code == pf; })); }
/// <summary> /// /// </summary> /// <param name="item"></param> /// <returns></returns> public bool Find(ref T item) { return(innerlist.Find(ref item)); }
public static void Main(string[] args) { //====================================// 1 var student = new Student { Age = 19, Group = 4, Name = "Катя" }; ArrayList arrayList = new ArrayList { 6, 2, 11, 1, 9 }; arrayList.Add("строка"); arrayList.Add(student); arrayList.PrintCollection(); arrayList.RemoveAt(0); arrayList.PrintCollection(); int founded = arrayList.Find(student); Console.WriteLine($"Индекс искомого элемента: {founded}\n"); //====================================// 2 SortedDictionary <string, char> symbolDict = new SortedDictionary <string, char>(); //клавиатура symbolDict.Add("key_S_eng", 'S'); symbolDict.Add("key_S_rus", 'Ы'); symbolDict.Add("key_D_eng", 'D'); symbolDict.Add("key_D_rus", 'В'); symbolDict.Add("key_F_eng", 'F'); symbolDict.Add("key_F_rus", 'А'); symbolDict.Add("key_G_eng", 'G'); symbolDict.Add("key_G_rus", 'П'); symbolDict.PrintDictionary(); symbolDict.DeleteElementSequence(2, 1); symbolDict.PrintDictionary(); symbolDict.Add("key_W_eng", 'W'); symbolDict.Add("key_W_rus", 'Ц'); symbolDict.Add("key_Q_eng", 'Q'); symbolDict.Add("key_Q_rus", 'Й'); symbolDict.PrintDictionary(); LinkedList <char> symbList = new LinkedList <char>(); symbList.AddFirst(symbolDict.First().Value); foreach (var s in symbolDict.Skip(1)) { symbList.AddAfter(symbList.Last, s.Value); } symbList.PrintCollection(); LinkedListNode <char> foundedNode = symbList.Find('W'); if (foundedNode != null) { Console.WriteLine($"Искомый элемент: {foundedNode.Value}, Next :{foundedNode.Next?.Value}, Prev: {foundedNode.Previous?.Value}\n"); } //====================================// 3 SortedDictionary <string, Stone> stoneDict = new SortedDictionary <string, Stone>(); stoneDict.Add("rare_Ruby", new Ruby { Price = 130, Weight = 16 }); stoneDict.Add("common_Ruby", new Ruby { Price = 79, Weight = 11 }); stoneDict.Add("rare_Diamond", new Diamond { Price = 240, Weight = 15 }); stoneDict.Add("common_Diamond", new Diamond { Price = 360, Weight = 19 }); stoneDict.Add("rare_Nefrit", new Nefrit { Price = 122, Weight = 27 }); stoneDict.Add("common_Nefrit", new Nefrit { Price = 100, Weight = 20 }); stoneDict.PrintDictionary(); stoneDict.DeleteElementSequence(2, 1); stoneDict.PrintDictionary(); stoneDict.Add("exclusive_Diamond", new Diamond { Price = 450, Weight = 25 }); stoneDict.Add("exclusive_Ruby", new Diamond { Price = 190, Weight = 22 }); stoneDict.PrintDictionary(); LinkedList <Stone> stoneList = new LinkedList <Stone>(); stoneList.AddFirst(stoneDict.First().Value); foreach (var s in stoneDict.Skip(1)) { stoneList.AddAfter(stoneList.Last, s.Value); } stoneList.PrintCollection(); LinkedListNode <Stone> foundedStoneNode = stoneList.Find(new Diamond { Price = 450, Weight = 25 }); if (foundedStoneNode != null) { Console.WriteLine($"Искомый элемент: {foundedStoneNode.Value}, \n\tNext :{foundedStoneNode.Next?.Value}, \n\tPrev: {foundedStoneNode.Previous?.Value}\n"); } //====================================// 4 ObservableCollection <Stone> observableStones = new ObservableCollection <Stone>(stoneList); observableStones.CollectionChanged += OnCollectionChanged; observableStones.Add(new Nefrit { Price = 90, Weight = 34 }); observableStones.RemoveAt(0); observableStones.PrintCollection(); }
public static void DoTest() { int index = 0; var arrayList = new ArrayList <long>(); for (long i = 1; i < 1000000; ++i) { arrayList.Add(i); } for (int i = 1000; i < 1100; i++) { arrayList.RemoveAt(i); } for (int i = 100000; i < 100100; i++) { arrayList.Remove(i); } var allNumbersGreatorThanNineHundK = arrayList.FindAll(item => item > 900000); Assert.True(allNumbersGreatorThanNineHundK.Count > 0, "Count check failed!"); long nineHundK = arrayList.Find(item => item == 900000); var indexIfNineHundK = arrayList.FindIndex(item => item == nineHundK); Assert.True(indexIfNineHundK != -1, "Wrong index!"); index = 900000; arrayList.InsertAt(99999, index); arrayList.InsertAt(99999, index); arrayList.InsertAt(99999, index); arrayList.InsertAt(99999, index); arrayList.InsertAt(99999, index); var allNines = arrayList.FindAll(item => item == 99999); Assert.True(allNines.Count == 6, "Wrong result!"); bool doesMillionExist = arrayList.Exists(item => item == 1000000); Assert.False(doesMillionExist, "Wrong result!"); bool doesEightsExists = arrayList.Contains(88888); Assert.True(doesEightsExists, "Wrong result!"); //arrayList.Reverse (); var arrayList2 = new ArrayList <int>(); arrayList2.Add(0); arrayList2.Add(10); arrayList2.Add(20); arrayList2.Add(30); arrayList2.Add(40); arrayList2.Add(50); arrayList2.Add(60); arrayList2.Add(70); arrayList2.Add(80); arrayList2.Add(90); arrayList2.Add(100); // Console.WriteLine(arrayList2.ToHumanReadable(addHeader: true)); //var arrayList3 = arrayList.GetRange(0, 100); //Console.WriteLine(arrayList3.ToHumanReadable(addHeader: true)); /****************************************************************/ arrayList = new ArrayList <long>(); arrayList.AddRepeatedly(11, 32); Assert.True(arrayList.Count == 32, "Wrong array size."); }
[TestMethod] // Поиск в пустом списке public void FindInEmptyListTest() { int n = 2; ArrayList<object> data = new ArrayList<object>(n); data.Find(4); }