示例#1
0
        public void GetBoringScoreParser_ShouldReturnBoringScoreParser()
        {
            string             typeOfParser       = "BoringScoreParser";
            ScoreParserFactory scoreParserFactory = new ScoreParserFactory();
            Mock <IDiceHolder> mockDiceHolder     = GetMockDiceHolder(1, 2, 3, 4, 5);

            IScoreParser      actual   = scoreParserFactory.GetScoreParser(typeOfParser, mockDiceHolder.Object);
            BoringScoreParser expected = new BoringScoreParser(mockDiceHolder.Object);

            actual.Should().NotBeNull();
            actual.Should().BeEquivalentTo(expected);
        }
示例#2
0
        /// <summary>
        /// 進行排名。
        /// </summary>
        /// <param name="scoreParser">要被排名的成績計算邏輯。</param>
        /// <param name="option">排名選項,接序 or 不接序排名。</param>
        /// <param name="placeNamespace">存放排名結果的 Namespace。</param>
        public void Rank(IScoreParser <T> scoreParser, PlaceOptions option)
        {
            //取得有成績的學生。
            List <ScoredStudent> students = GetScoredStudents(scoreParser);

            //排序名次。
            students.Sort(delegate(ScoredStudent x, ScoredStudent y)
            {
                decimal X = x.Score;
                decimal Y = y.Score;

                //反過來排,由大到小。
                return(Y.CompareTo(X));
            });

            //決定排序。
            IPlaceAlgorithm algorithm = null;

            if (option == PlaceOptions.Sequence)
            {
                algorithm = new Sequence();
            }
            else
            {
                algorithm = new Unsequence();
            }

            int    radix     = students.Count;
            string scorename = scoreParser.Name;

            foreach (ScoredStudent each in students)
            {
                int level = algorithm.NextLevel(each.Score);

                T student = _students[each.Id];

                PlaceCollection places = GetPlaceCollection(student);

                if (places.Contains(scorename))
                {
                    places[scorename] = new Place(level, each.Score, radix);
                }
                else
                {
                    places.Add(scorename, new Place(level, each.Score, radix));
                }
            }
        }
示例#3
0
        /// <summary>
        /// 取得有成績的學生清單,並且轉型成 StudentInternal。
        /// </summary>
        /// <returns></returns>
        /// <remarks>如果該學生沒有成績,就不會列入排名。</remarks>
        private List <ScoredStudent> GetScoredStudents(IScoreParser <T> scoreParser)
        {
            List <ScoredStudent> students = new List <ScoredStudent>();

            foreach (T each in this)
            {
                decimal?score = scoreParser.GetScore(each);

                if (score.HasValue)
                {
                    students.Add(new ScoredStudent(each.Id, score.Value));
                }
            }

            return(students);
        }
示例#4
0
 public ScoreManager(IScoreParser scoreParser)
 {
     this._rules       = new List <IPointCalculationRule>();
     this._scoreParser = scoreParser;
 }
示例#5
0
        /// <summary>
        /// 進行排名。
        /// </summary>
        /// <param name="scoreParser">要被排名的成績計算邏輯。</param>
        /// <param name="option">排名選項,接序 or 不接序排名。</param>
        /// <param name="provider">當相同名次時決定先後成績資料,所有排名範圍內的學生都應該供相同順序與數量的成績資料,否則會產生無法預期的結果。</param>
        public void Rank(IScoreParser <T> scoreParser, PlaceOptions option)
        {
            //取得有成績的學生。
            List <ScoredStudent> students = GetScoredStudents(scoreParser);

            //沒有成績就不用排名了。
            if (students.Count <= 0)
            {
                return;
            }

            //排序名次。
            students.Sort(delegate(ScoredStudent x, ScoredStudent y)
            {
                if (scoreParser is IScoresParser <T> )
                {
                    IScoresParser <T> p2 = scoreParser as IScoresParser <T>;

                    if (x.SecondScores.Count <= 0)
                    {
                        x.SecondScores = p2.GetSecondScores(x.Source);
                    }
                    if (y.SecondScores.Count <= 0)
                    {
                        y.SecondScores = p2.GetSecondScores(y.Source);
                    }
                }
                return(y.CompareTo(x));
            });

            int    radix     = students.Count;   //基數。
            string scorename = scoreParser.Name; //排名的名稱。

            //先把之前的排名結果清掉。
            foreach (T each in this)
            {
                PlaceCollection places = GetPlaceCollection(each);
                if (places.Contains(scorename))
                {
                    places.Remove(scorename);
                }
            }

            //決定排序。
            IPlaceAlgorithm placeAlg = null;

            if (option == PlaceOptions.Sequence)
            {
                placeAlg = new Sequence();
            }
            else
            {
                placeAlg = new Unsequence();
            }

            StandardPercentage percenAlg = new StandardPercentage();

            percenAlg.Initital(students.Count);

            foreach (ScoredStudent each in students)
            {
                int level  = placeAlg.NextLevel(each);
                int percen = percenAlg.NextPercentage(level);

                T student = _students[each.Id];

                PlaceCollection places = GetPlaceCollection(student);

                if (places.Contains(scorename))
                {
                    places[scorename] = new Place(level, percen, each.Score, radix, this.Count);
                }
                else
                {
                    places.Add(scorename, new Place(level, percen, each.Score, radix, this.Count));
                }
            }
        }