Exemple #1
0
 public void AListSize1Test()
 {
     var a = MakeAList();
     Person[] mas = new Person[1] { new Person(1, "rr", "qwer", 22) };
     a.Init(mas);
     int size = a.Size();
     Assert.AreEqual(1, size);
 }
Exemple #2
0
 public void AListSize0Test()
 {
     var a = MakeAList();
     Person[] mas = new Person[0];
     a.Init(mas);
     int size = a.Size();
     Assert.AreEqual(0, size);
 }
Exemple #3
0
 public void AListSize5Test()
 {
     Person[] mas = new Person[5] { new Person(1, "rr", "qwer", 22), new Person(2, "rr", "qwer", 22), new Person(3, "rr", "qwer", 22), new Person(4, "rr", "qwer", 22),
         new Person(5, "rr", "qwer", 22)};
     var a = MakeAList();
     a.Init(mas);
     int size = a.Size();
     Assert.AreEqual(5, size);
 }
        public void Del(Person person)
        {
            int key = person.GetHashCode(Size);

            if (hashArray[key] != null)
            {
                hashArray[key].Remove(person);
            }
            count--;
        }
        public void Init(Person[] arr)
        {
            Size = 997;
            hashArray = new List<Person>[Size];

            for (int i = 0; i < Size; i++)
            {
                Add(arr[i]);
            }
        }
        public void TestMethodHashAdd()
        {
            Hashtable ht = new Hashtable();
            ht.Init(array);
            var person = new Person ( "Neil", "Shay", 87 );
            ht.Add(person);

            var actualArr = ht.ToArray();
            Assert.AreEqual(person, ht.Get(person.ID));
            Assert.AreEqual(actualArr.Length, ht.Size);
        }
        public void TestMethodHashDel()
        {
            Hashtable ht = new Hashtable();
            ht.Init(array);
            var person = new Person("Kent", "Williams", 45);
            ht.Add(person);
            ht.Del(person);

            var actualArr = ht.ToArray();
            Assert.AreEqual(actualArr.Length, ht.Size);
        }
        public void Add(Person person)
        {
            int key = person.GetHashCode(Size);

            if (hashArray[key] == null)
            {
                hashArray[key] = new List<Person>();
            }

            hashArray[key].Add(person);
            count++;
        }
 public void AListAddStart16Test()
 {
     var a = new AList1<Person>();
     a.Init(mas);
     Person tmp = new Person(17, "rr", "qwer", 22);
     a.AddStart(tmp);
     int size = a.Size();
     Assert.AreEqual(17, size);
     mas = new Person[17] {new Person(17,"rr","qwer",22), new Person(1, "rr", "qwer", 22), new Person(2, "rr", "qwer", 22), new Person(3, "rr", "qwer", 22), new Person(4, "rr", "qwer", 22),
         new Person(5, "rr", "qwer", 22), new Person(6, "rr", "qwer", 22), new Person(7, "rr", "qwer", 22), new Person(8, "rr", "qwer", 22), new Person(9, "rr", "qwer", 22),
         new Person(10, "rr", "qwer", 22), new Person(11, "rr", "qwer", 22), new Person(12, "rr", "qwer", 22), new Person(13, "rr", "qwer", 22), new Person(14, "rr", "qwer", 22),
         new Person(15, "rr", "qwer", 22), new Person(16, "rr", "qwer", 22)};
     Assert.AreEqual(mas.ToString(), a.ToArray().ToString());
 }
        public void Del(Person person)
        {
            int key = person.GetHashCode(count);

            if (hashArray[key] != null)
            {
                while (person.ID != hashArray[key].ID)
                {
                    key++;
                }
                hashArray[key] = null;
                Size--;
            }
        }
        public void Add(Person person)
        {
            int key = person.GetHashCode(count);

            if (hashArray[key] != null)
            {
                while (hashArray[key] != null && key < count)
                {
                    key++;
                }
            }

            hashArray[key] = person;
            Size++;
        }
        public Person[] ToArray()
        {
            Person[] result = new Person[count];
            int j = 0;

            for (int i = 0; i < Size; i++)
            {
                if (hashArray[i] != null)
                {
                    foreach (var ha in hashArray[i])
                        result[j++] = ha;
                }
            }

            return result;
        }
Exemple #13
0
 public void AListHalfReverse1Test()
 {
     var a = MakeAList();
     var expectedRes = MakeAList();
     Person[] mas = new Person[1] { new Person(1, "rr", "qwer", 22)};
     a.Init(mas);
     mas = new Person[1] { new Person(1, "rr", "qwer", 22) };
     expectedRes.Init(mas);
     a.HalfReverse();
     Assert.AreEqual(1, a.Size());
     Assert.AreEqual(expectedRes.ToArray().ToString(), a.ToArray().ToString());
 }
Exemple #14
0
 public void AListMaxI1Test()
 {
     var a = MakeAList();
     Person[] mas = new Person[1] { new Person(1, "rr", "qwer", 22) };
     a.Init(mas);
     int res = a.MaxI();
     int expectedRes = 0;
     Assert.AreEqual(expectedRes, res);
 }
Exemple #15
0
 public void AListReversEvenTest()
 {
     var a = MakeAList();
     var expectedRes = MakeAList();
     Person[] mas = new Person[4] { new Person(1, "rr", "qwer", 22), new Person(2, "rr", "qwer", 22), new Person(11, "rr", "qwer", 22), new Person(4, "rr", "qwer", 22) };
     a.Init(mas);
     mas = new Person[4] { new Person(4, "rr", "qwer", 22), new Person(11, "rr", "qwer", 22), new Person(2, "rr", "qwer", 22), new Person(1, "rr", "qwer", 22) };
     expectedRes.Init(mas);
     a.Reverse();
     Assert.AreEqual(4, a.Size());
     Assert.AreEqual(expectedRes.ToArray().ToString(), a.ToArray().ToString());
 }
Exemple #16
0
 public void AListMaxIRandomTest()
 {
     var a = MakeAList();
     Person[] mas = new Person[5] { new Person(1, "rr", "qwer", 22), new Person(2, "rr", "qwer", 22), new Person(11, "rr", "qwer", 22), new Person(4, "rr", "qwer", 22),
         new Person(5, "rr", "qwer", 22) };
     a.Init(mas);
     int res = a.MaxI();
     int expectedRes = 2;
     Assert.AreEqual(expectedRes, res);
 }
Exemple #17
0
 public void AListAddPos1Test()
 {
     var a = MakeAList();
     var expectedRes = MakeAList();
     Person[] mas = new Person[1] { new Person(1, "rr", "qwer", 22)};
     a.Init(mas);
     mas = new Person[2] {new Person(6, "rr", "qwer", 22), new Person(1, "rr", "qwer", 22)};
     expectedRes.Init(mas);
     a.AddPos(0, new Person(6, "rr", "qwer", 22));
     Assert.AreEqual(2, a.Size());
     Assert.AreEqual((new Person(6, "rr", "qwer", 22)).ToString(), a.Get(0).ToString());
     Assert.AreEqual(expectedRes.ToArray().ToString(), a.ToArray().ToString());
 }
Exemple #18
0
 public void AListAddPosRandomTest()
 {
     var a = MakeAList();
     var expectedRes = MakeAList();
     Person[] mas = new Person[5] { new Person(1, "rr", "qwer", 22), new Person(2, "rr", "qwer", 22), new Person(3, "rr", "qwer", 22), new Person(4, "rr", "qwer", 22),
         new Person(5, "rr", "qwer", 22)};
     a.Init(mas);
     mas = new Person[6] { new Person(1, "rr", "qwer", 22), new Person(2, "rr", "qwer", 22), new Person(3, "rr", "qwer", 22), new Person(6, "rr", "qwer", 22), new Person(4, "rr", "qwer", 22),
         new Person(5, "rr", "qwer", 22)};
     expectedRes.Init(mas);
     a.AddPos(3, new Person(6, "rr", "qwer", 22));
     Assert.AreEqual(6, a.Size());
     Assert.AreEqual((new Person(6, "rr", "qwer", 22)).ToString(), a.Get(3).ToString());
     Assert.AreEqual(expectedRes.ToArray().ToString(), a.ToArray().ToString());
 }
Exemple #19
0
 public void AListMan2Test()
 {
     var a = MakeAList();
     Person[] mas = new Person[2] { new Person(1, "rr", "qwer", 22), new Person(2, "rr", "qwer", 22) };
     a.Init(mas);
     Person res = a.Max();
     Person expectedRes = new Person(2, "rr", "qwer", 22);
     Assert.AreEqual(expectedRes.ToString(), res.ToString());
 }
Exemple #20
0
 public void AListDelPosPosNotExistTest()
 {
     var a = MakeAList();
     Person[] mas = new Person[4] { new Person(1, "rr", "qwer", 22), new Person(2, "rr", "qwer", 22), new Person(4, "rr", "qwer", 22), new Person(5, "rr", "qwer", 22) };
     a.Init(mas);
     a.DelPos(10);
 }
Exemple #21
0
 public void AListAddPosPosNotExistTest()
 {
     var a = MakeAList();
     Person[] mas = new Person[5] { new Person(1, "rr", "qwer", 22), new Person(2, "rr", "qwer", 22), new Person(3, "rr", "qwer", 22), new Person(4, "rr", "qwer", 22),
         new Person(5, "rr", "qwer", 22)};
     a.Init(mas);
     a.AddPos(10, new Person(6, "rr", "qwer", 22));
 }
Exemple #22
0
 public void AListSetPosNotExistTest()
 {
     var a = MakeAList();
     Person[] mas = new Person[5] { new Person(1, "rr", "qwer", 22), new Person(2, "rr", "qwer", 22), new Person(11, "rr", "qwer", 22), new Person(4, "rr", "qwer", 22),
         new Person(5, "rr", "qwer", 22) };
     a.Init(mas);
     a.Set(8, new Person(10, "rr", "qwer", 22));
 }
Exemple #23
0
 public void AListClearTest()
 {
     var a = MakeAList();
     var expectedRes = MakeAList();
     Person[] mas = new Person[5] { new Person(1, "rr", "qwer", 22), new Person(2, "rr", "qwer", 22), new Person(3, "rr", "qwer", 22), new Person(4, "rr", "qwer", 22),
         new Person(5, "rr", "qwer", 22)};
     a.Init(mas);
     a.Clear();
     Assert.AreEqual(0, a.Size());
     Assert.AreEqual((expectedRes.ToArray()).ToString(), (a.ToArray()).ToString());
 }
Exemple #24
0
 public void AListGetOneEllTest()
 {
     var a = MakeAList();
     Person[] mas = new Person[] { new Person(1, "rr", "qwer", 22) };
     a.Init(mas);
     Person expectedRes = new Person(1, "rr", "qwer", 22);
     Person res = a.Get(0);
     Assert.AreEqual(expectedRes.ToString(), res.ToString());
 }
Exemple #25
0
 public void AListGetRandomTest()
 {
     var a = MakeAList();
     Person[] mas = new Person[5] { new Person(1, "rr", "qwer", 22), new Person(2, "rr", "qwer", 22), new Person(11, "rr", "qwer", 22), new Person(4, "rr", "qwer", 22),
         new Person(5, "rr", "qwer", 22) };
     a.Init(mas);
     Person expectedRes = new Person(2, "rr", "qwer", 22);
     Person res = a.Get(2);
     Assert.AreEqual(expectedRes.ToString(), res.ToString());
 }
Exemple #26
0
 public void AListDelStart2Test()
 {
     var a = MakeAList();
     Person[] mas = new Person[2] { new Person(6, "rr", "qwer", 22), new Person(1, "rr", "qwer", 22)};
     a.Init(mas);
     Person expectedRes = new Person(6, "rr", "qwer", 22);
     Person res = a.DelStart();
     mas = new Person[] { new Person(1, "rr", "qwer", 22) };
     Assert.AreEqual(1, a.Size());
     Assert.AreEqual(expectedRes.ToString(), res.ToString());
     Assert.AreEqual(mas.ToString(), a.ToArray().ToString());
 }
Exemple #27
0
 public void AListSet2EllTest()
 {
     var a = MakeAList();
     var expectedRes = MakeAList();
     Person[] mas = new Person[2] { new Person(1, "rr", "qwer", 22), new Person(2, "rr", "qwer", 22) };
     a.Init(mas);
     mas = new Person[2] { new Person(1, "rr", "qwer", 22), new Person(10, "rr", "qwer", 22) };
     expectedRes.Init(mas);
     a.Set(1, new Person(10, "rr", "qwer", 22));
     Assert.AreEqual(2, a.Size());
     Assert.AreEqual(expectedRes.ToArray().ToString(), a.ToArray().ToString());
 }
Exemple #28
0
 public void AListDelPosRandomTest()
 {
     var a = MakeAList();
     Person[] mas = new Person[5] { new Person(1, "rr", "qwer", 22), new Person(2, "rr", "qwer", 22), new Person(3, "rr", "qwer", 22), new Person(4, "rr", "qwer", 22),
         new Person(5, "rr", "qwer", 22) };
     a.Init(mas);
     Person expectedRes = new Person(3, "rr", "qwer", 22);
     Person res = a.DelPos(2);
     mas = new Person[4] { new Person(1, "rr", "qwer", 22), new Person(2, "rr", "qwer", 22), new Person(4, "rr", "qwer", 22), new Person(5, "rr", "qwer", 22) };
     Assert.AreEqual(4, a.Size());
     Assert.AreEqual(expectedRes.ToString(), res.ToString());
     Assert.AreEqual(mas.ToString(), a.ToArray().ToString());
 }
Exemple #29
0
 public void AListSortRandomTest()
 {
     var a = MakeAList();
     var expectedRes = MakeAList();
     Person[] mas = new Person[5] { new Person(1, "rr", "qwer", 22), new Person(4, "rr", "qwer", 22), new Person(11, "rr", "qwer", 22), new Person(1, "rr", "qwer", 22),
         new Person(5, "rr", "qwer", 22) };
     a.Init(mas);
     mas = new Person[5] { new Person(1, "rr", "qwer", 22), new Person(2, "rr", "qwer", 22), new Person(4, "rr", "qwer", 22), new Person(5, "rr", "qwer", 22),
         new Person(11, "rr", "qwer", 22) };
     expectedRes.Init(mas);
     a.Sort();
     Assert.AreEqual(5, a.Size());
     Assert.AreEqual(expectedRes.ToArray().ToString(), a.ToArray().ToString());
 }
Exemple #30
0
 public void AListDelPos1Test()
 {
     var a = MakeAList();
     Person[] mas = new Person[1] { new Person(1, "rr", "qwer", 22) };
     a.Init(mas);
     Person expectedRes = new Person(1, "rr", "qwer", 22);
     Person res = a.DelPos(0);
     mas = new Person[0];
     Assert.AreEqual(0, a.Size());
     Assert.AreEqual(expectedRes.ToString(), res.ToString());
     Assert.AreEqual(mas.ToString(), a.ToArray().ToString());
 }