    1   package baseCode.math;
    2
    3   import java.util.HashMap;
    4   import java.util.Map;
    5
    6   import junit.framework.TestCase;
    7   import baseCode.math.Rank;
    8   import cern.colt.list.DoubleArrayList;
    9   import cern.colt.list.IntArrayList;
    10
    11  /***
    12   * Copyright (c) 2004 Columbia University
    13   *
    14   * @author Paul Pavlidis
    15   * @version $Id: TestRank.java,v 1.1 2005/03/17 13:58:41 pavlidis Exp $
    16   */
    17  public class TestRank extends TestCase {
    18
    19     DoubleArrayList testdata = null;
    20     Map testmap = null;
    21     Map testbadmap = null;
    22
    23     /*
    24      * @see TestCase#setUp()
    25      */
    26     protected void setUp() throws Exception {
    27        super.setUp();
    28        testdata = new DoubleArrayList( new double[] { 10.0, 11.0, 12.0, 13.0,
    29              114.0, 5.0 } );
    30        testmap = new HashMap();
    31        testmap.put( "Ten", new Double( 10.0 ) );
    32        testmap.put( "Eleven", new Double( 11.0 ) );
    33        testmap.put( "Twelve", new Double( 12.0 ) );
    34        testmap.put( "Thirteen", new Double( 13.0 ) );
    35        testmap.put( "HundredFourteen", new Double( 114.0 ) );
    36        testmap.put( "Five", new Double( 5.0 ) );
    37        testbadmap = new HashMap();
    38        testbadmap.put( "Ten", "I am not a Double" );
    39     }
    40
    41     /*
    42      * @see TestCase#tearDown()
    43      */
    44     protected void tearDown() throws Exception {
    45        super.tearDown();
    46        testdata = null;
    47        testmap = null;
    48        testbadmap = null;
    49     }
    50
    51     /*
    52      * Class under test for DoubleArrayList rankTransform(DoubleArrayList)
    53      */
    54     public void testRankTransformDoubleArrayList() {
    55        IntArrayList actualReturn = Rank.rankTransform( testdata );
    56        IntArrayList expectedReturn = new IntArrayList( new int[] { 1 ,
    57              2 , 3 , 4 , 5 , 0 } );
    58        assertEquals( "return value", expectedReturn, actualReturn );
    59     }
    60
    61     public void testRankTransformMap() {
    62
    63        Map actualReturn = Rank.rankTransform( testmap );
    64        Map expectedReturn = new HashMap();
    65        expectedReturn.put( "Ten", new Integer( 1 ) );
    66        expectedReturn.put( "Eleven", new Integer( 2 ) );
    67        expectedReturn.put( "Twelve", new Integer( 3 ) );
    68        expectedReturn.put( "Thirteen", new Integer( 4 ) );
    69        expectedReturn.put( "HundredFourteen", new Integer( 5 ) );
    70        expectedReturn.put( "Five", new Integer( 0 ) );
    71        assertEquals( "return value", expectedReturn, actualReturn );
    72
    73     } /*
    74        * Class under test for Map rankTransform(Map)
    75        */
    76
    77     public void testRankTransformBadMap() {
    78        try {
    79           Rank.rankTransform( testbadmap );
    80           fail( "Should have generated an exception" );
    81        } catch ( IllegalArgumentException success ) {
    82        }
    83     }
    84
    85  }