Exemplo n.º 1
0
        static void Main(string[] args)
        {
            char start = 'к', finish = 'ю';

            do
            {
                MyStrings testString  = new RusString(start, finish, 10);
                MyStrings testString1 = new LatString('a', 'q', 7);
                Console.WriteLine(testString);
                Console.WriteLine(testString.CountLetter('о'));
                Console.WriteLine(testString1);
                Console.WriteLine(testString1.CountLetter('b'));
                // тестируем неверные входные данные
                try
                {
                    testString = new RusString(start, finish, -11);
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    Console.WriteLine("Состояние объекта не изменено");// если объект не сформирован
                }
                try
                {
                    testString1 = new LatString('6', 'x', 6);
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    Console.WriteLine("Состояние объекта не изменено");// если объект не сформирован
                }
                Console.WriteLine(testString);
                Console.WriteLine(testString.CountLetter('о'));
                Console.WriteLine(testString1);
                Console.WriteLine(testString1.CountLetter('j'));
            } while (Console.ReadKey().Key != ConsoleKey.Escape);
        }
        static void Main(string[] args)
        {
            char start = 'к', finish = 'ю';

            do
            {
                RusString testRusString = new RusString(start, finish, 10);
                LatString testLatString = new LatString(start, finish, 10);
                Console.WriteLine(testRusString);
                Console.WriteLine(testRusString.CountLetter('о'));
                // тестируем неверные входные данные
                try
                {
                    testRusString = new RusString(start, finish, -11);
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    Console.WriteLine("Состояние объекта не изменено");// если объект не сформирован
                    Console.WriteLine(ex.Message);
                }
                Console.WriteLine(testLatString);
                Console.WriteLine(testLatString.CountLetter('o'));
                // тестируем неверные входные данные
                try
                {
                    testLatString = new LatString(start, finish, -11);
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    Console.WriteLine("Состояние объекта не изменено");// если объект не сформирован
                    Console.WriteLine(ex.Message);
                }
            } while (Console.ReadKey().Key != ConsoleKey.Escape);
        }
        static void Main(string[] args)
        {
            char start  = 'к',
                 finish = 'ю';

            do
            {
                MyStrings testString = new RusString(start, finish, 10);
                Console.WriteLine(testString);
                Console.WriteLine(testString.CountLetter('o'));

                // Тестируем.
                try
                {
                    testString = new RusString(start, finish, -11);
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    Console.WriteLine("Ошибка:" + ex.Message);
                    Console.WriteLine("Состояние объекта не изменено");
                }

                Console.WriteLine(testString);
                Console.WriteLine(testString.CountLetter('o'));
            }while (Console.ReadKey().Key != ConsoleKey.Escape);

            // Теперь тестируем класс для латинских строк.
            start  = 'f';
            finish = 'l';
            Console.WriteLine("\n");
            do
            {
                MyStrings testString = new LatString(start, finish, 10);
                Console.WriteLine(testString);
                Console.WriteLine(testString.CountLetter('h'));

                // Тестируем.
                try
                {
                    testString = new RusString(start, finish, -11);
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    Console.WriteLine("Ошибка:" + ex.Message);
                    Console.WriteLine("Состояние объекта не изменено");
                }

                Console.WriteLine(testString);
                Console.WriteLine(testString.CountLetter('h'));
            }while (Console.ReadKey().Key != ConsoleKey.Escape);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            char start = 'к', finish = 'ю';

            do
            {
                MyStrings testString = new RusString(start, finish, 10);

                Console.WriteLine(testString);
                Console.WriteLine(testString.CountLetter('о'));
                Console.WriteLine(testString.IsPalidrome());

                try
                {
                    testString = new RusString(start, finish, -11);
                }
                catch (ArgumentOutOfRangeException)
                {
                    Console.WriteLine("Nothing was changed.");
                }

                Console.WriteLine(testString);
                Console.WriteLine(testString.CountLetter('о'));
                Console.WriteLine(testString.IsPalidrome());

                testString = new LatString(start, finish, 10);

                Console.WriteLine(testString);
                Console.WriteLine(testString.CountLetter('о'));
                Console.WriteLine(testString.IsPalidrome());

                try
                {
                    testString = new RusString(start, finish, -11);
                }
                catch (ArgumentOutOfRangeException)
                {
                    Console.WriteLine("Nothing was changed.");
                }

                Console.WriteLine(testString);
                Console.WriteLine(testString.CountLetter('о'));
                Console.WriteLine(testString.IsPalidrome());
            } while (Console.ReadKey().Key != ConsoleKey.Escape);
        }
        static void Main(string[] args)
        {
            do
            {
                char start1, finish1, start2, finish2;
                do
                {
                    Console.Clear();
                    try
                    {
                        Console.WriteLine("Введите русские символы(начало и конец)");
                        start1  = Console.ReadKey().KeyChar;
                        finish1 = Console.ReadKey().KeyChar;
                        Console.WriteLine();
                        Console.WriteLine("Введите латинские символы(начало и конец)");
                        start2  = Console.ReadKey().KeyChar;
                        finish2 = Console.ReadKey().KeyChar;
                        break;
                    }
                    catch (ArgumentOutOfRangeException ex)
                    {
                        Console.WriteLine("Введены неверные значения");
                    }
                } while (true);
                try
                {
                    MyStrings testString1 = new RusString(start1, finish1, 10);
                    MyStrings testString2 = new LatString(start2, finish2, 23);

                    Console.WriteLine("Для ру слов");

                    // тестируем неверные входные данные
                    try
                    {
                        Console.WriteLine(testString1);
                        Console.WriteLine(testString1.CountLetter('о'));
                        testString1 = new RusString(start1, start1, -11);
                    }
                    catch (ArgumentOutOfRangeException ex)
                    {
                        Console.WriteLine("Состояние объекта не изменено");// если объект не сформирован
                    }
                    catch (OverflowException ex)
                    {
                        Console.WriteLine("За массив выходим :(");
                    }

                    Console.WriteLine("Для лат слов");
                    // тестируем неверные входные данные
                    try
                    {
                        Console.WriteLine(testString2);
                        Console.WriteLine(testString2.CountLetter('о'));
                        testString2 = new RusString(start2, start2, -11);
                    }
                    catch (ArgumentOutOfRangeException ex)
                    {
                        Console.WriteLine("Состояние объекта не изменено");// если объект не сформирован
                    }
                    catch (OverflowException ex)
                    {
                        Console.WriteLine("За массив выходим :(");
                    }
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    Console.WriteLine("Введеные неверные значения");
                }
            } while (Console.ReadKey().Key != ConsoleKey.Escape);
        }