public void EnqueueTestMethod() { MyGenericQueue <Person> genericQueue = new MyGenericQueue <Person>(); genericQueue.Enqueue(new Person(1, "+77051648241")); genericQueue.Enqueue(new Person(2, "+77051648252")); genericQueue.Enqueue(new Person(3, "+77051648255")); genericQueue.Enqueue(new Person(4, "+77051648244")); genericQueue.Enqueue(new Person(0, "+77051648233")); genericQueue.SortBy(d => d.PhoneNumber); Assert.IsTrue(genericQueue[0].Id == 0, genericQueue[0].PhoneNumber); }
public void InputTestData() { int input = 3; MyGenericQueue <Person> genericQueue = new MyGenericQueue <Person>(); genericQueue.Enqueue(new Person(0, "+77051648233")); genericQueue.Enqueue(new Person(1, "+77051648241")); genericQueue.Enqueue(new Person(2, "+77051648252")); genericQueue.Enqueue(new Person(3, "+77051648255")); genericQueue.Enqueue(new Person(4, "+77051648244")); Person[] persons = genericQueue.GetNElements(input); Assert.AreEqual(input, persons.Length, $"persons.Length = {persons.Length}"); }
/// <summary> /// Demostrates work of generic queue /// </summary> private static void MyGenericQueueDemonstrate() { List <Car> cars = new List <Car> { new Car("Toyota", "Land Cruiser"), new Car("Audi", "A7"), new Car("Ford", "Mustang", 5.5), new Car("Lada", "Kalina"), }; try { var myGenericQueue = new MyGenericQueue <Car>(cars); foreach (var item in myGenericQueue) { if (item != null) { Console.WriteLine($"{item.Manufacturer} {item.Model}"); } } Console.WriteLine(); do { var car = myGenericQueue.Dequeue(); Console.WriteLine($"{car.Manufacturer} {car.Model}"); }while (!myGenericQueue.IsEmpty); Console.WriteLine($"Is queue empty? {myGenericQueue.IsEmpty}"); } catch (ArgumentOutOfRangeException e) { Console.WriteLine($"{e.Message}"); } catch (InvalidOperationException e) { Console.WriteLine($"{e.Message}"); } catch (Exception e) { Console.WriteLine($"Error! {e.Message}"); } }
static void Main(string[] args) { tryStart: try { begin: Console.Clear(); Console.WriteLine("Введите n (количество номеров которые вы хотите увидеть первыми)"); bool b = int.TryParse(Console.ReadLine(), out int n); if (!b) { ShowError(); goto begin; } else { whatToUse: Console.WriteLine("1 - Использовать Generic Queue"); Console.WriteLine("2 - Использовать обычный Queue (завязанный только на Person)"); b = int.TryParse(Console.ReadLine(), out int choise); if (!b) { ShowError(); goto whatToUse; } Console.WriteLine("Начинайте вводить номера! Чтобы закончить ввод нажмите escape"); if (choise == 1) { MyGenericQueue <Person> genericQueue = new MyGenericQueue <Person>(); int counter = 1; do { Console.Write("+"); string phoneNumber = Console.ReadLine(); genericQueue.Enqueue(new Person(counter++, "+" + phoneNumber)); Console.WriteLine("Write enter to continue or ESC to exit"); }while (Console.ReadKey().Key != ConsoleKey.Escape); Person[] firstNPersons = genericQueue.GetNElements(n); foreach (Person nPerson in firstNPersons) { Console.WriteLine("Unique Id = {0} , Id = {1} , PhoneNumber = {2}", nPerson.UniqueId, nPerson.Id, nPerson.PhoneNumber); } } else if (choise == 2) { MyQueue myQueue = new MyQueue(); int counter = 1; do { Console.Write("+"); string phoneNumber = Console.ReadLine(); myQueue.Enqueue(new Person(counter++, "+" + phoneNumber)); Console.WriteLine("Write enter to continue or ESC to exit"); }while (Console.ReadKey().Key != ConsoleKey.Escape); Person[] firstNPersons = myQueue.GetNElements(n); foreach (Person nPerson in firstNPersons) { Console.WriteLine("[{0}]PhoneNumber = {1},Unique Id = {2}.", nPerson.Id, nPerson.PhoneNumber, nPerson.UniqueId); } } else { ShowError(); goto begin; } Console.WriteLine("Всё прошло успешно"); Console.ReadLine(); } } catch (Exception ex) { Console.WriteLine(ex); Thread.Sleep(3500); goto tryStart; } }