package uk.ac.ebi.quickgo.annotation.model;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

/**
 * Tests the behaviour of the {@link StatisticsByType} class.
 */
public class StatisticsByTypeTest {
    @Rule
    public ExpectedException thrown = ExpectedException.none();

    @Test
    public void nullTypeThrowsException() {
        String type = null;

        thrown.expect(IllegalArgumentException.class);
        thrown.expectMessage("Statistics type cannot be null or empty");

        new StatisticsByType(type, 0);
    }

    @Test
    public void emptyTypeThrowsException() {
        String type = "";

        thrown.expect(IllegalArgumentException.class);
        thrown.expectMessage("Statistics type cannot be null or empty");

        new StatisticsByType(type, 0);
    }

    @Test
    public void nullStatisticsValueThrowsException() {
        String type = "type";
        StatisticsValue value = null;

        thrown.expect(IllegalArgumentException.class);
        thrown.expectMessage("Stats value cannot be null");

        StatisticsByType statsType = new StatisticsByType(type, 0);
        statsType.addValue(value);
    }

    @Test
    public void addedStatisticsValueIsRetrievedCorrectly() {
        String type = "type";
        StatisticsByType statsType = new StatisticsByType(type, 12);

        assertThat(statsType.getDistinctValueCount(), is(12));
    }

    @Test
    public void addedStatisticsValueRoundedIfValueGreaterThan10K() {
        String type = "type";
        StatisticsByType statsType = new StatisticsByType(type, 10001);

        assertThat(statsType.getDistinctValueCount(), is(10000));
    }

    @Test
    public void addedStatisticsValueRoundedIfValueGreaterThan10KTest2() {
        String type = "type";
        StatisticsByType statsType = new StatisticsByType(type, 11999);

        assertThat(statsType.getDistinctValueCount(), is(11000));
    }

    @Test
    public void addedStatisticsValueRoundedIfValueGreaterThan100K() {
        String type = "type";
        StatisticsByType statsType = new StatisticsByType(type, 487934);

        assertThat(statsType.getDistinctValueCount(), is(487000));
    }

    @Test
    public void addedStatisticsValueRoundedIfValueGreaterThan1m() {
        String type = "type";
        StatisticsByType statsType = new StatisticsByType(type, 7487934);

        assertThat(statsType.getDistinctValueCount(), is(7487000));
    }
}

@@ -2018,17 +2018,17 @@
 (), is(1
-1
+2
 000));%0A 
@@ -2063,57 +2063,28 @@
 oid 
-addedStatisticsValueRoundedIfValueGreaterThan100K
+roundUpDistinctCount
 () %7B
@@ -2247,17 +2247,17 @@
 ), is(48
-7
+8
 000));%0A 
@@ -2292,42 +2292,258 @@
 oid 
-addedStatistics
+noNeedToRoundUpDistinctCount() %7B%0A        String type = %22type%22;%0A        StatisticsByType statsType = new StatisticsByType(type, 333434);%0A%0A        assertThat(statsType.getDistinct
 Value
-RoundedIfValue
+Count(), is(333000));%0A    %7D%0A%0A    @Test%0A    public void distinctCount
 Grea
@@ -2721,17 +2721,17 @@
 , is(748
-7
+8
 000));%0A 

Test for the rounded version of the truncated distinct value.