Esempio n. 1
0
 public void ShouldCheckIfAddingWorksFor2Elements()
 {
     Vector<int> list = new Vector<int>();
     list.Add(0);
     list.Add(2);
     Assert.AreEqual(2, list.Count);
 }
 public void ShouldReturnFalseForListContainingNumberTwo()
 {
     Vector<int> list = new Vector<int>();
     list.Add(3);
     list.Add(1);
     bool contains = list.Contains(2);
     Assert.IsFalse(contains);
 }
 public void ShouldInsertNumberFourAtIndexOne()
 {
     Vector<int> list = new Vector<int>();
     list.Add(2);
     list.Add(3);
     list.Add(1);
     list.Insert(1, 4);
     Assert.AreEqual(1, list.IndexOf(4));
 }
 public void ShouldClearListOfAllElements()
 {
     Vector<int> list = new Vector<int>();
     list.Add(2);
     list.Add(3);
     list.Add(1);
     list.Clear();
     int result = list.Count;
     Assert.AreEqual(0, result);
 }
 public void ShouldCopyValueToList()
 {
     Vector<int> list = new Vector<int>();
     list.Add(2);
     list.Add(3);
     list.Add(1);
     int[] value = new int[2];
     list.CopyTo(value, 0);
     Assert.AreEqual(2, value[0]);
 }
 public void ShouldRemoveItemAtIndexTwo()
 {
     Vector<int> list = new Vector<int>();
     list.Add(2);
     list.Add(3);
     list.Add(1);
     list.RemoveAt(2);
     Assert.AreEqual(2, list.Count);
     Assert.AreEqual(1, list.IndexOf(3));
 }
 public void ShouldRemoveNumberThreeFromList()
 {
     Vector<int> list = new Vector<int>();
     list.Add(2);
     list.Add(3);
     list.Add(1);
     list.Remove(3);
     Assert.AreEqual(2, list.Count);
     Assert.AreEqual(1, list.IndexOf(1));
 }
Esempio n. 8
0
 public void ShouldRemoveTheFirstInstanceOf5()
 {
     Vector<int> list = new Vector<int>();
     list.Add(3);
     list.Add(2);
     list.Add(4);
     list.Add(5);
     list.Add(6);
     Assert.IsTrue(list.Remove(5));
     Assert.AreEqual(3, list.IndexOf(6));
 }
Esempio n. 9
0
 public void ShouldRemoveTheElementAtIndex1()
 {
     Vector<int> list = new Vector<int>();
     list.Add(3);
     list.Add(2);
     list.Add(4);
     list.Add(5);
     list.Add(7);
     list.RemoveAt(1);
     Assert.AreEqual(4, list[1]);
 }
Esempio n. 10
0
 public void ShouldInsertANumberAtIndex3()
 {
     Vector<int> list = new Vector<int>();
     list.Add(3);
     list.Add(2);
     list.Add(4);
     list.Add(5);
     list.Add(7);
     list.Insert(2, 9);
     Assert.AreEqual(2, list.IndexOf(9));
 }
Esempio n. 11
0
 public void ShouldReturnLengthOfListAsOneForDecimal()
 {
     Vector<decimal> list = new Vector<decimal>();
     list.Add(2.5m);
     int result = list.Count;
     Assert.AreEqual(1, result);
 }
Esempio n. 12
0
 public void ShouldReturnTrueIfOneElementIsContainedForInteger()
 {
     Vector<int> list = new Vector<int>();
     list.Add(0);
     list.Add(2);
     Assert.IsTrue(list.Contains(2));
 }
Esempio n. 13
0
            static void Main(string[] args)
            {
                Vector <int> vector = null;
                string       result = "";

                // test 1
                try
                {
                    Console.WriteLine("\nTest A: Run a sequence of operations: ");
                    Console.WriteLine("Create a new vector by calling 'Vector<int> vector = new Vector<int>(50);'");
                    vector = new Vector <int>(50);
                    Console.WriteLine("Add a sequence of numbers 2, 6, 8, 5, 5, 1, 8, 5, 3, 5, 7, 1, 4, 9");
                    vector.Add(2); vector.Add(6); vector.Add(8); vector.Add(5); vector.Add(5); vector.Add(1); vector.Add(8); vector.Add(5);
                    vector.Add(3); vector.Add(5); vector.Add(7); vector.Add(1); vector.Add(4); vector.Add(9);
                    if (!CheckIntSequence(new int[] { 2, 6, 8, 5, 5, 1, 8, 5, 3, 5, 7, 1, 4, 9 }, vector))
                    {
                        throw new Exception("Vector stores an incorrect sequence of integers after adding new elements");
                    }
                    Console.WriteLine("Sort the integers in the default order defined by the native CompareTo() method");
                    vector.Sort();
                    int[] array = new int[] { 2, 6, 8, 5, 5, 1, 8, 5, 3, 5, 7, 1, 4, 9 };
                    Array.Sort(array, 0, 14);
                    Console.WriteLine("Resulting order: " + vector.ToString());
                    if (!CheckIntSequence(array, vector))
                    {
                        throw new Exception("Vector stores an incorrect sequence of integers after sorting them");
                    }
                    Console.WriteLine(" :: SUCCESS");
                    result = result + "A";
                }
                catch (Exception exception)
                {
                    Console.WriteLine(" :: FAIL");
                    Console.WriteLine(exception.ToString());
                    result = result + "-";
                }

                // test 2
                try
                {
                    Console.WriteLine("\nTest B: Run a sequence of operations: ");
                    Console.WriteLine("Create a new vector by calling 'Vector<int> vector = new Vector<int>(50);'");
                    vector = new Vector <int>(50);
                    Console.WriteLine("Add a sequence of numbers 2, 6, 8, 5, 5, 1, 8, 5, 3, 5, 7, 1, 4, 9");
                    vector.Add(2); vector.Add(6); vector.Add(8); vector.Add(5); vector.Add(5); vector.Add(1); vector.Add(8);
                    vector.Add(5); vector.Add(3); vector.Add(5); vector.Add(7); vector.Add(1); vector.Add(4); vector.Add(9);
                    if (!CheckIntSequence(new int[] { 2, 6, 8, 5, 5, 1, 8, 5, 3, 5, 7, 1, 4, 9 }, vector))
                    {
                        throw new Exception("Vector stores an incorrect sequence of integers after adding new elements");
                    }
                    Console.WriteLine("Sort the integers in the order defined by the AscendingIntComparer class");
                    vector.Sort(new AscendingIntComparer());
                    int[] array = new int[] { 2, 6, 8, 5, 5, 1, 8, 5, 3, 5, 7, 1, 4, 9 };
                    Array.Sort(array, 0, 14, new AscendingIntComparer());
                    Console.WriteLine("Resulting order: " + vector.ToString());
                    if (!CheckIntSequence(array, vector))
                    {
                        throw new Exception("Vector stores an incorrect sequence of integers after sorting them");
                    }
                    Console.WriteLine(" :: SUCCESS");
                    result = result + "B";
                }
                catch (Exception exception)
                {
                    Console.WriteLine(" :: FAIL");
                    Console.WriteLine(exception.ToString());
                    result = result + "-";
                }

                // test 3
                try
                {
                    Console.WriteLine("\nTest C: Run a sequence of operations: ");
                    Console.WriteLine("Create a new vector by calling 'Vector<int> vector = new Vector<int>(50);'");
                    vector = new Vector <int>(50);
                    Console.WriteLine("Add a sequence of numbers 2, 6, 8, 5, 5, 1, 8, 5, 3, 5, 7, 1, 4, 9");
                    vector.Add(2); vector.Add(6); vector.Add(8); vector.Add(5); vector.Add(5); vector.Add(1); vector.Add(8);
                    vector.Add(5); vector.Add(3); vector.Add(5); vector.Add(7); vector.Add(1); vector.Add(4); vector.Add(9);
                    if (!CheckIntSequence(new int[] { 2, 6, 8, 5, 5, 1, 8, 5, 3, 5, 7, 1, 4, 9 }, vector))
                    {
                        throw new Exception("Vector stores an incorrect sequence of integers after adding new elements");
                    }
                    Console.WriteLine("Sort the integers in the order defined by the DescendingIntComparer class");
                    vector.Sort(new DescendingIntComparer());
                    int[] array = new int[] { 2, 6, 8, 5, 5, 1, 8, 5, 3, 5, 7, 1, 4, 9 };
                    Array.Sort(array, 0, 14, new DescendingIntComparer());
                    Console.WriteLine("Resulting order: " + vector.ToString());
                    if (!CheckIntSequence(array, vector))
                    {
                        throw new Exception("Vector stores an incorrect sequence of integers after sorting them");
                    }
                    Console.WriteLine(" :: SUCCESS");
                    result = result + "C";
                }
                catch (Exception exception)
                {
                    Console.WriteLine(" :: FAIL");
                    Console.WriteLine(exception.ToString());
                    result = result + "-";
                }

                // test 4
                try
                {
                    Console.WriteLine("\nTest D: Run a sequence of operations: ");
                    Console.WriteLine("Create a new vector by calling 'Vector<int> vector = new Vector<int>(50);'");
                    vector = new Vector <int>(50);
                    Console.WriteLine("Add a sequence of numbers 2, 6, 8, 5, 5, 1, 8, 5, 3, 5, 7, 1, 4, 9");
                    vector.Add(2); vector.Add(6); vector.Add(8); vector.Add(5); vector.Add(5); vector.Add(1); vector.Add(8);
                    vector.Add(5); vector.Add(3); vector.Add(5); vector.Add(7); vector.Add(1); vector.Add(4); vector.Add(9);
                    if (!CheckIntSequence(new int[] { 2, 6, 8, 5, 5, 1, 8, 5, 3, 5, 7, 1, 4, 9 }, vector))
                    {
                        throw new Exception("Vector stores an incorrect sequence of integers after adding new elements");
                    }
                    Console.WriteLine("Sort the integers in the order defined by the EvenNumberFirstComparer class");
                    vector.Sort(new EvenNumberFirstComparer());
                    int[] array = new int[] { 2, 6, 8, 5, 5, 1, 8, 5, 3, 5, 7, 1, 4, 9 };
                    Array.Sort(array, 0, 14, new EvenNumberFirstComparer());
                    Console.WriteLine("Resulting order: " + vector.ToString());
                    if (!CheckIntSequence(array, vector))
                    {
                        throw new Exception("Vector stores an incorrect sequence of integers after sorting them");
                    }
                    Console.WriteLine(" :: SUCCESS");
                    result = result + "D";
                }
                catch (Exception exception)
                {
                    Console.WriteLine(" :: FAIL");
                    Console.WriteLine(exception.ToString());
                    result = result + "-";
                }

                // test 5
                try
                {
                    string[] names  = new string[] { "Kelly", "Cindy", "John", "Andrew", "Richard", "Michael", "Guy", "Elicia", "Tom", "Iman", "Simon", "Vicky" };
                    Random   random = new Random(100);
                    Console.WriteLine("\nTest E: Run a sequence of operations: ");
                    Console.WriteLine("Create a new vector of Student objects by calling 'Vector<Student> students = new Vector<Student>();'");
                    Vector <Student> students = new Vector <Student>();
                    for (int i = 0; i < 14; i++)
                    {
                        Student student = new Student()
                        {
                            Name = names[random.Next(0, names.Length)], Id = i
                        };
                        Console.WriteLine("Add student with record: " + student.ToString());
                        students.Add(student);
                    }
                    Console.WriteLine("Sort the students in the default order defined by the native CompareTo() method");
                    students.Sort();
                    Console.WriteLine("Print the vector of students via students.ToString();");
                    Console.WriteLine(students.ToString());

                    Console.WriteLine(" :: SUCCESS");
                    result = result + "E";
                }
                catch (Exception exception)
                {
                    Console.WriteLine(" :: FAIL");
                    Console.WriteLine(exception.ToString());
                    result = result + "-";
                }

                // test 6
                try
                {
                    string[] names  = new string[] { "Kelly", "Cindy", "John", "Andrew", "Richard", "Michael", "Guy", "Elicia", "Tom", "Iman", "Simon", "Vicky" };
                    Random   random = new Random(100);
                    Console.WriteLine("\nTest F: Run a sequence of operations: ");
                    Console.WriteLine("Create a new vector of Student objects by calling 'Vector<Student> students = new Vector<Student>();'");
                    Vector <Student> students = new Vector <Student>();
                    for (int i = 0; i < 14; i++)
                    {
                        Student student = new Student()
                        {
                            Name = names[random.Next(0, names.Length)], Id = i
                        };
                        Console.WriteLine("Add student with record: " + student.ToString());
                        students.Add(student);
                    }
                    Console.WriteLine("Sort the students in the order defined by the AscendingIDComparer class");
                    students.Sort(new AscendingIDComparer());
                    Console.WriteLine("Print the vector of students via students.ToString();");
                    Console.WriteLine(students.ToString());

                    Console.WriteLine(" :: SUCCESS");
                    result = result + "F";
                }
                catch (Exception exception)
                {
                    Console.WriteLine(" :: FAIL");
                    Console.WriteLine(exception.ToString());
                    result = result + "-";
                }

                // test 7
                try
                {
                    string[] names  = new string[] { "Kelly", "Cindy", "John", "Andrew", "Richard", "Michael", "Guy", "Elicia", "Tom", "Iman", "Simon", "Vicky" };
                    Random   random = new Random(100);
                    Console.WriteLine("\nTest G: Run a sequence of operations: ");
                    Console.WriteLine("Create a new vector of Student objects by calling 'Vector<Student> students = new Vector<Student>();'");
                    Vector <Student> students = new Vector <Student>();
                    for (int i = 0; i < 14; i++)
                    {
                        Student student = new Student()
                        {
                            Name = names[random.Next(0, names.Length)], Id = i
                        };
                        Console.WriteLine("Add student with record: " + student.ToString());
                        students.Add(student);
                    }
                    Console.WriteLine("Sort the students in the order defined by the DescendingNameDescendingIdComparer class");
                    students.Sort(new DescendingNameDescendingIdComparer());
                    Console.WriteLine("Print the vector of students via students.ToString();");
                    Console.WriteLine(students.ToString());

                    Console.WriteLine(" :: SUCCESS");
                    result = result + "G";
                }
                catch (Exception exception)
                {
                    Console.WriteLine(" :: FAIL");
                    Console.WriteLine(exception.ToString());
                    result = result + "-";
                }

                Console.WriteLine("\n\n ------------------- SUMMARY ------------------- ");
                Console.WriteLine("Tests passed: " + result);
                Console.ReadKey();
            }
Esempio n. 14
0
 public void ShouldCheckIfStringAdded()
 {
     Vector<string> list = new Vector<string>();
     list.Add("hello");
     Assert.AreEqual(1, list.Count);
 }
Esempio n. 15
0
 public void ShouldTestIfCopyWorksForInteger()
 {
     Vector<int> list = new Vector<int>();
     list.Add(3);
     list.Add(2);
     list.Add(4);
     list.Add(5);
     list.Add(7);
     int[] value = new int[list.Count];
     list.CopyTo(value, 0);
     Assert.AreEqual(3, value[0]);
 }
Esempio n. 16
0
 public void ShouldReturnTheIndexOfNumberThree()
 {
     Vector<int> list = new Vector<int>();
     list.Add(2);
     list.Add(3);
     list.Add(1);
     int index = list.IndexOf(3);
     Assert.AreEqual(1, index);
 }
Esempio n. 17
0
 public void ShouldReturnTheIndexOfAGivenValue()
 {
     Vector<int> list = new Vector<int>();
     list.Add(3);
     list.Add(2);
     list.Add(4);
     list.Add(5);
     list.Add(7);
     Assert.AreEqual(4, list.IndexOf(7));
 }
Esempio n. 18
0
        static void Main(string[] args)
        {
            string result       = "";
            int    problem_size = 20;

            int[]  data = new int[problem_size]; data[0] = 333;
            Random k    = new Random(1000);

            for (int i = 1; i < problem_size; i++)
            {
                data[i] = 100 + k.Next(900);
            }

            Vector <int> vector = new Vector <int>(problem_size);


            // ------------------ RandomizedQuickSort ----------------------------------

            try
            {
                Console.WriteLine("\nTest A: Sort integer numbers applying RandomizedQuickSort with AscendingIntComparer: ");
                vector        = new Vector <int>(problem_size);
                vector.Sorter = new RandomizedQuickSort();
                for (int i = 0; i < problem_size; i++)
                {
                    vector.Add(data[i]);
                }
                Console.WriteLine("Intital data: " + vector.ToString());
                vector.Sort(new AscendingIntComparer());
                Console.WriteLine("Resulting order: " + vector.ToString());
                if (!CheckAscending(vector))
                {
                    throw new Exception("Sorted vector has an incorrect sequence of integers");
                }
                Console.WriteLine(" :: SUCCESS");
                result = result + "A";
            }
            catch (Exception exception)
            {
                Console.WriteLine(" :: FAIL");
                Console.WriteLine(exception.ToString());
                result = result + "-";
            }

            try
            {
                Console.WriteLine("\nTest B: Sort integer numbers applying RandomizedQuickSort with DescendingIntComparer: ");
                vector        = new Vector <int>(problem_size);
                vector.Sorter = new RandomizedQuickSort();
                for (int i = 0; i < problem_size; i++)
                {
                    vector.Add(data[i]);
                }
                Console.WriteLine("Intital data: " + vector.ToString());
                vector.Sort(new DescendingIntComparer());
                Console.WriteLine("Resulting order: " + vector.ToString());
                if (!CheckDescending(vector))
                {
                    throw new Exception("Sorted vector has an incorrect sequence of integers");
                }
                Console.WriteLine(" :: SUCCESS");
                result = result + "B";
            }
            catch (Exception exception)
            {
                Console.WriteLine(" :: FAIL");
                Console.WriteLine(exception.ToString());
                result = result + "-";
            }

            try
            {
                Console.WriteLine("\nTest C: Sort integer numbers applying RandomizedQuickSort with EvenNumberFirstComparer: ");
                vector        = new Vector <int>(problem_size);
                vector.Sorter = new RandomizedQuickSort();
                for (int i = 0; i < problem_size; i++)
                {
                    vector.Add(data[i]);
                }
                Console.WriteLine("Intital data: " + vector.ToString());
                vector.Sort(new EvenNumberFirstComparer());
                Console.WriteLine("Resulting order: " + vector.ToString());
                if (!CheckEvenNumberFirst(vector))
                {
                    throw new Exception("Sorted vector has an incorrect sequence of integers");
                }
                Console.WriteLine(" :: SUCCESS");
                result = result + "C";
            }
            catch (Exception exception)
            {
                Console.WriteLine(" :: FAIL");
                Console.WriteLine(exception.ToString());
                result = result + "-";
            }



            //------------------MergeSortTopDown----------------------------------

            try
            {
                Console.WriteLine("\nTest D: Sort integer numbers applying MergeSortTopDown with AscendingIntComparer: ");
                vector        = new Vector <int>(problem_size);
                vector.Sorter = new MergeSortTopDown();
                for (int i = 0; i < problem_size; i++)
                {
                    vector.Add(data[i]);
                }
                Console.WriteLine("Intital data: " + vector.ToString());
                vector.Sort(new AscendingIntComparer());
                Console.WriteLine("Resulting order: " + vector.ToString());
                if (!CheckAscending(vector))
                {
                    throw new Exception("Sorted vector has an incorrect sequence of integers");
                }
                Console.WriteLine(" :: SUCCESS");
                result = result + "D";
            }
            catch (Exception exception)
            {
                Console.WriteLine(" :: FAIL");
                Console.WriteLine(exception.ToString());
                result = result + "-";
            }

            try
            {
                Console.WriteLine("\nTest E: Sort integer numbers applying MergeSortTopDown with DescendingIntComparer: ");
                vector        = new Vector <int>(problem_size);
                vector.Sorter = new MergeSortTopDown();
                for (int i = 0; i < problem_size; i++)
                {
                    vector.Add(data[i]);
                }
                Console.WriteLine("Intital data: " + vector.ToString());
                vector.Sort(new DescendingIntComparer());
                Console.WriteLine("Resulting order: " + vector.ToString());
                if (!CheckDescending(vector))
                {
                    throw new Exception("Sorted vector has an incorrect sequence of integers");
                }
                Console.WriteLine(" :: SUCCESS");
                result = result + "E";
            }
            catch (Exception exception)
            {
                Console.WriteLine(" :: FAIL");
                Console.WriteLine(exception.ToString());
                result = result + "-";
            }

            try
            {
                Console.WriteLine("\nTest F: Sort integer numbers applying MergeSortTopDown with EvenNumberFirstComparer: ");
                vector        = new Vector <int>(problem_size);
                vector.Sorter = new MergeSortTopDown();
                for (int i = 0; i < problem_size; i++)
                {
                    vector.Add(data[i]);
                }
                Console.WriteLine("Intital data: " + vector.ToString());
                vector.Sort(new EvenNumberFirstComparer());
                Console.WriteLine("Resulting order: " + vector.ToString());
                if (!CheckEvenNumberFirst(vector))
                {
                    throw new Exception("Sorted vector has an incorrect sequence of integers");
                }
                Console.WriteLine(" :: SUCCESS");
                result = result + "F";
            }
            catch (Exception exception)
            {
                Console.WriteLine(" :: FAIL");
                Console.WriteLine(exception.ToString());
                result = result + "-";
            }



            //------------------MergeSortBottomUp----------------------------------

            try
            {
                Console.WriteLine("\nTest G: Sort integer numbers applying MergeSortBottomUp with AscendingIntComparer: ");
                vector        = new Vector <int>(problem_size);
                vector.Sorter = new MergeSortBottomUp();
                for (int i = 0; i < problem_size; i++)
                {
                    vector.Add(data[i]);
                }
                Console.WriteLine("Intital data: " + vector.ToString());
                vector.Sort(new AscendingIntComparer());
                Console.WriteLine("Resulting order: " + vector.ToString());
                if (!CheckAscending(vector))
                {
                    throw new Exception("Sorted vector has an incorrect sequence of integers");
                }
                Console.WriteLine(" :: SUCCESS");
                result = result + "G";
            }
            catch (Exception exception)
            {
                Console.WriteLine(" :: FAIL");
                Console.WriteLine(exception.ToString());
                result = result + "-";
            }

            try
            {
                Console.WriteLine("\nTest H: Sort integer numbers applying MergeSortBottomUp with DescendingIntComparer: ");
                vector        = new Vector <int>(problem_size);
                vector.Sorter = new MergeSortBottomUp();
                for (int i = 0; i < problem_size; i++)
                {
                    vector.Add(data[i]);
                }
                Console.WriteLine("Intital data: " + vector.ToString());
                vector.Sort(new DescendingIntComparer());
                Console.WriteLine("Resulting order: " + vector.ToString());
                if (!CheckDescending(vector))
                {
                    throw new Exception("Sorted vector has an incorrect sequence of integers");
                }
                Console.WriteLine(" :: SUCCESS");
                result = result + "H";
            }
            catch (Exception exception)
            {
                Console.WriteLine(" :: FAIL");
                Console.WriteLine(exception.ToString());
                result = result + "-";
            }

            try
            {
                Console.WriteLine("\nTest I: Sort integer numbers applying MergeSortBottomUp with EvenNumberFirstComparer: ");
                vector        = new Vector <int>(problem_size);
                vector.Sorter = new MergeSortBottomUp();
                for (int i = 0; i < problem_size; i++)
                {
                    vector.Add(data[i]);
                }
                Console.WriteLine("Intital data: " + vector.ToString());
                vector.Sort(new EvenNumberFirstComparer());
                Console.WriteLine("Resulting order: " + vector.ToString());
                if (!CheckEvenNumberFirst(vector))
                {
                    throw new Exception("Sorted vector has an incorrect sequence of integers");
                }
                Console.WriteLine(" :: SUCCESS");
                result = result + "I";
            }
            catch (Exception exception)
            {
                Console.WriteLine(" :: FAIL");
                Console.WriteLine(exception.ToString());
                result = result + "-";
            }

            Console.WriteLine("\n\n ------------------- SUMMARY ------------------- ");
            Console.WriteLine("Tests passed: " + result);
            Console.ReadKey();
        }
Esempio n. 19
0
        public Vector<vQualification> listQualifications(uint gvoid)
        {
            // Declarations
            Vector<vQualification> quals = new Vector<vQualification>();
            uint gvqid = 0;
            string qualification = null;
            vQualification input = new vQualification();

            // Command
            string query = string.Format("SELECT gvq_id, gvq_qual " +
                                            "FROM gfrc_volunteer_qualification WHERE gvo_id = {0}", gvoid);

            try
            {
                using (conn)
                {
                    conn.Open();
                    cmd = new OleDbCommand(query, conn);
                    rdr = cmd.ExecuteReader();

                    while (rdr.Read())
                    {
                        if (!UInt32.TryParse(rdr.GetValue(0).ToString(), out gvqid))
                            gvqid = 0;
                        qualification = rdr.GetString(1);
                        if (gvqid != 0)
                        {
                            input = new vQualification(gvqid, gvoid, qualification);
                            quals.Add(input);
                        }

                    }
                }
            }
            finally
            {
                if (rdr != null)
                    rdr.Close();
            }
            if (conn != null)
            {
                conn.Close();
            }

            return quals;
        }
Esempio n. 20
0
 public void ShouldReturnLengthOfListAsOneForInt()
 {
     Vector<int> list = new Vector<int>();
     list.Add(2);
     int result = list.Count;
     Assert.AreEqual(1, result);
 }
Esempio n. 21
0
        static void Main()
        {
            var vector1 = new Vector(3);

            Console.WriteLine($"Вектор 1: {vector1}");

            var vector2 = new Vector(new double[] { 2.3, 4.5, 7 });

            Console.WriteLine($"Вектор 2: {vector2}");

            var vector3 = new Vector(vector2);

            Console.WriteLine($"Вектор 3: {vector3}");

            Vector vector4 = new Vector(8, new double[] { 1, 5, 0, 8 });

            Console.WriteLine($"Вектор 4: {vector4}");

            Console.WriteLine();
            try
            {
                var invalidVector = new Vector(-7);
                Console.WriteLine(invalidVector);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Попытка передать в конструктор некорректные аргументы: {ex.Message}");
            }

            Console.WriteLine();
            Console.Write($"{vector1} + {vector2} = ");
            vector1.Add(vector2);
            Console.WriteLine(vector1);

            Console.WriteLine();
            Console.Write($"{vector1} - {vector4} = ");
            vector1.Subtract(vector4);
            Console.WriteLine(vector1);

            Console.WriteLine();
            Console.Write($"{vector1} * 6.5 = ");
            vector1.Multiply(6.5);
            Console.WriteLine(vector1);

            Console.WriteLine();
            Console.Write($"Инверсия вектора {vector1} : ");
            vector1.Invert();
            Console.WriteLine(vector1);

            Console.WriteLine();
            Console.WriteLine($"Длина вектора {vector1} равна {vector1.GetLength()}");

            Console.WriteLine();
            Console.Write($"Второй компоненте вектора {vector1} присваивается 5.9 ");
            vector1[1] = 5.9;
            Console.WriteLine(vector1);
            Console.WriteLine($"Теперь вторая компонента вектора равна {vector1[1]}");

            Console.WriteLine();
            try
            {
                Console.WriteLine(vector1[-5]);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Попытка обратиться к несуществующей компоненте вектора: {ex.Message}");
            }

            Console.WriteLine();
            Console.WriteLine($"Вектор {vector2} {(vector2.Equals(vector1) ? "равен" : "не равен")} вектору {vector1}");
            Console.WriteLine($"Вектор {vector2} {(vector2.Equals(vector3) ? "равен" : "не равен")} вектору {vector3}");

            Console.WriteLine();
            Console.WriteLine($"{vector1} + {vector2} = {Vector.Add(vector1, vector2)}");
            Console.WriteLine($"{vector1} - {vector3} = {Vector.Subtract(vector1, vector3)}");
            Console.WriteLine($"({vector1}, {vector2} ) = {Vector.ScalarProduct(vector1, vector2)}");

            Console.ReadLine();
        }
Esempio n. 22
0
        static void Main(string[] args)
        {
            string result = "";

            Vector <int> vector = null;

            // test 1
            try
            {
                Console.WriteLine("\nTest A: Run a sequence of operations: ");
                Console.WriteLine("Create a new vector by calling 'Vector<int> vector = new Vector<int>(5);'");
                vector = new Vector <int>(5);
                Console.WriteLine(" :: SUCCESS");
                Console.WriteLine("Add a sequence of numbers 2, 6, 8, 5, 5, 1, 8, 5, 3, 5, 7, 1, 4, 9");
                vector.Add(2); vector.Add(6); vector.Add(8); vector.Add(5); vector.Add(5); vector.Add(1); vector.Add(8); vector.Add(5);
                vector.Add(3); vector.Add(5); vector.Add(7); vector.Add(1); vector.Add(4); vector.Add(9);
                Console.WriteLine(" :: SUCCESS");
                result = result + "A";
            }
            catch (Exception exception)
            {
                Console.WriteLine(" :: FAIL");
                Console.WriteLine(exception.ToString());
                result = result + "-";
            }

            // test 2
            try
            {
                Console.WriteLine("\nTest B: Run a sequence of operations: ");
                Console.WriteLine("Check whether the interface IEnumerable<T> is implemented for the Vector<T> class");
                if (!(vector is IEnumerable <int>))
                {
                    throw new Exception("Vector<T> does not implement IEnumerable<T>");
                }
                Console.WriteLine(" :: SUCCESS");
                Console.WriteLine("Check whether GetEnumerator() method is implemented");
                vector.GetEnumerator();
                Console.WriteLine(" :: SUCCESS");
                result = result + "B";
            }
            catch (NotImplementedException)
            {
                Console.WriteLine(" :: FAIL");
                Console.WriteLine("GetEnumerator() method is not implemented");
                result = result + "-";
            }
            catch (Exception exception)
            {
                Console.WriteLine(" :: FAIL");
                Console.WriteLine(exception.ToString());
                result = result + "-";
            }

            // test 3
            try
            {
                Console.WriteLine("\nTest C: Run a sequence of operations: ");
                Console.WriteLine("Return the Enumerator of the Vector<T> and check whether it implements IEnumerator<T>");
                if (!(vector.GetEnumerator() is IEnumerator <int>))
                {
                    throw new Exception("The Enumerator of the Vector<T> does not implement IEnumerator<T>");
                }
                Console.WriteLine("Check the initial value of Current of the Enumerator");
                if (vector.GetEnumerator().Current != default(int))
                {
                    throw new Exception("The initial Current value of the Enumerator is incorrect. Must be the value of " + default(int));
                }

                Console.WriteLine("Check the value of Current of the Enumerator after MoveNext() operation");
                IEnumerator <int> enumerator = vector.GetEnumerator();
                enumerator.MoveNext();
                if (enumerator.Current != 2)
                {
                    throw new Exception("The value of Current of the Enumerator after MoveNext() operation is incorrect. Must be the value of " + vector[0]);
                }
                Console.WriteLine(" :: SUCCESS");
                result = result + "C";
            }
            catch (Exception exception)
            {
                Console.WriteLine(" :: FAIL");
                Console.WriteLine(exception.ToString());
                result = result + "-";
            }

            // test 4
            try
            {
                Console.WriteLine("\nTest D: Check the content of the Vector<int> by traversing it via 'foreach' statement ");
                if (!CheckIntSequence(new int[] { 2, 6, 8, 5, 5, 1, 8, 5, 3, 5, 7, 1, 4, 9 }, vector))
                {
                    throw new Exception("The 'foreach' statement produces an incorrect sequence of integers");
                }
                Console.WriteLine(" :: SUCCESS");
                result = result + "D";
            }
            catch (Exception exception)
            {
                Console.WriteLine(" :: FAIL");
                Console.WriteLine(exception.ToString());
                result = result + "-";
            }

            // test 5
            int num = 14;

            Student[]        certificate_student = new Student[num];
            Vector <Student> students            = null;

            try
            {
                string[] names  = new string[] { "Kelly", "Cindy", "John", "Andrew", "Richard", "Michael", "Guy", "Elicia", "Tom", "Iman", "Simon", "Vicky" };
                Random   random = new Random(100);
                Console.WriteLine("\nTest E: Run a sequence of operations: ");
                Console.WriteLine("Create a new vector of Student objects by calling 'Vector<Student> students = new Vector<Student>();'");
                students = new Vector <Student>();
                for (int i = 0; i < num; i++)
                {
                    Student student = new Student()
                    {
                        Name = names[random.Next(0, names.Length)], Id = i
                    };
                    Console.WriteLine("Add student with record: " + student.ToString());
                    students.Add(student);
                    certificate_student[i] = student;
                }
                Console.WriteLine("Print the vector of students via students.ToString();");
                Console.WriteLine(students.ToString());

                Console.WriteLine(" :: SUCCESS");
                result = result + "E";
            }
            catch (Exception exception)
            {
                Console.WriteLine(" :: FAIL");
                Console.WriteLine(exception.ToString());
                result = result + "-";
            }

            // test 6
            try
            {
                Console.WriteLine("\nTest F: Check the content of the Vector<Student> by traversing it via 'foreach' statement ");
                if (!CheckIntSequence(certificate_student, students))
                {
                    throw new Exception("The 'foreach' statement produces an incorrect sequence of dtudents");
                }
                Console.WriteLine(" :: SUCCESS");
                result = result + "F";
            }
            catch (Exception exception)
            {
                Console.WriteLine(" :: FAIL");
                Console.WriteLine(exception.ToString());
                result = result + "-";
            }

            Console.WriteLine("\n\n ------------------- SUMMARY ------------------- ");
            Console.WriteLine("Tests passed: " + result);
            Console.ReadKey();
        }
Esempio n. 23
0
 public void ShouldReturnLengthOfListAsOneForString()
 {
     Vector<string> list = new Vector<string>();
     list.Add("sample");
     int result = list.Count;
     Assert.AreEqual(1, result);
 }
Esempio n. 24
0
 public void ShouldReturnNegativeOneSinceValueIsNotInList()
 {
     Vector<int> list = new Vector<int>();
     list.Add(2);
     list.Add(3);
     list.Add(1);
     int index = list.IndexOf(4);
     Assert.AreEqual(-1, index);
 }
Esempio n. 25
0
        public Vector<Holiday> listHolidays(uint gvoid)
        {
            // Declarations
            Vector<Holiday> quals = new Vector<Holiday>();
            uint gvhid = 0, modifiedby = 0;
            DateTime datemodified = new DateTime(1901, 1, 1), start = new DateTime(1901, 1, 1), end = new DateTime(1901, 1, 1);
            Holiday input = new Holiday();

            // Declarations

            // Command
            string query = string.Format("SELECT gvh_id, gvh_start, gvh_end, date_modified, modified_by " +
                                            "FROM gfrc_volunteer_holiday WHERE gvo_id = {0}", gvoid);

            try
            {
                using (conn)
                {
                    conn.Open();
                    cmd = new OleDbCommand(query, conn);
                    rdr = cmd.ExecuteReader();

                    while (rdr.Read())
                    {
                        if (UInt32.TryParse(rdr.GetValue(0).ToString(), out gvhid))
                        {
                            start = rdr.GetDateTime(1);
                            if (!DateTime.TryParse(rdr.GetValue(2).ToString(), out end))
                                end = new DateTime(1901, 1, 1);
                            if (!DateTime.TryParse(rdr.GetValue(14).ToString(), out datemodified))
                                datemodified = new DateTime(1901, 1, 1);
                            if (!UInt32.TryParse(rdr.GetValue(15).ToString(), out modifiedby))
                                modifiedby = 0;

                            input = new Holiday(gvhid, gvoid, start, end, datemodified, modifiedby);
                            quals.Add(input);
                        }
                    }
                }
            }
            finally
            {
                if (rdr != null)
                    rdr.Close();
            }
            if (conn != null)
            {
                conn.Close();
            }

            return quals;
        }
Esempio n. 26
0
        static void Main(string[] args)
        {
            string result       = "";
            int    problem_size = 20;

            int[]  data = new int[problem_size]; data[0] = 333;
            Random k    = new Random(1000);

            for (int i = 1; i < problem_size; i++)
            {
                data[i] = 100 + k.Next(900);
            }

            Vector <int> vector = new Vector <int>(problem_size);

            // ------------------ BinarySearch ----------------------------------//
            int[] temp = null; int check;

            try
            {
                vector.Sorter = null;
                temp          = new int[problem_size];
                data.CopyTo(temp, 0);
                Array.Sort(temp, new AscendingIntComparer());
                Console.WriteLine("\nTest A: Apply BinarySearch searching for number 333 to array of integer numbers sorted in AscendingIntComparer: ");
                vector = new Vector <int>(problem_size);
                for (int i = 0; i < problem_size; i++)
                {
                    vector.Add(data[i]);
                }
                vector.Sort(new AscendingIntComparer());
                Console.WriteLine("Resulting order: " + vector.ToString());
                check = Array.BinarySearch(temp, 333, new AscendingIntComparer());
                check = check < 0 ? -1 : check;
                if (vector.BinarySearch(333, new AscendingIntComparer()) != check)
                {
                    throw new Exception("The resulting index (or return value) is incorrect.");
                }
                Console.WriteLine(" :: SUCCESS");
                result = result + "A";
            }
            catch (Exception exception)
            {
                Console.WriteLine(" :: FAIL");
                Console.WriteLine(exception.ToString());
                result = result + "-";
            }

            try
            {
                vector.Sorter = null;
                temp          = new int[problem_size];
                data.CopyTo(temp, 0);
                Array.Sort(temp, new AscendingIntComparer());
                Console.WriteLine("\nTest B: Apply BinarySearch searching for number " + (temp[0] - 1) + " to array of integer numbers sorted in AscendingIntComparer: ");
                vector = new Vector <int>(problem_size);
                for (int i = 0; i < problem_size; i++)
                {
                    vector.Add(data[i]);
                }
                vector.Sort(new AscendingIntComparer());
                Console.WriteLine("Resulting order: " + vector.ToString());
                check = Array.BinarySearch(temp, temp[0] - 1, new AscendingIntComparer());
                check = check < 0 ? -1 : check;
                if (vector.BinarySearch(data[0] - 1, new AscendingIntComparer()) != check)
                {
                    throw new Exception("The resulting index (or return value) is incorrect.");
                }
                Console.WriteLine(" :: SUCCESS");
                result = result + "B";
            }
            catch (Exception exception)
            {
                Console.WriteLine(" :: FAIL");
                Console.WriteLine(exception.ToString());
                result = result + "-";
            }

            try
            {
                vector.Sorter = null;

                Console.WriteLine("\nTest C: Apply BinarySearch searching for number " + (temp[problem_size - 1] + 1) + " to array of integer numbers sorted in AscendingIntComparer: ");
                temp = new int[problem_size];
                data.CopyTo(temp, 0);
                Array.Sort(temp, new AscendingIntComparer());
                vector = new Vector <int>(problem_size);
                for (int i = 0; i < problem_size; i++)
                {
                    vector.Add(data[i]);
                }
                vector.Sort(new AscendingIntComparer());
                Console.WriteLine("Resulting order: " + vector.ToString());
                check = Array.BinarySearch(temp, temp[problem_size - 1] + 1, new AscendingIntComparer());
                check = check < 0 ? -1 : check;
                if (vector.BinarySearch(data[problem_size - 1] + 1, new AscendingIntComparer()) != check)
                {
                    throw new Exception("The resulting index (or return value) is incorrect.");
                }
                Console.WriteLine(" :: SUCCESS");
                result = result + "C";
            }
            catch (Exception exception)
            {
                Console.WriteLine(" :: FAIL");
                Console.WriteLine(exception.ToString());
                result = result + "-";
            }

            try
            {
                vector.Sorter = null;
                temp          = new int[problem_size];
                data.CopyTo(temp, 0);
                Array.Sort(temp, new DescendingIntComparer());
                Console.WriteLine("\nTest D: Apply BinarySearch searching for number 333 to array of integer numbers sorted in DescendingIntComparer: ");
                vector = new Vector <int>(problem_size);
                for (int i = 0; i < problem_size; i++)
                {
                    vector.Add(data[i]);
                }
                vector.Sort(new DescendingIntComparer());
                Console.WriteLine("Resulting order: " + vector.ToString());
                check = Array.BinarySearch(temp, 333, new DescendingIntComparer());
                check = check < 0 ? -1 : check;
                if (vector.BinarySearch(333, new DescendingIntComparer()) != check)
                {
                    throw new Exception("The resulting index (or return value) is incorrect.");
                }
                Console.WriteLine(" :: SUCCESS");
                result = result + "D";
            }
            catch (Exception exception)
            {
                Console.WriteLine(" :: FAIL");
                Console.WriteLine(exception.ToString());
                result = result + "-";
            }

            try
            {
                vector.Sorter = null;
                temp          = new int[problem_size];
                data.CopyTo(temp, 0);
                Array.Sort(temp, new DescendingIntComparer());
                Console.WriteLine("\nTest E: Apply BinarySearch searching for number " + (temp[0] - 1) + " to array of integer numbers sorted in DescendingIntComparer: ");
                vector = new Vector <int>(problem_size);
                for (int i = 0; i < problem_size; i++)
                {
                    vector.Add(data[i]);
                }
                vector.Sort(new DescendingIntComparer());
                Console.WriteLine("Resulting order: " + vector.ToString());
                check = Array.BinarySearch(temp, temp[0] - 1, new DescendingIntComparer());
                check = check < 0 ? -1 : check;
                if (vector.BinarySearch(data[0] - 1, new DescendingIntComparer()) != check)
                {
                    throw new Exception("The resulting index (or return value) is incorrect.");
                }
                Console.WriteLine(" :: SUCCESS");
                result = result + "E";
            }
            catch (Exception exception)
            {
                Console.WriteLine(" :: FAIL");
                Console.WriteLine(exception.ToString());
                result = result + "-";
            }

            try
            {
                vector.Sorter = null;

                Console.WriteLine("\nTest F: Apply BinarySearch searching for number " + (temp[problem_size - 1] + 1) + " to array of integer numbers sorted in DescendingIntComparer: ");
                temp = new int[problem_size];
                data.CopyTo(temp, 0);
                Array.Sort(temp, new DescendingIntComparer());
                vector = new Vector <int>(problem_size);
                for (int i = 0; i < problem_size; i++)
                {
                    vector.Add(data[i]);
                }
                vector.Sort(new DescendingIntComparer());
                Console.WriteLine("Resulting order: " + vector.ToString());
                check = Array.BinarySearch(temp, temp[problem_size - 1] + 1, new DescendingIntComparer());
                check = check < 0 ? -1 : check;
                if (vector.BinarySearch(data[problem_size - 1] + 1, new DescendingIntComparer()) != check)
                {
                    throw new Exception("The resulting index (or return value) is incorrect.");
                }
                Console.WriteLine(" :: SUCCESS");
                result = result + "F";
            }
            catch (Exception exception)
            {
                Console.WriteLine(" :: FAIL");
                Console.WriteLine(exception.ToString());
                result = result + "-";
            }

            Console.WriteLine("\n\n ------------------- SUMMARY ------------------- ");
            Console.WriteLine("Tests passed: " + result);
            Console.ReadKey();
        }