package de.fuberlin.dynhist;

import org.junit.Before;
import org.junit.Test;

import java.util.List;

import static org.junit.Assert.assertEquals;

/**
 * @author Martin Görick
 */
public class CompressedHistogramImplTest {

  private double[] input;
  private CompressedHistogram histogram;

  @Before
  public void setUp() {
    input = new double[]{1.4,1.5,1.2,1.2,2.2,4.1,5.5,3.6,2.7,2.8,6,7.2};
    int buckets = 6;
    histogram = new CompressedHistogramImpl(buckets, 1);
  }

  @Test
  public void histogramTest() {
    for(double d : input) {
      histogram.addValue(d);
    }

    List<Bucket> hist = histogram.getHistogram();
    assertEquals(1.2, hist.get(0).getLeftBorder(), 0.1);
    assertEquals(1.23, hist.get(1).getLeftBorder(), 0.1);
    assertEquals(1.43, hist.get(2).getLeftBorder(), 0.1);
    assertEquals(1.61, hist.get(3).getLeftBorder(), 0.1);
    assertEquals(2.57, hist.get(4).getLeftBorder(), 0.1);
    assertEquals(2.8, hist.get(5).getLeftBorder(), 0.1);

    for (Bucket bucket : hist) {
      assertEquals(2 , bucket.getCount());
    }
  }
}

@@ -470,11 +470,8 @@
 kets
-, 1
 );%0A 
@@ -708,10 +708,9 @@
 s(1.
-23
+4
 , hi
@@ -821,12 +821,11 @@
 als(
-1.61
+2.2
 , hi
@@ -878,12 +878,11 @@
 als(
-2.57
+4.1
 , hi
@@ -931,19 +931,19 @@
 tEquals(
-2.8
+5.5
 , hist.g
@@ -980,39 +980,188 @@
     
-for (Bucket bucket : hist) %7B%0A  
+assertEquals(2 , hist.get(0).getCount());%0A    assertEquals(1 , hist.get(1).getCount());%0A    assertEquals(1 , hist.get(2).getCount());%0A    assertEquals(4 , hist.get(3).getCount());%0A
     
@@ -1177,18 +1177,23 @@
 als(
-2 , bucket
+1 , hist.get(4)
 .get
@@ -1206,16 +1206,56 @@
 ));%0A    
-%7D
+assertEquals(3 , hist.get(5).getCount());
 %0A  %7D%0A%7D%0A

remove partition