예제 #1
0
 public decimal CalculateGeneralAveragePerStudent(Student student)
 {
     decimal sum = 0;
     for (int i = 0; i < student.subjectAndGrades.Length; i++)
         sum += CalculateAveragePerSubjectPerStudent(student.subjectAndGrades[i]);
     return sum / student.subjectAndGrades.Length;
 }
예제 #2
0
        public void FindsTwoStudentsWithSpecificAverage()
        {
            Subject math1 = new Subject("Mathematics", new int[] { 5, 5 });
            Subject sport1 = new Subject("Sport", new int[] { 10, 4 });
            Subject[] subject1 = { math1, sport1 };
            Student gheorghe = new Student { name = "Gheorghe", subjectAndGrades = subject1 };

            Subject math2 = new Subject("Mathematics", new int[] { 10, 9 });
            Subject sport2 = new Subject("Sport", new int[] { 7, 5 });
            Subject[] subject2 = { math2, sport2 };
            Student ion = new Student { name = "Ion", subjectAndGrades = subject2 };

            Subject math3 = new Subject("Mathematics", new int[] { 7, 5 });
            Subject sport3 = new Subject("Sport", new int[] { 10, 8 });
            Subject[] subject3 = { math3, sport3 };
            Student vasile = new Student { name = "Vasile", subjectAndGrades = subject3 };

            Subject math4 = new Subject("Mathematics", new int[] { 5, 5 });
            Subject sport4 = new Subject("Sport", new int[] { 10, 4 });
            Subject[] subject4 = { math4, sport4 };
            Student grigore = new Student { name = "Grigore", subjectAndGrades = subject4 };

            Student[] allClass = { gheorghe, ion, vasile, grigore };
            Average[] averageArray = SelectionSortForGeneralAverage(ref allClass);
            string[] toFind = FindSpecificAverage(allClass, 6m);
            string[] expected = { "Gheorghe", "Grigore" };
            CollectionAssert.AreEqual(toFind, expected);
        }
 public void ShouldCalculateGeneralMeanForOneStudent()
 {
     Grades[] cucuGrade = { new Grades("Math", new int[] { 10, 8 }),
                           new Grades("Sport", new int[] { 6, 8 })};
     Student cucu = new Student("Cucu",cucuGrade);
     Assert.AreEqual(8, cucu.CalculateGeneralMean());
 }
예제 #4
0
 public string[] BuildsStudentArray(Student[] fullClass)
 {
     string[] studentsNames = new string[fullClass.Length];
     for (int i = 0; i < fullClass.Length; i++)
     {
         studentsNames[i] = fullClass[i].name;
     }
     return studentsNames;
 }
예제 #5
0
 public void ShouldReturnStringArrayForOneStudent()
 {
     Maters mathCucu = new Maters("Mathematics", new int[] { 6, 7 });
     Maters sportCucu = new Maters("Sport", new int[] { 8, 9 });
     Maters[] cucuMatters = { mathCucu, sportCucu };
     Student cucu = new Student { name = "Cucu", mattersAndNotes = cucuMatters };
     Student[] allClass = { cucu };
     CollectionAssert.AreEqual(new string[] { "Cucu" }, SortStudentsAlpha(allClass));
 }
예제 #6
0
 public void ShouldReturnGeneralMeanForOneStudent()
 {
     Maters mathCucu = new Maters("Mathematics", new int[] { 6, 7 });
     Maters sportCucu = new Maters("Sport", new int[] { 8, 9 });
     Maters[] cucuMatters = { mathCucu, sportCucu };
     Student cucu = new Student { name = "Cucu", mattersAndNotes = cucuMatters };
     Student[] allClass = { cucu };
     GeneralMean[] expected = { new GeneralMean("Cucu", 7.5m) };
     CollectionAssert.AreEqual(expected, SortStudentsByGeneralMean(allClass));
 }
예제 #7
0
 public Average[] BuildAverageArray(Student[] fullClass)
 {
     Average[] students = new Average[fullClass.Length];
     for (int i = 0; i < fullClass.Length; i++)
     {
         students[i].name = fullClass[i].name;
         students[i].average = CalculateGeneralAveragePerStudent(fullClass[i]);
     }
     return students;
 }
 public void SouldReturnStudentArrayWithStudentsSortedByGenMean()
 {
     Grades[] cucuGrade = { new Grades("Math", new int[] { 10, 8 }),
                           new Grades("Sport", new int[] { 6, 8 })};
     Student cucu = new Student("Cucu", cucuGrade);
     Grades[] bubuGrade = { new Grades("Math", new int[] { 7, 9 }),
                           new Grades("Sport", new int[] { 10, 10 })};
     Student bubu = new Student("Bubu", bubuGrade);
     Student[] students = {cucu,bubu };
     StudentsCatalog allClass = new StudentsCatalog(students);
     Student[] expected = { bubu, cucu };
     CollectionAssert.AreEqual(expected, allClass.SortStudentsByGenMean());
 }
예제 #9
0
 public string[] FindSpecificAverage(Student[] fullClass, decimal averageToFind)
 {
     string[] studentsArray = { };
     Average[] averageArray = SelectionSortForGeneralAverage(ref fullClass);
     for (int i = 0; i < averageArray.Length; i++)
     {
         if (averageArray[i].average == averageToFind)
         {
             Array.Resize(ref studentsArray, studentsArray.Length + 1);
             studentsArray[studentsArray.Length - 1] = averageArray[i].name;
         }
     }
     return studentsArray;
 }
 public void SouldReturnStudentsWithHighestNumberOfTenGrades()
 {
     Grades[] cucuGrade = { new Grades("Math", new int[] { 10, 8 }),
                           new Grades("Sport", new int[] { 6, 8 })};
     Student cucu = new Student("Cucu", cucuGrade);
     Grades[] bubuGrade = { new Grades("Math", new int[] { 7, 9 }),
                           new Grades("Sport", new int[] { 10, 10 })};
     Student bubu = new Student("Bubu", bubuGrade);
     Grades[] tutuGrade = { new Grades("Math", new int[] { 10, 10 }),
                           new Grades("Sport", new int[] { 10, 10 })};
     Student tutu = new Student("Tutu", tutuGrade);
     Student[] students = { cucu, bubu, tutu };
     StudentsCatalog allClass = new StudentsCatalog(students);
     Student[] expected = { tutu };
     CollectionAssert.AreEqual(expected, allClass.FindStudentsWithTheMostTenGrades());
 }
 public void SouldReturnArrayWithStudentsWithASpecificGeneralMean()
 {
     Grades[] cucuGrade = { new Grades("Math", new int[] { 10, 8 }),
                           new Grades("Sport", new int[] { 6, 8 })};
     Student cucu = new Student("Cucu", cucuGrade);
     Grades[] bubuGrade = { new Grades("Math", new int[] { 7, 9 }),
                           new Grades("Sport", new int[] { 10, 10 })};
     Student bubu = new Student("Bubu", bubuGrade);
     Grades[] tutuGrade = { new Grades("Math", new int[] { 10, 10 }),
                           new Grades("Sport", new int[] { 10, 10 })};
     Student tutu = new Student("Tutu", tutuGrade);
     Student[] students = { cucu, bubu, tutu };
     StudentsCatalog allClass = new StudentsCatalog(students);
     Student[] expected = { tutu };
     CollectionAssert.AreEqual(expected, allClass.FindStudentsWithSpecificGeneralMean(10));
 }
예제 #12
0
 public void ShouldReturnStudentsWithTenNotes()
 {
     Maters mathZuzu = new Maters("Mathematics", new int[] { 8, 8 });
     Maters sportZuzu = new Maters("Sport", new int[] { 10, 10 });
     Maters[] zuzuMatters = { mathZuzu, sportZuzu };
     Student zuzu = new Student { name = "Zuzu", mattersAndNotes = zuzuMatters };
     Maters mathCucu = new Maters("Mathematics", new int[] { 6, 7 });
     Maters sportCucu = new Maters("Sport", new int[] { 8, 9 });
     Maters[] cucuMatters = { mathCucu, sportCucu };
     Student cucu = new Student { name = "Cucu", mattersAndNotes = cucuMatters };
     Maters mathBubu = new Maters("Mathematics", new int[] { 9, 8 });
     Maters sportBubu = new Maters("Sport", new int[] { 10, 9 });
     Maters[] bubuMatters = { mathBubu, sportBubu };
     Student bubu = new Student { name = "Bubu", mattersAndNotes = bubuMatters };
     Student[] allClass = { cucu, bubu, zuzu };
     StudWithTenNotes[] expected = { new StudWithTenNotes("Bubu",1), new StudWithTenNotes("Zuzu", 2) };
     CollectionAssert.AreEqual(expected, SearchSudentsWithTenNotes(allClass));
 }
예제 #13
0
        public void TestsTheSelectionSortingAlgorithmForAlphabeticalOrder()
        {
            Subject math1 = new Subject("Mathematics", new int[] { 10, 9 });
            Subject sport1 = new Subject("Sport", new int[] { 7, 5 });
            Subject[] subjects1 = { math1, sport1 };
            Student zorand = new Student { name = "Zorand", subjectAndGrades = subjects1 };

            Subject math2 = new Subject("Mathematics", new int[] { 7, 5 });
            Subject sport2 = new Subject("Sport", new int[] { 10, 9 });
            Subject[] subjects2 = { math2, sport2 };
            Student alex = new Student { name = "Alex", subjectAndGrades = subjects2 };

            Subject math3 = new Subject("Mathematics", new int[] { 7, 5 });
            Subject sport3 = new Subject("Sport", new int[] { 10, 9 });
            Subject[] subjects3 = { math3, sport3 };
            Student petrica = new Student { name = "Petrica", subjectAndGrades = subjects3 };

            Student[] allClass = { zorand, alex, petrica };
            SelectionSort(ref allClass);
            CollectionAssert.AreEqual(new string[] { "Alex", "Petrica", "Zorand" }, BuildsStudentArray(allClass));
        }
 private void SortStruct(ref Student[] allStud)
 {
     for (int i = 0; i < allStud.Length - 1; i++)
     {
         for (int j = i + 1; j < allStud.Length; j++)
         {
             if (allStud[i].CalculateGeneralMean() < allStud[j].CalculateGeneralMean())
             {
                 Swap(ref allStud[i], ref allStud[j]);
             }
         }
     };
 }
예제 #15
0
        public void TestsTheGeneralAverageCalculationForOneStudent()
        {
            Subject math1 = new Subject("Mathematics", new int[] { 10, 9 });
            Subject sport1 = new Subject("Sport", new int[] { 7, 5 });
            Subject[] subjects1 = { math1, sport1 };
            Student zorand = new Student { name = "Zorand", subjectAndGrades = subjects1 };

            Student[] allClass = { zorand };

            Assert.AreEqual(7.75m, CalculateGeneralAveragePerStudent(zorand));
        }
 public void AddStudentToTheClass(Student student)
 {
     Array.Resize(ref allClass, allClass.Length + 1);
     allClass[allClass.Length] = student;
 }
예제 #17
0
 public void QuickSort(ref Student[] theClass, int left, int right)
 {
     if (left < right)
     {
         int q = Partition(ref theClass, left, right);
         QuickSort(ref theClass, left, q - 1);
         QuickSort(ref theClass, q + 1, right);
     }
 }
예제 #18
0
 static void Swap(ref Student a, ref Student b)
 {
     Student temp = a;
     a = b;
     b = temp;
 }
예제 #19
0
 public Average[] SelectionSortForGeneralAverage(ref Student[] fullClass)
 {
     Average[] allClassWithAverage = BuildAverageArray(fullClass);
     for (int i = 0; i < allClassWithAverage.Length - 1; i++)
         for (int j = i + 1; j < allClassWithAverage.Length; j++)
             if (allClassWithAverage[j].average > allClassWithAverage[i].average)
                 SwapForAverage(ref allClassWithAverage[i], ref allClassWithAverage[j]);
     return allClassWithAverage;
 }
예제 #20
0
 public void SelectionSort(ref Student[] theClass)
 {
     for (int i = 0; i < theClass.Length - 1; i++)
         for (int j = i + 1; j < theClass.Length; j++)
           if (theClass[j].name.CompareTo(theClass[i].name) < 0)
                 Swap(ref theClass[i], ref theClass[j]);
 }
 private void AddStudToResult(ref Student[] result, Student stud)
 {
     Array.Resize(ref result, result.Length+1);
     result[result.Length-1] = stud;
 }
예제 #22
0
        public void TestsTheSortForTheAverageStructArray()
        {
            Subject math1 = new Subject("Mathematics", new int[] { 5, 5 });
            Subject sport1 = new Subject("Sport", new int[] { 10, 4 });
            Subject[] subject1 = { math1, sport1 };
            Student gheorghe = new Student { name = "Gheorghe", subjectAndGrades = subject1 };

            Subject math2 = new Subject("Mathematics", new int[] { 10, 9 });
            Subject sport2 = new Subject("Sport", new int[] { 7, 5 });
            Subject[] subject2 = { math2, sport2 };
            Student ion = new Student { name = "Ion", subjectAndGrades = subject2 };

            Subject math3 = new Subject("Mathematics", new int[] { 7, 5 });
            Subject sport3 = new Subject("Sport", new int[] { 10, 8 });
            Subject[] subject3 = { math3, sport3 };
            Student vasile = new Student { name = "Vasile", subjectAndGrades = subject3 };

            Student[] allClass = { gheorghe, ion, vasile };
            Average[] averageArray = SelectionSortForGeneralAverage(ref allClass);

            Average[] expected = { new Average("Ion", 7.75m), new Average("Vasile", 7.5m), new Average("Gheorghe", 6) };
            CollectionAssert.AreEqual(expected, averageArray);
        }
예제 #23
0
        static int Partition(ref Student[] theClass, int left, int right)
        {
            Student pivot = theClass[right];
            int i = left;

            for (int j = left; j < right; j++)
            {
                if (theClass[j].name.CompareTo(pivot.name) < 0)
                    Swap(ref theClass[j], ref theClass[i++]);
            }
            theClass[right] = theClass[i];
            theClass[i] = pivot;
            return i;
        }
 private void Swap(ref Student nameAndGenMean1, ref Student nameAndGenMean2)
 {
     Student temp = nameAndGenMean1;
     nameAndGenMean1 = nameAndGenMean2;
     nameAndGenMean2 = temp;
 }
예제 #25
0
 public void ShouldReturnTwoStudentWithASpecificGeneralMean()
 {
     Maters mathZuzu = new Maters("Mathematics", new int[] { 8, 8 });
     Maters sportZuzu = new Maters("Sport", new int[] { 10, 10 });
     Maters[] zuzuMatters = { mathZuzu, sportZuzu };
     Student zuzu = new Student { name = "Zuzu", mattersAndNotes = zuzuMatters };
     Maters mathCucu = new Maters("Mathematics", new int[] { 6, 7 });
     Maters sportCucu = new Maters("Sport", new int[] { 8, 9 });
     Maters[] cucuMatters = { mathCucu, sportCucu };
     Student cucu = new Student { name = "Cucu", mattersAndNotes = cucuMatters };
     Maters mathBubu = new Maters("Mathematics", new int[] { 9, 8 });
     Maters sportBubu = new Maters("Sport", new int[] { 10, 9 });
     Maters[] bubuMatters = { mathBubu, sportBubu };
     Student bubu = new Student { name = "Bubu", mattersAndNotes = bubuMatters };
     Student[] allClass = { cucu, bubu, zuzu };
     string[] expected = { "Bubu","Zuzu" };
     CollectionAssert.AreEqual(expected, SearchStudentsByGeneralMean(allClass, 9m));
 }
예제 #26
0
        public void TestsIfBuildingTheStringArrayForFourStudentsWorks()
        {
            Subject math1 = new Subject("Mathematics", new int[] { 10, 9 });
            Subject sport1 = new Subject("Sport", new int[] { 7, 5 });
            Subject[] subjects1 = { math1, sport1 };
            Student ion = new Student { name = "Ion", subjectAndGrades = subjects1 };

            Subject math2 = new Subject("Mathematics", new int[] { 7, 5 });
            Subject sport2 = new Subject("Sport", new int[] { 10, 9 });
            Subject[] subjects2 = { math2, sport2 };
            Student vasile = new Student { name = "Vasile", subjectAndGrades = subjects2 };

            Subject math3 = new Subject("Mathematics", new int[] { 7, 5 });
            Subject sport3 = new Subject("Sport", new int[] { 10, 9 });
            Subject[] subjects3 = { math3, sport3 };
            Student petrica = new Student { name = "Petrica", subjectAndGrades = subjects3 };

            Student[] allClass = { ion, vasile, petrica };
            CollectionAssert.AreEqual(new string[] { "Ion", "Vasile", "Petrica" }, BuildsStudentArray(allClass));
        }
예제 #27
0
        public void TestsIfBuildingTheStringArrayForTwoStudentsWorks()
        {
            Subject maths = new Subject("Mathematics", new int[] { 10, 9 });
            Subject sports = new Subject("Sport", new int[] { 7, 5 });
            Subject[] subjects = { maths, sports };
            Student ion = new Student { name = "Ion", subjectAndGrades = subjects };

            Subject math = new Subject("Mathematics", new int[] { 7, 5 });
            Subject sport = new Subject("Sport", new int[] { 10, 9 });
            Subject[] subject = { math, sport };
            Student vasile = new Student { name = "Vasile", subjectAndGrades = subject };

            Student[] allClass = { ion, vasile };
            CollectionAssert.AreEqual(new string[] { "Ion", "Vasile" }, BuildsStudentArray(allClass));
        }
예제 #28
0
        public void TestsTheAverageCalculationPerStudentPerOneSubject()
        {
            Subject math1 = new Subject("Mathematics", new int[] { 10, 9 });
            Subject sport1 = new Subject("Sport", new int[] { 7, 5 });
            Subject[] subjects1 = { math1, sport1 };
            Student zorand = new Student { name = "Zorand", subjectAndGrades = subjects1 };

            Student[] allClass = { zorand};

            Assert.AreEqual(9.5m, CalculateAveragePerSubjectPerStudent(math1));
            //Assert.AreEqual(6, CalculateAveragePerSubjectPerStudent(sport1));
        }
예제 #29
0
        public void TestsIfBuildingTheAverageArrayForTwoStudentsWorks()
        {
            Subject maths = new Subject("Mathematics", new int[] { 10, 9 });
            Subject sports = new Subject("Sport", new int[] { 7, 5 });
            Subject[] subjects = { maths, sports };
            Student ion = new Student { name = "Ion", subjectAndGrades = subjects };

            Subject math = new Subject("Mathematics", new int[] { 7, 5 });
            Subject sport = new Subject("Sport", new int[] { 10, 8 });
            Subject[] subject = { math, sport };
            Student vasile = new Student { name = "Vasile", subjectAndGrades = subject };

            Student[] allClass = { ion, vasile };
            Average[] averageArray = BuildAverageArray(allClass);

            Average[] expected = { new Average("Ion", 7.75m), new Average("Vasile", 7.5m) };

            CollectionAssert.AreEqual(expected, averageArray);
        }
 public StudentsCatalog(Student[] allClass)
 {
     this.allClass = allClass;
 }