PageRenderTime 24ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

/src/test/java/com/googlecode/charts4j/XYLineChartTest.java

http://charts4j.googlecode.com/
Java | 116 lines | 71 code | 17 blank | 28 comment | 1 complexity | 96a4e62e19bc82aab25a9b95c40807cb MD5 | raw file
  1/**
  2 *
  3 * The MIT License
  4 *
  5 * Copyright (c) 2011 the original author or authors.
  6 *
  7 * Permission is hereby granted, free of charge, to any person obtaining a copy
  8 * of this software and associated documentation files (the "Software"), to deal
  9 * in the Software without restriction, including without limitation the rights
 10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 11 * copies of the Software, and to permit persons to whom the Software is
 12 * furnished to do so, subject to the following conditions:
 13
 14 * The above copyright notice and this permission notice shall be included in
 15 * all copies or substantial portions of the Software.
 16
 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 23 * THE SOFTWARE.
 24 */
 25
 26package com.googlecode.charts4j;
 27
 28import static com.googlecode.charts4j.Color.BLUE;
 29import static com.googlecode.charts4j.UrlUtil.normalize;
 30import static org.junit.Assert.assertEquals;
 31
 32import java.util.logging.Level;
 33import java.util.logging.Logger;
 34
 35import org.junit.After;
 36import org.junit.AfterClass;
 37import org.junit.Before;
 38import org.junit.BeforeClass;
 39import org.junit.Test;
 40
 41/**
 42 *
 43 * @author Julien Chastang (julien.c.chastang at gmail dot com)
 44 */
 45public class XYLineChartTest {
 46
 47    @BeforeClass
 48    public static void setUpBeforeClass() throws Exception {
 49        Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).setLevel(Level.ALL);
 50    }
 51
 52    @AfterClass
 53    public static void tearDownAfterClass() throws Exception {
 54    }
 55
 56    @Before
 57    public void setUp() throws Exception {
 58    }
 59
 60    @After
 61    public void tearDown() throws Exception {
 62    }
 63
 64    @Test
 65    public void test0() {
 66
 67        double[] x = new double[10];
 68        double[] y = new double[10];
 69        int cnt = 0;
 70        for (double i = 0; i < 10; i = i + 1) {
 71            x[cnt] = 50 + 49 * Math.sin(i / 18);
 72            y[cnt] = 50 + 49 * Math.cos(i / 20);
 73            cnt++;
 74        }
 75
 76        Data data1 = Data.newData(x);
 77        Data data2 = Data.newData(y);
 78        XYLine line = Plots.newXYLine(data1, data2);
 79        line.setColor(BLUE);
 80        XYLineChart chart = GCharts.newXYLineChart(line);
 81        chart.setSize(400, 400);
 82        Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString());
 83        String expectedString = "http://chart.apis.google.com/chart?cht=lxy&chco=0000FF&chs=400x400&chd=e:gAhvjelMm6omqQr4tevB,.W.U.M.A-u-Y989c848O";
 84        assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString()));
 85
 86    }
 87
 88    @Test
 89    public void testEvenlySpacedDataPoints() {
 90
 91        Data data1 = Data.newData(10, 11, 12, 50);
 92        Data data2 = Data.newData(30, 10, 30, 20);
 93        XYLine line = Plots.newXYLine(data1, data2);
 94        line.setColor(BLUE);
 95        XYLineChart chart = GCharts.newXYLineChart(line);
 96        chart.setSize(400, 400);
 97        Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString());
 98        String expectedString = "http://chart.apis.google.com/chart?cht=lxy&chco=0000FF&chs=400x400&chd=e:GaHCHrgA,TNGaTNMz";
 99        assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString()));
100    }
101
102    @Test
103    public void testLineStyle() {
104
105        Data data1 = Data.newData(10, 11, 12, 50);
106        Data data2 = Data.newData(30, 10, 30, 20);
107        XYLine line = Plots.newXYLine(data1, data2);
108        line.setLineStyle(LineStyle.MEDIUM_DOTTED_LINE);
109        line.setColor(BLUE);
110        XYLineChart chart = GCharts.newXYLineChart(line);
111        chart.setSize(400, 400);
112        Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString());
113        String expectedString = "http://chart.apis.google.com/chart?cht=lxy&chls=3,5,3&chco=0000FF&chs=400x400&chd=e:GaHCHrgA,TNGaTNMz";
114        assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString()));
115    }
116}