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.contains;
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";
        StatisticsValue value = new StatisticsValue("key", 0, 0);

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

        assertThat(statsType.getValues(), contains(value));
        assertThat(statsType.getDistinctValueCount(), is(12));
    }
}

@@ -1443,56 +1443,497 @@
 tics
-Value value = new StatisticsValue(%22key%22, 0, 0);%0A
+ByType statsType = new StatisticsByType(type,12);%0A%0A        assertThat(statsType.getDistinctValueCount(), is(12));%0A    %7D%0A%0A    @Test%0A    public void addedStatisticsValueRoundedIfValueGreaterThan10K() %7B%0A        String type = %22type%22;%0A        StatisticsByType statsType = new StatisticsByType(type, 10001);%0A%0A        assertThat(statsType.getDistinctValueCount(), is(10000));%0A    %7D%0A%0A    @Test%0A    public void addedStatisticsValueRoundedIfValueGreaterThan10KTest2() %7B%0A        String type = %22type%22;
 %0A   
@@ -1996,21 +1996,26 @@
 ype,
-12
+ 11999
 );%0A
+%0A
         
 stat
@@ -2014,96 +2014,514 @@
     
-statsType.addValue(value);%0A%0A        assertThat(statsType.getValues(), contains(value)
+assertThat(statsType.getDistinctValueCount(), is(11000));%0A    %7D%0A%0A    @Test%0A    public void addedStatisticsValueRoundedIfValueGreaterThan100K() %7B%0A        String type = %22type%22;%0A        StatisticsByType statsType = new StatisticsByType(type, 487934);%0A%0A        assertThat(statsType.getDistinctValueCount(), is(487000));%0A    %7D%0A%0A    @Test%0A    public void addedStatisticsValueRoundedIfValueGreaterThan1m() %7B%0A        String type = %22type%22;%0A        StatisticsByType statsType = new StatisticsByType(type, 7487934
 );%0A
+%0A
     
@@ -2565,30 +2565,35 @@
 alueCount(), is(
-12
+7487000
 ));%0A    %7D%0A%7D%0A

Test the truncation of distinct value count to tens of thousands, if bigger than 10,000