Esempio n. 1
0
        public void WordPointsCalculatorNullValueScore()
        {
            string word  = null;
            int    score = WordPointsCalculator.GetPoints(word);

            Assert.Equal(0, score);
        }
Esempio n. 2
0
        public void WordPointsCalculatorSevenLettersScore()
        {
            string word  = "abcdefg";
            int    score = WordPointsCalculator.GetPoints(word);

            Assert.Equal(5, score);
        }
Esempio n. 3
0
        public void WordPointsCalculatorNineLettersScore()
        {
            string word  = "abcdefghi";
            int    score = WordPointsCalculator.GetPoints(word);

            Assert.Equal(11, score);
        }
Esempio n. 4
0
        public void WordPointsCalculatorFiveLettersScore()
        {
            string word  = "abcde";
            int    score = WordPointsCalculator.GetPoints(word);

            Assert.Equal(2, score);
        }
Esempio n. 5
0
        public void WordPointsCalculatorThreeLettersScore()
        {
            string word  = "abc";
            int    score = WordPointsCalculator.GetPoints(word);

            Assert.Equal(1, score);
        }
Esempio n. 6
0
        public void WordPointsCalculatorOneLetterScore()
        {
            string word  = "a";
            int    score = WordPointsCalculator.GetPoints(word);

            Assert.Equal(0, score);
        }
Esempio n. 7
0
        public void WordPointsCalculatorEmptyValueScore()
        {
            string word  = string.Empty;
            int    score = WordPointsCalculator.GetPoints(word);

            Assert.Equal(0, score);
        }
Esempio n. 8
0
        /// <summary>
        /// Method calculates score for list of words based on words length.
        /// </summary>
        /// <param name="words"></param>
        /// <returns>Score represented in integer.</returns>
        public async Task <int> CalculateSingleScoreAsync(List <string> words)
        {
            if (words == null || words.Count == 0)
            {
                return(0);
            }

            // Remove duplicate words in list if any
            List <string> uniqueWords = words.Where(w => !string.IsNullOrWhiteSpace(w))
                                        .Select(w => w.Trim().ToLower())
                                        .Distinct()
                                        .ToList();
            int score = 0;

            uniqueWords.ForEach(word => score += WordPointsCalculator.GetPoints(word));
            return(score);
        }