/// <summary> /// Gets the percentage of entrants. /// </summary> /// <param name="answer"> /// The possible answer. /// </param> /// <returns> /// The percentage of entrants for a given answer. /// </returns> public decimal GetPercentageOfEntrants(CompetitionAnswer answer) { if (ValidEntrants.Any()) { return((decimal)ValidEntrants.Count(e => e.Answer == answer) / ValidEntrants.Count() * 100); } return(0); }
public void SetCompetitionAnswer(CompetitionAnswer answer) { var participant = answer.CompetitionParticipant; ParticipantNo.Text = participant.No.ToString(); RightCount.Text = participant.AnsweredCorrect.ToString(); WrongCount.Text = (participant.AnsweredIncorrect + participant.Unanswered).ToString(); Score.Text = answer.Score.ToString("0.#"); TotalScore.Text = participant.Score.ToString("0.#"); Rank.Text = participant.Rank.ToString(); }
/// <summary> /// Asserts the answer count. /// </summary> /// <param name="answer">The answer.</param> /// <param name="expectedCount">The expected count.</param> private static void AssertAnswerCount(CompetitionAnswer answer, int expectedCount) { // Arrange Competition competition = Stubs.StubCompetition(); // Act int count = competition.GetNumberOfEntrants(answer); // Assert Assert.AreEqual(expectedCount, count); }
/// <summary> /// Asserts the answer percentage. /// </summary> /// <param name="answer">The answer.</param> /// <param name="expectedPercentage">The expected percentage.</param> private static void AssertAnswerPercentage(CompetitionAnswer answer, decimal expectedPercentage) { // Arrange Competition competition = Stubs.StubCompetition(); // Act decimal percentage = competition.GetPercentageOfEntrants(answer); // Assert Assert.AreEqual(expectedPercentage, decimal.Round(percentage, 2)); }
/// <summary> /// Gets the percentage of entrants. /// </summary> /// <param name="answer"> /// The possible answer. /// </param> /// <returns> /// The percentage of entrants for a given answer. /// </returns> public decimal GetPercentageOfEntrants(CompetitionAnswer answer) { if (ValidEntrants.Any()) { return (decimal)ValidEntrants.Count(e => e.Answer == answer) / ValidEntrants.Count() * 100; } return 0; }
/// <summary> /// Gets the number of entrants. /// </summary> /// <param name="answer"> /// The answer. /// </param> /// <returns> /// The number of entrants for a given answer. /// </returns> public int GetNumberOfEntrants(CompetitionAnswer answer) { return ValidEntrants.Any() ? ValidEntrants.Count(e => e.Answer == answer) : 0; }
/// <summary> /// Initializes a new instance of the <see cref="PossibleAnswer" /> class. /// </summary> /// <param name="isCorrectAnswer">if set to <c>true</c> [is correct answer].</param> /// <param name="answerKey">The answer key.</param> /// <param name="answerText">The answer text.</param> public PossibleAnswer(bool isCorrectAnswer, CompetitionAnswer answerKey, string answerText) { IsCorrectAnswer = isCorrectAnswer; AnswerKey = answerKey; AnswerText = answerText; }
/// <summary> /// Initializes a new instance of the <see cref="PossibleAnswer" /> class. /// </summary> /// <param name="answerKey">The answer key.</param> public PossibleAnswer(CompetitionAnswer answerKey) { IsCorrectAnswer = false; AnswerKey = answerKey; AnswerText = string.Empty; }
/// <summary> /// Gets the number of entrants. /// </summary> /// <param name="answer"> /// The answer. /// </param> /// <returns> /// The number of entrants for a given answer. /// </returns> public int GetNumberOfEntrants(CompetitionAnswer answer) { return(ValidEntrants.Any() ? ValidEntrants.Count(e => e.Answer == answer) : 0); }
/// <summary> /// Adds the specified answer. /// </summary> /// <param name="answer"> /// The answer. /// </param> /// <param name="description"> /// The description. /// </param> /// <param name="isCorrectAnswer"> /// if set to <c>true</c> [is correct answer]. /// </param> public void Add(CompetitionAnswer answer, string description, bool isCorrectAnswer = false) { Add(new PossibleAnswer(isCorrectAnswer, answer, description)); }
/// <summary> /// Initializes a new instance of the <see cref="PossibleAnswer"/> class. /// </summary> /// <param name="answerKey"> /// The answer key. /// </param> public PossibleAnswer(CompetitionAnswer answerKey) { IsCorrectAnswer = false; AnswerKey = answerKey; AnswerText = string.Empty; }
/// <summary> /// Initializes a new instance of the <see cref="PossibleAnswer"/> class. /// </summary> /// <param name="isCorrectAnswer"> /// if set to <c>true</c> [is correct answer]. /// </param> /// <param name="answerKey"> /// The answer key. /// </param> /// <param name="answerText"> /// The answer text. /// </param> public PossibleAnswer(bool isCorrectAnswer, CompetitionAnswer answerKey, string answerText) { IsCorrectAnswer = isCorrectAnswer; AnswerKey = answerKey; AnswerText = answerText; }
/// <summary> /// Adds the specified answer. /// </summary> /// <param name="answer"> /// The answer. /// </param> /// <param name="description"> /// The description. /// </param> /// <param name="isCorrectAnswer"> /// if set to <c>true</c> [is correct answer]. /// </param> public void Add(CompetitionAnswer answer, string description, bool isCorrectAnswer = false) { Add(new PossibleAnswer(isCorrectAnswer, answer, description)); }