Package com.uphea.domain

Examples of com.uphea.domain.Answer


    }

    // update or save a vote
    if (userVote != null) {
      log.info("update vote {}", userVote.getId());
      Answer currentAnswer = question.lookupAnswerById(userVote.getAnswerId());
      if (currentAnswer.equals(userAnswer)) {
        log.debug("vote equals to previous one.");
        statsService.calcAnswerDistribution(question);
        return OK;
      }
      vote = answerService.changeVoteAnswer(userVote, currentAnswer, userAnswer, requestRemoteAddr);
View Full Code Here


    List<Answer> answers = question.getAnswers();
    for (int i = 0, answersSize = answers.size(); i < answersSize; i++) {
      if (i != 0) {
        json.append(',');
      }
      Answer answer = answers.get(i);
      json.append('"');
      json.append(answer.getText());
      json.append('"');
    }
    json.append(']');
    json.append('}');
View Full Code Here

public class StatsServiceTest {

  @Test
  public void calcAnswerDistribution1() {
    Answer a1 = new Answer();
    a1.setVotes(2);

    Answer a2 = new Answer();
    a2.setVotes(2);

    List<Answer> answers = new ArrayList<Answer>();
    answers.add(a1);
    answers.add(a2);

    StatsService statsService = new StatsService();
    statsService.calcAnswerDistribution(answers);

    Assert.assertEquals(5000, a1.getVotesPercent());
    Assert.assertEquals(5000, a2.getVotesPercent());
  }
View Full Code Here

    Assert.assertEquals(5000, a2.getVotesPercent());
  }

  @Test
  public void calcAnswerDistribution2() {
    Answer a1 = new Answer();
    a1.setVotes(2);

    Answer a2 = new Answer();
    a2.setVotes(1);

    List<Answer> answers = new ArrayList<Answer>();
    answers.add(a1);
    answers.add(a2);

    StatsService statsService = new StatsService();
    statsService.calcAnswerDistribution(answers);

    Assert.assertEquals(6667, a1.getVotesPercent());
    Assert.assertEquals(3333, a2.getVotesPercent());
  }
View Full Code Here

    Assert.assertEquals(3333, a2.getVotesPercent());
  }

  @Test
  public void calcAnswerDistribution3() {
    Answer a1 = new Answer();
    a1.setVotes(1342);

    Answer a2 = new Answer();
    a2.setVotes(1783);

    List<Answer> answers = new ArrayList<Answer>();
    answers.add(a1);
    answers.add(a2);

    StatsService statsService = new StatsService();
    statsService.calcAnswerDistribution(answers);

    Assert.assertEquals(4294, a1.getVotesPercent());
    Assert.assertEquals(5706, a2.getVotesPercent());
  }
View Full Code Here

    Assert.assertEquals(5706, a2.getVotesPercent());
  }

  @Test
  public void calcAnswerDistribution4() {
    Answer a1 = new Answer();
    a1.setVotes(0);

    Answer a2 = new Answer();
    a2.setVotes(1);

    Answer a3 = new Answer();
    a3.setVotes(4);

    Answer a4 = new Answer();
    a4.setVotes(1);

    List<Answer> answers = new ArrayList<Answer>();
    answers.add(a1);
    answers.add(a2);
    answers.add(a3);
    answers.add(a4);

    StatsService statsService = new StatsService();
    statsService.calcAnswerDistribution(answers);

    Assert.assertEquals(0, a1.getVotesPercent());
    Assert.assertEquals(1666, a2.getVotesPercent());
    Assert.assertEquals(6667, a3.getVotesPercent());
    Assert.assertEquals(1667, a4.getVotesPercent());
  }
View Full Code Here

TOP

Related Classes of com.uphea.domain.Answer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.