PageRenderTime 19ms CodeModel.GetById 12ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://charts4j.googlecode.com/
Java | 99 lines | 59 code | 12 blank | 28 comment | 0 complexity | 39c3aeeb0d0c4660e0761ae1bf55d328 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 ScatterPlotTest {
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        final Data xData = Data.newData(0, 10, 20, 100);
67        final Data yData = Data.newData(0, 45, 10, 100);
68        final ScatterPlotData data = Plots.newScatterPlotData(xData, yData);
69        final GChart chart = GCharts.newScatterPlot(data);
70        Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString());
71        String expectedString = "http://chart.apis.google.com/chart?chd=e:AAGaMz..,AAczGa..&chm=o,000000,0,0,10,0&chs=200x125&cht=s";
72        assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString()));
73    }
74
75    @Test
76    public void test1() {
77        final Data xData = Data.newData(0, 10, 20, 100);
78        final Data yData = Data.newData(0, 45, 10, 100);
79        final ScatterPlotData data = Plots.newScatterPlotData(xData, yData);
80        data.addShapeMarkers(Shape.DIAMOND, BLUE, 20);
81        data.setPointSizes(Data.newData(100, 50, 100, 10));
82        final ScatterPlot chart = GCharts.newScatterPlot(data);
83        Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString());
84        String expectedString = "http://chart.apis.google.com/chart?chd=e:AAGaMz..,AAczGa..,..gA..Ga&chm=d,0000FF,0,-1,20,0&chs=200x125&cht=s";
85        assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString()));
86    }
87
88    @Test
89    public void test2() {
90        final Data xData = Data.newData(0, 10, 20, 100);
91        final Data yData = Data.newData(0, 45, 10, 100);
92        final ScatterPlotData data = Plots.newScatterPlotData(xData, yData);
93        data.addShapeMarker(Shape.DIAMOND, BLUE, 20,2);
94        final ScatterPlot chart = GCharts.newScatterPlot(data);
95        Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString());
96        String expectedString = "http://chart.apis.google.com/chart?chd=e:AAGaMz..,AAczGa..&chm=o,000000,0,0,10,0|d,0000FF,0,2,20,0&chs=200x125&cht=s";
97        assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString()));
98    }
99}