/**
 * Copyright (C) 2012 Brookhaven National Laboratory
 * All rights reserved. Use is subject to license terms.
 */
package org.epics.graphene;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import junit.framework.AssertionFailedError;
import org.junit.AfterClass;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import org.junit.BeforeClass;
import static org.epics.graphene.ImageAssert.*;
import org.epics.util.array.ArrayDouble;
import org.epics.util.array.ListNumber;

/**
 *
 * @author carcassi
 */
public class Bar1DChartRendererTest {
    
    public Bar1DChartRendererTest() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }
    
    public static Statistics mockStatistics(Number min, Number max, double avg, double stdDev, int count) {
        Statistics stats = mock(Statistics.class);
        when(stats.getMinimum()).thenReturn(min);
        when(stats.getMaximum()).thenReturn(max);
        when(stats.getAverage()).thenReturn(avg);
        when(stats.getStdDev()).thenReturn(stdDev);
        when(stats.getCount()).thenReturn(count);
        return stats;
    }
    
    public static Cell1DDataset mockCell1DDataset(final ListNumber values, final ListNumber boundaries, final Statistics valueStats, final Range range, final int count) {
        return new Cell1DDataset() {

            @Override
            public double getValue(int x) {
                return values.getDouble(x);
            }

            @Override
            public Statistics getStatistics() {
                return valueStats;
            }

            @Override
            public ListNumber getXBoundaries() {
                return boundaries;
            }

            @Override
            public Range getXRange() {
                return range;
            }

            @Override
            public int getXCount() {
                return count;
            }
        };
    }
    
    @Test
    public void test1() throws Exception {
        Cell1DDataset dataset = mockCell1DDataset(new ArrayDouble(30, 14, 150, 160, 180, 230, 220, 350, 400, 450, 500,
                                        350, 230, 180, 220, 170, 130, 80, 30, 40), ListNumbers.linearRange(0, 2, 21),
                                        mockStatistics(0, 550, Double.NaN, Double.NaN, 21), RangeUtil.range(0.0, 2.0), 20);
        BufferedImage image = new BufferedImage(300, 200, BufferedImage.TYPE_3BYTE_BGR);
        Bar1DChartRenderer renderer = new Bar1DChartRenderer(300, 200);
        Graphics2D graphics = (Graphics2D) image.getGraphics();
        renderer.draw(graphics, dataset);
        compareImages("bar1DChart.1", image);
    }
//    
//    @Test
//    public void test2() throws Exception {
//        Histogram1D hist = new Hist1DT3();
//        BufferedImage image = new BufferedImage(300, 200, BufferedImage.TYPE_3BYTE_BGR);
//        Histogram1DRenderer renderer = new Histogram1DRenderer(300, 200);
//        Graphics2D graphics = (Graphics2D) image.getGraphics();
//        renderer.draw(graphics, hist);
//        compareImages("hist1D.3", image);
//    }
//    
//    @Test
//    public void test4() throws Exception {
//        Histogram1D hist = new Hist1DT4();
//        BufferedImage image = new BufferedImage(300, 200, BufferedImage.TYPE_3BYTE_BGR);
//        Histogram1DRenderer renderer = new Histogram1DRenderer(300, 200);
//        Graphics2D graphics = (Graphics2D) image.getGraphics();
//        renderer.draw(graphics, hist);
//        compareImages("hist1D.4", image);
//    }
//    
//    @Test
//    public void test5() throws Exception {
//        Histogram1D hist = new Hist1DT5();
//        BufferedImage image = new BufferedImage(300, 200, BufferedImage.TYPE_3BYTE_BGR);
//        Histogram1DRenderer renderer = new Histogram1DRenderer(300, 200);
//        Graphics2D graphics = (Graphics2D) image.getGraphics();
//        renderer.draw(graphics, hist);
//        compareImages("hist1D.5", image);
//    }
//    
//    @Test
//    public void test6() throws Exception {
//        Histogram1D hist = new Hist1DT6();
//        BufferedImage image = new BufferedImage(600, 200, BufferedImage.TYPE_3BYTE_BGR);
//        Histogram1DRenderer renderer = new Histogram1DRenderer(600, 200);
//        Graphics2D graphics = (Graphics2D) image.getGraphics();
//        renderer.draw(graphics, hist);
//        compareImages("hist1D.6", image);
//    }
//    

}

@@ -908,1298 +908,8 @@
   %0D%0A
-    public static Statistics mockStatistics(Number min, Number max, double avg, double stdDev, int count) %7B%0D%0A        Statistics stats = mock(Statistics.class);%0D%0A        when(stats.getMinimum()).thenReturn(min);%0D%0A        when(stats.getMaximum()).thenReturn(max);%0D%0A        when(stats.getAverage()).thenReturn(avg);%0D%0A        when(stats.getStdDev()).thenReturn(stdDev);%0D%0A        when(stats.getCount()).thenReturn(count);%0D%0A        return stats;%0D%0A    %7D%0D%0A    %0D%0A    public static Cell1DDataset mockCell1DDataset(final ListNumber values, final ListNumber boundaries, final Statistics valueStats, final Range range, final int count) %7B%0D%0A        return new Cell1DDataset() %7B%0D%0A%0D%0A            @Override%0D%0A            public double getValue(int x) %7B%0D%0A                return values.getDouble(x);%0D%0A            %7D%0D%0A%0D%0A            @Override%0D%0A            public Statistics getStatistics() %7B%0D%0A                return valueStats;%0D%0A            %7D%0D%0A%0D%0A            @Override%0D%0A            public ListNumber getXBoundaries() %7B%0D%0A                return boundaries;%0D%0A            %7D%0D%0A%0D%0A            @Override%0D%0A            public Range getXRange() %7B%0D%0A                return range;%0D%0A            %7D%0D%0A%0D%0A            @Override%0D%0A            public int getXCount() %7B%0D%0A                return count;%0D%0A            %7D%0D%0A        %7D;%0D%0A    %7D%0D%0A    %0D%0A
     
@@ -991,20 +991,16 @@
 taset = 
-mock
 Cell1DDa
@@ -1004,16 +1004,29 @@
 DDataset
+s.linearRange
 (new Arr
@@ -1175,165 +1175,12 @@
 0), 
-ListNumbers.linearRange(0, 2, 21),%0D%0A                                        mockStatistics(0, 550, Double.NaN, Double.NaN, 21), RangeUtil.range(0.0, 2.0), 20
+0, 2
 );%0D%0A
@@ -1338,24 +1338,122 @@
 300, 200);%0D%0A
+        renderer.update(new Bar1DChartRendererUpdate().yAxisRange(AxisRanges.absolute(0, 550)));%0D%0A
         Grap

test now uses a simpler dataset.