public void RemoveByItem_Test()
        {
            dict = new MyDictionary <int, int>(true);

            dict.Add(0, 00);
            dict.Add(1, 11);
            dict.Add(5, 23);
            dict.Add(7, 7);
            dict.Add(9, 77);
            dict.Add(6, 77);
            dict.Add(5, 22);
            dict.Add(5, 24);

            dict.Remove(new KeyValuePair <int, int>(5, 24));
            dict.Remove(new KeyValuePair <int, int>(5, 22));
            dict.Remove(new KeyValuePair <int, int>(5, 23));

            Assert.AreEqual(5, dict.Count);
            Assert.AreEqual(false, dict.ContainsKey(5), "Contains");
            Assert.AreEqual(true, dict.Contains(new KeyValuePair <int, int>(0, 00)));
            Assert.AreEqual(true, dict.Contains(new KeyValuePair <int, int>(1, 11)));
            Assert.AreEqual(false, dict.Contains(new KeyValuePair <int, int>(5, 22)), "5, 22");
            Assert.AreEqual(false, dict.Contains(new KeyValuePair <int, int>(5, 23)), "5, 23");
            Assert.AreEqual(false, dict.Contains(new KeyValuePair <int, int>(5, 24)), "5, 24");
        }
        public static void Contains()
        {
            MyDictionary dictBase = CreateDictionary(100);

            for (int i = 0; i < dictBase.Count; i++)
            {
                Assert.True(dictBase.Contains(CreateKey(i)));
            }
            Assert.False(dictBase.Contains(new FooKey()));
        }
        public void AddPair_Test()
        {
            KeyValuePair <int, int> pair1 = new KeyValuePair <int, int>(0, 00);
            KeyValuePair <int, int> pair2 = new KeyValuePair <int, int>(1, 11);
            KeyValuePair <int, int> pair3 = new KeyValuePair <int, int>(2, 22);

            dict.Add(pair1);
            dict.Add(pair2);
            dict.Add(pair3);

            Assert.AreEqual(3, dict.Count);
            Assert.AreEqual(true, dict.Contains(pair1));
            Assert.AreEqual(true, dict.Contains(pair2));
            Assert.AreEqual(true, dict.Contains(pair3));
        }
        public void RemoveByKey_Test()
        {
            dict = new MyDictionary <int, int>(true);

            dict.Add(0, 00);
            dict.Add(1, 11);
            dict.Add(1, 12);
            dict.Add(2, 22);

            dict.Remove(1);


            Assert.AreEqual(3, dict.Count);
            Assert.AreEqual(true, dict.ContainsKey(1));
            Assert.AreEqual(false, dict.Contains(new KeyValuePair <int, int>(1, 11)));
            Assert.AreEqual(true, dict.Contains(new KeyValuePair <int, int>(1, 12)));
            Assert.AreEqual(12, dict[1]);
        }
        public void MyDictionaryContainsTest()
        {
            KeyValuePair <int, string>[] pairs =
            {
                new KeyValuePair <int, string>(50, "Vasya"),
                new KeyValuePair <int, string>(38, "Stepan"),
                new KeyValuePair <int, string>(77, "Lilo"),
                new KeyValuePair <int, string>(13, "Stich"),
                new KeyValuePair <int, string>(20, "Alladin"),
                new KeyValuePair <int, string>(90, "Gaben"),
                new KeyValuePair <int, string>(45, "IceFrog")
            };
            MyDictionary <int, string> dict = new MyDictionary <int, string>(pairs);

            Assert.IsTrue(dict.Contains(new KeyValuePair <int, string>(20, "Alladin")));
            Assert.IsTrue(dict.Contains(new KeyValuePair <int, string>(13, "Stich")));
            Assert.IsFalse(dict.Contains(new KeyValuePair <int, string>(18, "Not Contains")));
        }
        public static void Keys()
        {
            MyDictionary dictBase = CreateDictionary(100);
            ICollection  keys     = dictBase.Keys;

            Assert.Equal(dictBase.Count, keys.Count);
            foreach (FooKey key in keys)
            {
                Assert.True(dictBase.Contains(key));
            }
        }
Exemple #7
0
        public void Contains()
        {
            MyDictionary <int, int> dictionary = new MyDictionary <int, int>();

            Assert.AreEqual(0, dictionary.Count);
            dictionary.Add(5, 2);
            dictionary.Add(2, 6);
            dictionary.Add(6, 6);
            dictionary.Add(252, 6);
            Assert.AreEqual(true, dictionary.Contains(2));
        }
Exemple #8
0
        public void ContanceTest()
        {
            MyDictionary <int, int> dictionary = new MyDictionary <int, int>();

            dictionary.Add(10, 25);
            dictionary.Add(15, 50);
            dictionary.Add(20, 99);
            Assert.IsTrue(dictionary.Contains(new KeyValuePair <int, int>(10, 25)));
            Assert.IsTrue(dictionary.Contains(new KeyValuePair <int, int>(15, 50)));
            Assert.IsTrue(dictionary.Contains(new KeyValuePair <int, int>(20, 99)));
            Assert.IsFalse(dictionary.Contains(new KeyValuePair <int, int>(10, 30)));
            Assert.IsFalse(dictionary.Contains(new KeyValuePair <int, int>(15, 90)));
            Assert.IsFalse(dictionary.Contains(new KeyValuePair <int, int>(20, 79)));
            Assert.IsFalse(dictionary.Contains(new KeyValuePair <int, int>(0, 79)));
            Assert.IsFalse(dictionary.Contains(new KeyValuePair <int, int>(1, 79)));
            Assert.IsFalse(dictionary.Contains(new KeyValuePair <int, int>(100, 79)));
        }
        public static void Remove()
        {
            MyDictionary dictBase = CreateDictionary(100);

            for (int i = 0; i < 100; i++)
            {
                FooKey key = CreateKey(i);
                dictBase.Remove(key);
                Assert.False(dictBase.Contains(key));
            }
            Assert.Equal(0, dictBase.Count);
            dictBase.Remove(new FooKey()); // Doesn't exist, but doesn't throw
        }
        public void WorkCollectionInheritedClasses()
        {
            //throw new NotImplementedException();
            Student student1 = new Student("Имя", "Фамилия", 11, new DateTime(1967, 1, 1), 1);
            Student student2 = new Student("Имя", "Фамилия", 22, new DateTime(1967, 1, 1), 2);
            Student student3 = new Student("Имя", "Фамилия", 33, new DateTime(1967, 1, 1), 3);
            Student student4 = new Student("Имя", "Фамилия", 44, new DateTime(1967, 1, 1), 4);

            MyDictionary groupForDictionary = new MyDictionary();
            groupForDictionary.Add(student1);
            groupForDictionary.Add(student2);
            groupForDictionary.Add(student3);
            groupForDictionary.Add(student4);

            Tuple<string, string, int, DateTime> workKey = Tuple.Create<string, string, int, DateTime>("Имя", "Фамилия", 22, new DateTime(1967, 1, 1));
            if (!groupForDictionary.Contains(workKey))
            {
                Console.WriteLine("Нет такого студента");
            }

            MyCollection<Student> groupForCollection = new MyCollection<Student>();
            groupForCollection.Add(student1);
            groupForCollection.Add(student3);

            Console.WriteLine("Студент 1,3");
            foreach (Student workStudent in groupForCollection)
            {
                Console.WriteLine("{0} {1} : {2}, {3}, {4} ", workStudent.firstName,
                                                              workStudent.secondName,
                                                              workStudent.birthDate,
                                                              workStudent.rating,
                                                              workStudent.personalCode);
            }

            groupForCollection.Insert(1, student2);
            groupForCollection.Remove(student1);
            groupForCollection.Add(student4);

            Console.WriteLine("+ Студент2, -Студент1,+ Студент4");
            foreach (Student workStudent in groupForCollection)
            {
                Console.WriteLine("{0} {1} : {2}, {3}, {4} ", workStudent.firstName,
                                                                  workStudent.secondName,
                                                                  workStudent.birthDate,
                                                                  workStudent.rating,
                                                                  workStudent.personalCode);
            }

            Console.ReadKey();
        }
        public void WorkCollectionInheritedClasses()
        {
            MyDictionary studentsBase = new MyDictionary();

            Student st1 = new Student() {firstName = "1", lastName = "2", birthDate = new DateTime(12,12,2012) };
            Tuple<string, string, DateTime> st1Key = new Tuple<string, string, DateTime>("1", "2", new DateTime(12, 12, 2012));

            if (studentsBase.Contains(st1))
            {
                studentsBase.Add(st1);
                Student st1Copy = studentsBase[st1Key];
            }
            else
            {
                Console.WriteLine("Student is not found");
            }
        }
Exemple #12
0
        public static void Add()
        {
            var dictBase = new MyDictionary();
            for (int i = 0; i < 100; i++)
            {
                FooKey key = CreateKey(i);
                dictBase.Add(key, CreateValue(i));
                Assert.True(dictBase.Contains(key));
            }

            Assert.Equal(100, dictBase.Count);
            for (int i = 0; i < dictBase.Count; i++)
            {
                Assert.Equal(CreateValue(i), dictBase[CreateKey(i)]);
            }

            FooKey nullKey = CreateKey(101);
            dictBase.Add(nullKey, null);
            Assert.Equal(null, dictBase[nullKey]);
        }
        public static void Add()
        {
            var dictBase = new MyDictionary();

            for (int i = 0; i < 100; i++)
            {
                FooKey key = CreateKey(i);
                dictBase.Add(key, CreateValue(i));
                Assert.True(dictBase.Contains(key));
            }

            Assert.Equal(100, dictBase.Count);
            for (int i = 0; i < dictBase.Count; i++)
            {
                Assert.Equal(CreateValue(i), dictBase[CreateKey(i)]);
            }

            FooKey nullKey = CreateKey(101);

            dictBase.Add(nullKey, null);
            Assert.Null(dictBase[nullKey]);
        }
        public void WorkCollectionInheritedClasses()
        {
            Student firstStudent = new Student("Alina", "Kylish", 123456789, new DateTime(1988, 4, 3));
            Student secondStudent = new Student("Elena", "Kylish", 987654321, new DateTime(1987, 8, 15));
            Student thirdStudent = new Student("Oleg", "Ivanov", 975312468, new DateTime(1992, 11, 20));
            MyDictionary students = new MyDictionary();
            Tuple<string, string, int> key = new Tuple<string,string,int>("Alina", "Kylish", 123456789);
            students.Add(firstStudent);
            if (!students.Contains(key))
            {
                Console.WriteLine("This key is not found");
            }
            else
            {
                Console.WriteLine("This key is found");
            }

            MyCollection students1 = new MyCollection();
            students1.Add(firstStudent);
            students1.Add(secondStudent);
            students1.Insert(0, thirdStudent);
            students1.Add(firstStudent);
            students1.Remove(firstStudent);
            students1.Clear();
            Console.ReadKey();
        }