public void CopyConstructorTest()
 {
     MyList<int> List = new MyArrayList<int>();
     List.Add(1);
     List.Add(2);
     MyList<int> List2 = new MyArrayList<int>(List);
     Assert.AreEqual(List2, List);
 }
 public void ClearTest()
 {
     MyList<int> List = new MyArrayList<int>();
     List.Add(1);
     List.Add(2);
     List.Clear();
     Assert.AreEqual(List.Count, 0);
     Assert.AreEqual((List as MyArrayList<int>).Capacity, 10);
 }
 public void AddMoreThanCapacityTest()
 {
     int actualCapacity = 1;
     int actualValue = 52;
     MyList<int> List = new MyArrayList<int>(actualCapacity);
     List.Add(1);
     List.Add(actualValue);
     Assert.AreEqual(List.Count, 2);
     Assert.AreEqual((List as MyArrayList<int>).Capacity, actualCapacity + 10);
     Assert.AreEqual(List[1], actualValue);
 }
        public void AddTest()
        {
            int actualValue = 38;
            MyList<int> List = new MyArrayList<int>();
            List.Add(actualValue);
            Assert.AreEqual(List.Count, 1);
            Assert.AreEqual(List[0], actualValue);

        }
 public void RemoveExistingElementTest()
 {
     MyList<int> List = new MyArrayList<int>();
     List.Add(75);
     List.Add(57);
     List.Add(50);
     Assert.AreEqual(List.Remove(57), true);
     Assert.AreEqual(List.Contains(57), false);
 }
Exemple #6
0
        static void Main(string[] args)
        {
            ArrayList arrayList = new ArrayList();

            arrayList.Add(0);
            arrayList.Add(0.67);
            arrayList.Add('a');
            arrayList.Add("elem");
            arrayList.Add(new MyClass());

            for (int i = 0; i < arrayList.Count; i++)
            {
                Console.WriteLine(arrayList[i]);
            }


            Console.WriteLine(new string('-', 50));


            Console.WriteLine("Our fleet of cars:");
            var park = new CarCollection <string>();

            park.AddCar("Lada", new DateTime(1985, 12, 5));
            park.AddCar("Toyota", new DateTime(2000, 4, 7));
            park.AddCar("Ford", new DateTime(2005, 5, 3));
            park.AddCar("Mercedes", new DateTime(2003, 11, 3));

            Console.WriteLine(park.ToString());

            Console.WriteLine("In the park are: {0} cars", park.Lenght);

            Console.WriteLine("Enter the number of the car you are interested in:");
            string stroka = Console.ReadLine();

            if (string.IsNullOrEmpty(stroka))
            {
                Console.WriteLine("You have not entered a value. Search failed.");
            }
            else
            {
                int nomer = Convert.ToInt32(stroka);
                Console.WriteLine(park[nomer - 1]);
            }


            Console.WriteLine(new string('-', 50));


            Console.WriteLine("Dictionary:");

            var dic = new Essential11_3.Dictionary <string, string>();

            dic.AddToDictionary("table", "стол");
            dic.AddToDictionary("apple", "яблоко");
            dic.AddToDictionary("sun", "солнце");
            dic.AddToDictionary("pencil", "карандаш");
            dic.AddToDictionary("cap", "чашка");
            dic.AddToDictionary("tea", "чай");

            Console.WriteLine(dic.ToString());
            Console.WriteLine();
            Console.WriteLine("In the dictionary {0} entries", dic.Lenght);
            Console.WriteLine(new string('-', 30));

            Console.WriteLine("Enter the entry number in the dictionary:");
            string str = Console.ReadLine();

            if (string.IsNullOrEmpty(str))
            {
                Console.WriteLine("You did not enter a dictionary entry number");
            }
            else
            {
                int nomer = Convert.ToInt32(str);
                Console.WriteLine(dic[nomer - 1]);
            }

            Console.WriteLine("Enter a value to search");
            string p = Console.ReadLine();

            Console.WriteLine(dic[p]);


            Console.WriteLine(new string('-', 50));


            MyArrayList m = new MyArrayList();

            m.Add(5);
            m.Add("Hello");
            m.Add('d');
            m.Add(5.78);

            Console.WriteLine("Array:");
            Console.WriteLine(m.ToString());

            Console.ReadKey();
        }
 public void InsertMoreThanRangeTest()
 {
     MyList<int> List = new MyArrayList<int>();
     List.Add(55);
     List.Add(41);
     List.Insert(79, 10);
     Assert.AreEqual(List[2], 79);
 }
 public void GetElementInRange()
 {
     MyList<int> List = new MyArrayList<int>();
     List.Add(52);
     List.Add(95);
     Assert.AreEqual(List.Get(0), 52);
     Assert.AreEqual(List.Get(1), 95);
 }
 public void GetElementOutOfRange()
 {
     MyList<int> List = new MyArrayList<int>();
     List.Add(52);
     List.Add(95);
     try
     {
         List.Get(2);
     }
     catch (IndexOutOfRangeException e)
     {
         StringAssert.Contains(e.Message, "Индекс вне диапазона.");
     }
 }
 public void InvalidCopyToArray()
 {
     int[] array = new int[2];
     MyList<int> List = new MyArrayList<int>();
     List.Add(51);
     List.Add(94);
     try
     {
         List.CopyTo(array, 2);
     }
     catch (IndexOutOfRangeException e)
     {
         StringAssert.Contains(e.Message, "Индекс вне диапазона.");
     }
 }
 public void FindNotExistingElement()
 {
     MyList<int> List = new MyArrayList<int>();
     List.Add(8);
     List.Add(61);
     Assert.AreEqual(List.Find(5), -1);
 }
 public void CopyToArray()
 {
     int[] array = new int[2];
     MyList<int> List = new MyArrayList<int>();
     List.Add(51);
     List.Add(94);
     List.CopyTo(array, 0);
     Assert.AreEqual(array[0], 51);
     Assert.AreEqual(array[1], 94);
 }
        public override List <DeviceFieldForUI> getDeviceFocusFields()
        {
            Dictionary <string, DeviceFieldForUI> map = this.getBaseInfoFields();
            var list = new MyArrayList <DeviceFieldForUI>();

            list.Add(GetUiItem(getBaseInfoFields(), SdcSoftDevice.KEY_POINT_RUN_DAYS));
            list.Add(GetUiItem(getBaseInfoFields(), SdcSoftDevice.KEY_POINT_RUN_HOURS));
            if (map[SdcSoftDevice.KEY_POINT_POWER].getValue().Equals(Power.Dian))
            {
                if (map[SdcSoftDevice.KEY_POINT_MEDIA].getValue().Equals(Media.ReShui))
                {
                    list.Add(GetUiItem(getDeviceFields(), "de_jiarezu"));
                    list.Add(GetUiItem(getMockFields(), "mo_chukouwendu"));
                    list.Add(GetUiItem(getMockFields(), "mo_rukouwendu"));
                    list.Add(GetUiItem(getBaseInfoFields(), "ba_shuixiangshuiweizhuangtai"));
                    list.Add(GetUiItem(getBaseInfoFields(), "ba_guolushuiweizhuangtai"));
                }
                else if (map[SdcSoftDevice.KEY_POINT_MEDIA].getValue().Equals(Media.DaoReYou))
                {
                }
                else if (map[SdcSoftDevice.KEY_POINT_MEDIA].getValue().Equals(Media.ReFeng))
                {
                }
                else if (map[SdcSoftDevice.KEY_POINT_MEDIA].getValue().Equals(Media.ZhengQi))
                {
                    list.Add(GetUiItem(getDeviceFields(), "de_jiarezu"));
                    list.Add(GetUiItem(getBaseInfoFields(), "ba_guolushuiweizhuangtai"));
                    if (this.getBaseInfoFields().ContainsKey("ba_guoluyalizhuangtai"))
                    {
                        list.Add(GetUiItem(getBaseInfoFields(), "ba_guoluyalizhuangtai"));
                    }
                    else
                    {
                        list.Add(GetUiItem(getMockFields(), "mo_zhengqiyali"));
                    }
                }
                else if (map[SdcSoftDevice.KEY_POINT_MEDIA].getValue().Equals(Media.ZhenKong))
                {
                }
            }
            else if (map[SdcSoftDevice.KEY_POINT_POWER].getValue().Equals(Power.Mei))
            {
                if (map[SdcSoftDevice.KEY_POINT_MEDIA].getValue().Equals(Media.ReShui))
                {
                    list.Add(GetUiItem(getMockFields(), "mo_paiyanwendu"));
                    list.Add(GetUiItem(getMockFields(), "mo_chukouwendu"));
                    list.Add(GetUiItem(getMockFields(), "mo_rukouwendu"));
                    if (this.getBaseInfoFields().ContainsKey("ba_guoluyalizhuangtai"))
                    {
                        list.Add(GetUiItem(getBaseInfoFields(), "ba_guoluyalizhuangtai"));
                    }
                    else
                    {
                        list.Add(GetUiItem(getMockFields(), "mo_zhengqiyali"));
                    }
                }
                else if (map[SdcSoftDevice.KEY_POINT_MEDIA].getValue().Equals(Media.DaoReYou))
                {
                    list.Add(GetUiItem(getMockFields(), "mo_paiyanwendu"));
                    list.Add(GetUiItem(getMockFields(), "mo_chukouwendu"));
                    list.Add(GetUiItem(getMockFields(), "mo_rukouwendu"));
                    if (this.getBaseInfoFields().ContainsKey("ba_guoluyalizhuangtai"))
                    {
                        list.Add(GetUiItem(getBaseInfoFields(), "ba_guoluyalizhuangtai"));
                    }
                    else
                    {
                        list.Add(GetUiItem(getMockFields(), "mo_zhengqiyali"));
                    }
                }
                else if (map[SdcSoftDevice.KEY_POINT_MEDIA].getValue().Equals(Media.ReFeng))
                {
                }
                else if (map[SdcSoftDevice.KEY_POINT_MEDIA].getValue().Equals(Media.ZhengQi))
                {
                    if (this.getBaseInfoFields().ContainsKey("ba_guoluyalizhuangtai"))
                    {
                        list.Add(GetUiItem(getBaseInfoFields(), "ba_guoluyalizhuangtai"));
                    }
                    else
                    {
                        list.Add(GetUiItem(getMockFields(), "mo_zhengqiyali"));
                    }
                    list.Add(GetUiItem(getMockFields(), "mo_paiyanwendu"));
                    list.Add(GetUiItem(getBaseInfoFields(), "ba_guolushuiweizhuangtai"));
                }
                else if (map[SdcSoftDevice.KEY_POINT_MEDIA].getValue().Equals(Media.ZhenKong))
                {
                }
            }
            else if (map[SdcSoftDevice.KEY_POINT_POWER].getValue().Equals(Power.ShengWuZhi))
            {
                if (map[SdcSoftDevice.KEY_POINT_MEDIA].getValue().Equals(Media.ReShui))
                {
                }
                else if (map[SdcSoftDevice.KEY_POINT_MEDIA].getValue().Equals(Media.DaoReYou))
                {
                }
                else if (map[SdcSoftDevice.KEY_POINT_MEDIA].getValue().Equals(Media.ReFeng))
                {
                }
                else if (map[SdcSoftDevice.KEY_POINT_MEDIA].getValue().Equals(Media.ZhengQi))
                {
                }
                else if (map[SdcSoftDevice.KEY_POINT_MEDIA].getValue().Equals(Media.ZhenKong))
                {
                }
            }
            else if (map[SdcSoftDevice.KEY_POINT_POWER].getValue().Equals(Power.YouQi))
            {
                if (map[SdcSoftDevice.KEY_POINT_MEDIA].getValue().Equals(Media.ReShui))
                {
                    list.Add(GetUiItem(getMockFields(), "mo_paiyanwendu"));
                    list.Add(GetUiItem(getMockFields(), "mo_chukouwendu"));
                    list.Add(GetUiItem(getMockFields(), "mo_rukouwendu"));
                    list.Add(GetUiItem(getBaseInfoFields(), "ba_guolushuiweizhuangtai"));
                    list.Add(GetUiItem(getBaseInfoFields(), "ba_shuixiangshuiweizhuangtai"));
                }
                else if (map[SdcSoftDevice.KEY_POINT_MEDIA].getValue().Equals(Media.DaoReYou))
                {
                    list.Add(GetUiItem(getMockFields(), "mo_paiyanwendu"));
                    list.Add(GetUiItem(getMockFields(), "mo_chukouwendu"));
                    list.Add(GetUiItem(getMockFields(), "mo_rukouwendu"));
                }
                else if (map[SdcSoftDevice.KEY_POINT_MEDIA].getValue().Equals(Media.ReFeng))
                {
                    list.Add(GetUiItem(getMockFields(), "mo_chukouwendu"));
                    list.Add(GetUiItem(getDeviceFields(), "de_ranshaoqi"));
                    list.Add(GetUiItem(getDeviceFields(), "de_yinfengji_fan"));
                }
                else if (map[SdcSoftDevice.KEY_POINT_MEDIA].getValue().Equals(Media.ZhengQi))
                {
                    list.Add(GetUiItem(getBaseInfoFields(), "ba_guolushuiweizhuangtai"));
                    list.Add(GetUiItem(getMockFields(), "mo_paiyanwendu"));

                    if (this.getBaseInfoFields().ContainsKey("ba_guoluyalizhuangtai"))
                    {
                        list.Add(GetUiItem(getBaseInfoFields(), "ba_guoluyalizhuangtai"));
                    }
                    else
                    {
                        list.Add(GetUiItem(getMockFields(), "mo_zhengqiyali"));
                    }
                }
                else if (map[SdcSoftDevice.KEY_POINT_MEDIA].getValue().Equals(Media.ZhenKong))
                {
                    list.Add(GetUiItem(getMockFields(), "mo_paiyanwendu"));
                    list.Add(GetUiItem(getMockFields(), "mo_chukouwendu"));
                    list.Add(GetUiItem(getMockFields(), "mo_meishuiwendu"));
                    list.Add(GetUiItem(getBaseInfoFields(), "ba_guolushuiweizhuangtai"));
                    if (this.getBaseInfoFields().ContainsKey("ba_guoluyalizhuangtai"))
                    {
                        list.Add(GetUiItem(getBaseInfoFields(), "ba_guoluyalizhuangtai"));
                    }
                    else
                    {
                        list.Add(GetUiItem(getMockFields(), "mo_zhengqiyali"));
                    }
                }
            }
            return(list);
        }
Exemple #14
0
        public void AddTest()
        {
            list.Add(7);
            list.Add(9);

            Assert.AreEqual(2, list.Count);
            Assert.AreEqual(9, list[1]);
        }
 public void ContainTest()
 {
     MyList<int> List = new MyArrayList<int>();
     List.Add(31);
     List.Add(9);
     Assert.AreEqual(List.Contains(31), true);
 }
 public void InsertTest()
 {
     MyList<int> List = new MyArrayList<int>();
     List.Add(55);
     List.Add(41);
     List.Insert(79, 1);
     Assert.AreEqual(List[1], 79);
 }
 public void NotContainTest()
 {
     MyList<int> List = new MyArrayList<int>();
     List.Add(31);
     List.Add(9);
     Assert.AreEqual(List.Contains(63), false);
 }
Exemple #18
0
        static void Main(string[] args)
        {
            #region SwapTool
            //SwapTool sTool = new SwapTool();

            //int num1 = 10, num2 = 90;
            //Console.WriteLine($"Before Swap values of Num1: {num1} and Num2: {num2}");

            //sTool.Swap<int>(ref num1, ref num2);
            //Console.WriteLine($"After Swap values of Num1: {num1} and Num2: {num2}");

            //Console.WriteLine("-----------String-----------");
            //string firstName = "Peter", lastName = "Parker";
            //Console.WriteLine($"Before Swap values of FirstName: {firstName} and LastName: {lastName}");

            //sTool.Swap(ref firstName, ref lastName);
            //Console.WriteLine($"After Swap values of FirstName: {firstName} and LastName: {lastName}");
            #endregion

            #region With Int
            //MyArrayList<int> list = new MyArrayList<int>();
            //list.Add(10);
            //list.Add(2);
            //list.Add(1);
            //Console.WriteLine($"List[1]: {list[1]}");
            //list.Add(6);
            #endregion

            #region With string
            //MyArrayList<string> list = new MyArrayList<string>();
            //list.Add("Tintin");
            //list.Add("Phantom");
            //list.Add("Mandrake");
            //Console.WriteLine($"List[1]: {list[1]}");
            //list.Add("Goffy");
            #endregion

            MyArrayList <Person> list = new MyArrayList <Person>();
            list.Add(new Person(10, "Tintin"));
            list.Add(new Person(2, "Snowy"));
            list.Add(new Person(1, "Mini"));
            Console.WriteLine($"List[1]: {list[1]}");
            list.Add(new Person(6, "Jughead"));


            for (int i = 0; i < list.Length; i++)
            {
                Console.WriteLine($"List[{i}]: {list[i]}");
            }
            Console.WriteLine("---------Calling Sort---------");
            list.Sort(Person.CompareByAge);

            foreach (Person p in list)
            {
                Console.WriteLine(p);
            }


            //for (int i = 0; i < list.Length; i++)
            //{
            //  Console.WriteLine($"List[{i}]: {list[i]}");
            //}

            //Console.ReadKey();
            //Console.WriteLine($"List[4]: {list[4]}");
        }