001    package org.hackystat.projectbrowser.page.projectportfolio.detailspanel.chart;
002    
003    import static org.junit.Assert.assertEquals;
004    import java.util.Arrays;
005    import java.util.List;
006    import org.junit.Test;
007    
008    /**
009     * Test cases for EnhancedStreamTrendClassifier.
010     * @author Shaoxuan Zhang
011     *
012     */
013    public class TestEnhancedStreamTrendClassifier {
014      /** the EnhancedStreamTrendClassifier. */
015      private StreamTrendClassifier streamTrendClassifier =
016        new StreamTrendClassifier(40, 90, true, true);
017      
018      private String testGranularity = "Day";
019      /**
020       * Test with a increasing stream with acceptable decreasing point.<p>
021       * example chart: 
022       * <img src="http://chart.apis.google.com/chart?chs=500x200&chd=t:55.0,67.0,66.5,78.8,76.0,89.0&
023       * chds=0.0,100.0&cht=lc&chls=2.0,1.0,0.0&chxt=y,x&chxr=0,0.0,100.0&chm=c,000000,0,-1.0,10.0"/>
024       */
025      @Test
026      public void testIncreaseTrend() {
027        List<Double> trend = Arrays.asList(new Double[]{55.0, 67.0, 66.5, 78.8, 76.0, 89.0});
028        MiniBarChart chart = new MiniBarChart(null, null, testGranularity);
029        chart.streamData = trend;
030        streamTrendClassifier.setHigherBetter(true);
031        assertEquals("", PortfolioCategory.GOOD, streamTrendClassifier.getStreamCategory(chart));
032        streamTrendClassifier.setHigherBetter(false);
033        assertEquals("", PortfolioCategory.POOR, streamTrendClassifier.getStreamCategory(chart));
034      }
035    
036      /**
037       * Test with a decreasing stream with acceptable increasing point. <p>
038       * example chart: 
039       * <img src="http://chart.apis.google.com/chart?chs=500x200&chd=t:89.0,76.0,78.8,66.5,67.0,55.0&
040       * chds=0.0,100.0&cht=lc&chls=2.0,1.0,0.0&chxt=y,x&chxr=0,0.0,100.0&chm=c,000000,0,-1.0,10.0"/>
041       */
042      @Test
043      public void testDecreaseTrend() {
044        List<Double> trend = Arrays.asList(new Double[]{89.0, 76.0, 78.8, 66.5, 67.0, 55.0});
045        MiniBarChart chart = new MiniBarChart(null, null, testGranularity);
046        chart.streamData = trend;
047        streamTrendClassifier.setHigherBetter(true);
048        assertEquals("", PortfolioCategory.POOR, streamTrendClassifier.getStreamCategory(chart));
049        streamTrendClassifier.setHigherBetter(false);
050        assertEquals("", PortfolioCategory.GOOD, streamTrendClassifier.getStreamCategory(chart));
051      }
052    
053      /**
054       * Test with a stable stream with acceptable vibration point.<p>
055       * example chart: 
056       * <img src="http://chart.apis.google.com/chart?chs=500x200&chd=t:65.0,67.0,66.5,68.8,66.0,69.0&
057       * chds=0.0,100.0&cht=lc&chls=2.0,1.0,0.0&chxt=y,x&chxr=0,0.0,100.0&chm=c,000000,0,-1.0,10.0"/>
058       */
059      @Test
060      public void testStableTrend() {
061        List<Double> trend = Arrays.asList(new Double[]{65.0, 67.0, 66.5, 68.8, 66.0, 69.0});
062        MiniBarChart chart = new MiniBarChart(null, null, testGranularity);
063        chart.streamData = trend;
064        assertEquals("", PortfolioCategory.GOOD, streamTrendClassifier.getStreamCategory(chart));
065      }
066    
067      /**
068       * Test with an unstable stream.<p>
069       * example chart: 
070       * <img src="http://chart.apis.google.com/chart?chs=500x200&chd=t:67.0,55.0,66.5,89.0,76.0,78.8&
071       * chds=0.0,100.0&cht=lc&chls=2.0,1.0,0.0&chxt=y,x&chxr=0,0.0,100.0&chm=c,000000,0,-1.0,10.0"/>
072       */
073      @Test
074      public void testUnstableTrend() {
075        List<Double> trend = Arrays.asList(new Double[]{67.0, 55.0, 66.5, 89.0, 76.0, 78.8});
076        MiniBarChart chart = new MiniBarChart(null, null, testGranularity);
077        chart.streamData = trend;
078        assertEquals("", PortfolioCategory.AVERAGE, streamTrendClassifier.getStreamCategory(chart));
079      }
080    }