Exemple #1
0
        private Tuple <bool, STANDING> StudentStanding(STANDING standing)
        {
            try
            {
                switch (standing)
                {
                case STANDING.Remedial:
                    return(new Tuple <bool, STANDING>(false, standing));

                case STANDING.Average:
                    return(new Tuple <bool, STANDING>(true, standing));

                case STANDING.SumaCumLaude:
                    return(new Tuple <bool, STANDING>(true, standing));

                case STANDING.MagnaCumLaude:
                    return(new Tuple <bool, STANDING>(true, standing));

                default:
                    return(new Tuple <bool, STANDING>(false, standing));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message.ToString());
            }
            return(new Tuple <bool, STANDING>(false, standing));
        }
Exemple #2
0
        private STANDING GetStandingForStudent(int average)
        {
            STANDING standing = STANDING.None;

            try
            {
                if (average < 50)
                {
                    standing = STANDING.Remedial;
                }
                else if (average < 80)
                {
                    standing = STANDING.Average;
                }
                else if (average < 95)
                {
                    standing = STANDING.MagnaCumLaude;
                }
                else
                {
                    standing = STANDING.MagnaCumLaude;
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message.ToString());
            }

            return(standing);
        }
        public void TestStanding(int marks, STANDING standing)
        {
            var students = new[]
            {
                new Student
                {
                    Id      = 1,
                    Courses = new Course[]
                    {
                        new Course {
                            Id = 1, Name = "Math", Mark = marks
                        },
                        new Course {
                            Id = 2, Name = "Science", Mark = marks
                        },
                        new Course {
                            Id = 3, Name = "Literature", Mark = marks
                        },
                        new Course {
                            Id = 4, Name = "Physichal Education", Mark = marks
                        }
                    }
                }
            };
            Mock <IStudentRepository> _mockStuRepository = new Mock <IStudentRepository>();

            _mockStuRepository.Setup(x => x.GetStudents()).Returns(students);
            _mockStuRepository.Setup(r => r.GetStudent(It.IsAny <int>()))
            .Returns <int>(id => students.SingleOrDefault(r => r.Id == id));
            var tracker = new GraduationTracker(_mockRequirementRepository.Object, _mockDiplomaRepository.Object, _mockStuRepository.Object);

            var result = tracker.HasGraduated(1, 1);

            Assert.AreEqual(standing, result.Item2);
        }
Exemple #4
0
        public void TestStatus_SumaCumLaude()
        {
            Diploma            diploma = _diplomaRepository.GetDiploma(1);
            List <List <int> > marks   = new List <List <int> >();
            List <int>         marks1  = new List <int>()
            {
                95, 90, 100, 100
            };
            List <int> marks2 = new List <int>()
            {
                100, 100, 95, 85
            };

            marks.Add(marks1);
            marks.Add(marks2);
            List <STANDING> standings = new List <STANDING>();

            List <Student> students = GetStudents_Fake(marks);

            foreach (Student student in students)
            {
                STANDING studentStanding = _tracker.GetGraduationStatus(diploma, student).Item2;
                standings.Add(studentStanding);
            }

            Assert.IsTrue(standings.FindAll(x => x == STANDING.SumaCumLaude).Count() == 2);
        }
Exemple #5
0
        public void TestStatus_Average()
        {
            Diploma            diploma = _diplomaRepository.GetDiploma(1);
            List <List <int> > marks   = new List <List <int> >();
            List <int>         marks1  = new List <int>()
            {
                50, 60, 70, 80
            };
            List <int> marks2 = new List <int>()
            {
                60, 50, 65, 70
            };

            marks.Add(marks1);
            marks.Add(marks2);
            List <STANDING> standings = new List <STANDING>();

            List <Student> students = GetStudents_Fake(marks);

            foreach (Student student in students)
            {
                STANDING studentStanding = _tracker.GetGraduationStatus(diploma, student).Item2;
                standings.Add(studentStanding);
            }

            Assert.IsTrue(standings.FindAll(x => x == STANDING.Average).Count() == 2);
        }
Exemple #6
0
        public void Test1GraduationStanding()
        {
            Diploma diploma = new Diploma();
            Student student = new Student();
            RequirementRepository requRepo = new RequirementRepository();

            diploma = new Diploma
            {
                Id           = 1,
                Credits      = 4,
                Requirements = new List <Requirement>()
                {
                    new Requirement()
                    {
                        Id = 100
                    }, new Requirement()
                    {
                        Id = 102
                    }, new Requirement()
                    {
                        Id = 103
                    }, new Requirement()
                    {
                        Id = 104
                    }
                }
            };

            student = new Student
            {
                Id        = 1,
                DiplomaId = 1,
                Courses   = new Course[]
                {
                    new Course {
                        CourseId = 1, CourseName = "Math", Mark = 95
                    },
                    new Course {
                        CourseId = 2, CourseName = "Science", Mark = 95
                    },
                    new Course {
                        CourseId = 3, CourseName = "Literature", Mark = 95
                    },
                    new Course {
                        CourseId = 4, CourseName = "Physichal Education", Mark = 95
                    }
                }
            };

            var      actual           = new GraduationTracker(requRepo, student, diploma).HasGraduated();
            STANDING expectedStanding = STANDING.MagnaCumLaude;

            // Standing
            Assert.AreEqual(expectedStanding, actual.Item2);
        }
Exemple #7
0
        public Tuple <bool, STANDING> GetGraduationStatus(Diploma diploma, Student student)
        {
            Tuple <bool, STANDING> graduationStatus = null;
            int averageMark = GetAverageMark(diploma, student);

            if (averageMark > 0)
            {
                STANDING standing     = GetStanding(averageMark);
                bool     hasGraduated = HasGraduated(standing);
                graduationStatus = new Tuple <bool, STANDING>(hasGraduated, standing);
            }
            return(graduationStatus);
        }
    public STANDING GetPlayerStanding()
    {
        STANDING playerStanding = STANDING.TIE;

        foreach (STANDING place in standings.Keys)
        {
            if (standings[place] == "Player")
            {
                playerStanding = place;
            }
        }

        return(playerStanding);
    }
        public static bool IsGraduatedBasedOnStanding(STANDING standing)
        {
            bool IsGraduated = false;

            if ((standing == STANDING.Average) || (standing == STANDING.SumaCumLaude) || (standing == STANDING.MagnaCumLaude))
            {
                IsGraduated = true;
            }
            else
            {
                IsGraduated = false;
            }

            return(IsGraduated);
        }
Exemple #10
0
        public bool HasGraduated(STANDING standing)
        {
            switch (standing)
            {
            case STANDING.Remedial:
                return(false);

            case STANDING.Average:
            case STANDING.SumaCumLaude:
            case STANDING.MagnaCumLaude:
                return(true);

            default:
                return(false);
            }
        }
        public static Tuple <bool, STANDING> HasGraduated(Diploma Diploma, Student Student)
        {
            STANDING Standing = GetStanding(GetAverage(Diploma, Student));

            switch (Standing)
            {
            case STANDING.Remedial:
                return(new Tuple <bool, STANDING>(false, Standing));

            case STANDING.Average:
                return(new Tuple <bool, STANDING>(true, Standing));

            case STANDING.SumaCumLaude:
                return(new Tuple <bool, STANDING>(true, Standing));

            case STANDING.MagnaCumLaude:
                return(new Tuple <bool, STANDING>(true, Standing));

            default:
                return(new Tuple <bool, STANDING>(false, Standing));
            }
        }
Exemple #12
0
        public STANDING GetStanding(int average)
        {
            STANDING standing = STANDING.None;

            if (average < 50)
            {
                standing = STANDING.Remedial;
            }
            else if (average < 80)
            {
                standing = STANDING.Average;
            }
            else if (average < 95)
            {
                standing = STANDING.MagnaCumLaude;
            }
            else
            {
                standing = STANDING.SumaCumLaude;
            }

            return(standing);
        }
        public Tuple <bool, STANDING> HasGraduated(Diploma diploma, Student student)
        {
            // variables
            int  average           = 0;
            bool isFailedAnyCourse = false;

            // validations
            if (diploma == null ||
                diploma.Requirements == null)
            {
                throw new Exception("Invalid diploma");
            }

            if (student == null ||
                student.Courses == null)
            {
                throw new Exception("Invalid student");
            }

            // check if one is qualified for graduation
            foreach (int req in diploma.Requirements)
            {
                Requirement requirement = repository.GetRequirementById(req);

                // validation
                if (requirement == null)
                {
                    throw new Exception("Incorrect requirement id " + req);
                }

                // get averages and check if the one failed any courses
                bool isCourseFound = false;

                foreach (int reqCourse in requirement.Courses)
                {
                    foreach (Course course in student.Courses)
                    {
                        if (reqCourse == course.Id)
                        {
                            isCourseFound = true;
                            average      += course.Mark;

                            if (course.Mark < requirement.MinimumMark)
                            {
                                isFailedAnyCourse = true;
                            }

                            break;
                        }
                    }

                    if (isCourseFound)
                    {
                        break;
                    }
                }

                if (!isCourseFound)
                {
                    throw new Exception(String.Format("Course not found for a student id {0}", student.Id));
                }
            }

            // calculate course average
            average /= student.Courses.Length;

            // get standing
            STANDING standing = GetStanding(average);

            // if failed any course, return false
            if (isFailedAnyCourse)
            {
                return(new Tuple <bool, STANDING>(false, standing));
            }

            // return result based on the standing value
            switch (standing)
            {
            case STANDING.Remedial:
                return(new Tuple <bool, STANDING>(false, standing));

            case STANDING.Average:
                return(new Tuple <bool, STANDING>(true, standing));

            case STANDING.SumaCumLaude:
                return(new Tuple <bool, STANDING>(true, standing));

            case STANDING.MagnaCumLaude:
                return(new Tuple <bool, STANDING>(true, standing));

            default:
                return(new Tuple <bool, STANDING>(false, standing));
            }
        }