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(12000));
    }

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

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

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

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

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

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

@@ -948,26 +948,33 @@
 id n
-ullStatisticsValue
+egativeDistinctValueCount
 Thro
@@ -1022,46 +1022,8 @@
 pe%22;
-%0A        StatisticsValue value = null;
 %0A%0A  
@@ -1109,75 +1109,72 @@
 ge(%22
-Stats value cannot be null%22);%0A%0A        StatisticsByType statsType =
+Distinct Value Count should be be greater than zero.%22);%0A%0A       
  new
@@ -1201,47 +1201,14 @@
 pe, 
+-1
 0);%0A
-        statsType.addValue(value);%0A
     
@@ -1228,37 +1228,36 @@
     public void 
-added
+null
 StatisticsValueI
@@ -1259,28 +1259,23 @@
 alue
-IsRetrievedCorrectly
+ThrowsException
 () %7B
@@ -1297,32 +1297,187 @@
  type = %22type%22;%0A
+        StatisticsValue value = null;%0A%0A        thrown.expect(IllegalArgumentException.class);%0A        thrown.expectMessage(%22Stats value cannot be null%22);%0A%0A
         Statisti
@@ -1528,22 +1528,20 @@
 pe, 
-12
+0
 );%0A
-%0A
         
 asse
@@ -1540,60 +1540,32 @@
     
-assertThat(statsType.getDistinctValueCount(), is(12)
+statsType.addValue(value
 );%0A 
@@ -1600,55 +1600,33 @@
 oid 
-addedStat
+zeroD
 isti
-cs
+nct
 Value
-RoundedIfValueGreaterThan10
+CountIsO
 K() 
@@ -1725,13 +1725,9 @@
 pe, 
-10001
+0
 );%0A%0A
@@ -1787,12 +1787,8 @@
  is(
-1000
 0));
@@ -1825,61 +1825,47 @@
 oid 
-addedStat
+d
 isti
-cs
+nct
 Value
-RoundedIfValueGreaterThan10KTest2
+CountBelow10001IsUnchanged
 () %7B
@@ -1964,12 +1964,12 @@
 e, 1
-1999
+0000
 );%0A%0A
@@ -2030,9 +2030,9 @@
 is(1
-2
+0
 000)
@@ -2071,28 +2071,77 @@
 oid 
-roundUpDistinctCount
+distinctValueCountRoundedDownIfValueGreaterThan10KAndEndsWith101To499
 () %7B
@@ -2235,22 +2235,21 @@
 e(type, 
-487934
+10001
 );%0A%0A    
@@ -2301,19 +2301,18 @@
 t(), is(
-488
+10
 000));%0A 
@@ -2347,36 +2347,56 @@
 oid 
-noNeedToRoundUpDistinctCount
+distinctValueCountRoundedDownIfEndsWith499OrLess
 () %7B
@@ -2494,14 +2494,13 @@
 pe, 
-333434
+10499
 );%0A%0A
@@ -2560,11 +2560,10 @@
  is(
-333
+10
 000)
@@ -2610,26 +2610,49 @@
 inct
-Count
+ValueCountRoundedUpIfEndsWith500Or
 Greater
-Than1m
 () %7B
@@ -2750,15 +2750,13 @@
 pe, 
-7487934
+10500
 );%0A%0A
@@ -2816,12 +2816,10 @@
  is(
-7488
+11
 000)

Make the test names more explicit, test the boundary for rounding (where it starts, rounding up and rounding down).