package net.congstar.jira.plugins.scrumpoker.model;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import java.util.Arrays;

import org.junit.Test;

public class ScrumPokerSessionTest {

    @Test
    public void shouldShowTheDeckAfterRevealing() {
        ScrumPokerSession session = new ScrumPokerSession();

        session.updateCard("user1", "8");
        session.revealDeck();

        assertThat(session.isVisible(), is(true));
    }

    @Test
    public void shouldHideTheDeckAfterUpdatingCard() {
        ScrumPokerSession session = new ScrumPokerSession();

        session.updateCard("user1", "8");
        session.revealDeck();
        session.updateCard("user1", "5");

        assertThat(session.isVisible(), is(false));
    }

    @Test
    public void shouldNotRevealAnEmptyDeck() {
        ScrumPokerSession session = new ScrumPokerSession();

        session.revealDeck();

        assertThat(session.isVisible(), is(false));
    }

    @Test
    public void shouldAddCardIsUserHasNoCardYet() {
        ScrumPokerSession session = new ScrumPokerSession();

        session.updateCard("user1", "8");
        session.updateCard("user2", "3");

        assertThat(session.getCards().size(), is(2));
        assertThat(session.getCards().get("user1"), is("8"));
        assertThat(session.getCards().get("user2"), is("3"));
    }

    @Test
    public void shouldUpdateExistingCardForSameUser() {
        ScrumPokerSession session = new ScrumPokerSession();

        session.updateCard("user1", "8");
        session.updateCard("user1", "3");

        assertThat(session.getCards().size(), is(1));
        assertThat(session.getCards().get("user1"), is("3"));
    }

    @Test
    public void shouldClearAllCardsWhenResettingTheDeck() {
        ScrumPokerSession session = new ScrumPokerSession();

        session.updateCard("user1", "8");
        session.resetDeck();

        assertThat(session.getCards().size(), is(0));
    }

    @Test
    public void shouldCalculateMinimumAndMaximumWithSimpleListOfCards() {
        ScrumPokerSession session = new ScrumPokerSession();

        session.updateCard("user1", "8");
        session.updateCard("user2", "2");
        session.updateCard("user3", "13");

        assertThat(session.getMinimumVote(), is("2"));
        assertThat(session.getMaximumVote(), is("13"));
    }

    @Test
    public void shouldCalculateMinimumAndMaximumWithDuplicateCards() {
        ScrumPokerSession session = new ScrumPokerSession();

        session.updateCard("user1", "3");
        session.updateCard("user2", "3");
        session.updateCard("user3", "100");

        assertThat(session.getMinimumVote(), is("3"));
        assertThat(session.getMaximumVote(), is("100"));
    }

    @Test
    public void shouldCalculateMinimumAndMaximumIgnoringQuestionmark() {
        ScrumPokerSession session = new ScrumPokerSession();

        session.updateCard("user1", "8");
        session.updateCard("user2", "?");
        session.updateCard("user3", "3");

        assertThat(session.getMinimumVote(), is("3"));
        assertThat(session.getMaximumVote(), is("8"));
    }

    @Test
    public void shouldCalculateBoundedVotes() {
        ScrumPokerSession session = new ScrumPokerSession();

        session.updateCard("user1", "8");
        session.updateCard("user2", "?");
        session.updateCard("user3", "3");

        assertThat(session.getBoundedVotes(), is(equalTo(Arrays.asList("3", "5", "8"))));
    }

}

@@ -3252,16 +3252,30 @@
 dedVotes
+ForNormalRange
 () %7B%0A   
@@ -3557,10 +3557,737 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void shouldCalculateBoundedVotesForWideRange() %7B%0A        ScrumPokerSession session = new ScrumPokerSession();%0A%0A        session.updateCard(%22user1%22, %222%22);%0A        session.updateCard(%22user2%22, %22?%22);%0A        session.updateCard(%22user3%22, %2240%22);%0A%0A        assertThat(session.getBoundedVotes(), is(equalTo(Arrays.asList(%222%22, %223%22, %225%22, %228%22, %2213%22, %2220%22, %2240%22))));%0A    %7D%0A%0A    @Test%0A    public void shouldCalculateBoundedVotesForExactMatch() %7B%0A        ScrumPokerSession session = new ScrumPokerSession();%0A%0A        session.updateCard(%22user1%22, %222%22);%0A        session.updateCard(%22user2%22, %222%22);%0A        session.updateCard(%22user3%22, %222%22);%0A%0A        assertThat(session.getBoundedVotes(), is(equalTo(Arrays.asList(%222%22))));%0A    %7D%0A%0A
 %7D%0A

add test coverage for bounded votes