    1   package baseCode.io.writer;
    2
    3   import hep.aida.ref.Histogram1D;
    4
    5   import java.io.IOException;
    6   import java.io.StringWriter;
    7   import java.io.Writer;
    8
    9   import junit.framework.TestCase;
    10  import baseCode.io.writer.HistogramWriter;
    11  import baseCode.util.RegressionTesting;
    12
    13  /***
    14   *
    15   *
    16   * <hr>
    17   * <p>
    18   * Copyright (c) 2004 Columbia University
    19   *
    20   * @author pavlidis
    21   * @version $Id: TestHistogramWriter.java,v 1.1 2005/03/17 13:58:43 pavlidis Exp $
    22   */
    23  public class TestHistogramWriter extends TestCase {
    24
    25     HistogramWriter w = new HistogramWriter();
    26     Histogram1D m = new Histogram1D( "test", 10, 1, 10 );
    27
    28     /*
    29      * @see TestCase#setUp()
    30      */
    31     protected void setUp() throws Exception {
    32        super.setUp();
    33        m.fill( 1.0 );
    34        m.fill( 1.0 );
    35        m.fill( 2.0 );
    36        m.fill( 1.0 );
    37        m.fill( 5.0 );
    38        m.fill( 11.0 );
    39        m.fill( 6.0 );
    40        m.fill( 6.0 );
    41        m.fill( 4.0 );
    42        m.fill( 4.0 );
    43        m.fill( 4.0 );
    44        m.fill( 4.0 );
    45
    46     }
    47
    48     /*
    49      * @see TestCase#tearDown()
    50      */
    51     protected void tearDown() throws Exception {
    52        super.tearDown();
    53     }
    54
    55     public final void testWriter() {
    56        String expectedReturn = "";
    57        String actualReturn = "";
    58        Writer k;
    59        try {
    60           k = new StringWriter();
    61           w.write( m, k );
    62           k.close();
    63           actualReturn = k.toString();
    64        } catch ( Exception e ) {
    65           e.printStackTrace();
    66        }
    67
    68        try {
    69           expectedReturn = RegressionTesting
    70                 .readTestResult( "/data/histogramwritertestoutput.txt" );
    71        } catch ( IOException e1 ) {
    72           e1.printStackTrace();
    73        }
    74
    75        assertEquals( "return value", expectedReturn, actualReturn );
    76     }
    77
    78  }