/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. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. * THE SOFTWARE.
  22. */
  23. package com.googlecode.charts4j;
  24. import static com.googlecode.charts4j.Color.BLUE;
  25. import static com.googlecode.charts4j.UrlUtil.normalize;
  26. import static org.junit.Assert.assertEquals;
  27. import java.util.logging.Level;
  28. import java.util.logging.Logger;
  29. import org.junit.After;
  30. import org.junit.AfterClass;
  31. import org.junit.Before;
  32. import org.junit.BeforeClass;
  33. import org.junit.Test;
  34. /**
  35. *
  36. * @author Julien Chastang (julien.c.chastang at gmail dot com)
  37. */
  38. public class ScatterPlotTest {
  39. @BeforeClass
  40. public static void setUpBeforeClass() throws Exception {
  41. Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).setLevel(Level.ALL);
  42. }
  43. @AfterClass
  44. public static void tearDownAfterClass() throws Exception {
  45. }
  46. @Before
  47. public void setUp() throws Exception {
  48. }
  49. @After
  50. public void tearDown() throws Exception {
  51. }
  52. @Test
  53. public void test0() {
  54. final Data xData = Data.newData(0, 10, 20, 100);
  55. final Data yData = Data.newData(0, 45, 10, 100);
  56. final ScatterPlotData data = Plots.newScatterPlotData(xData, yData);
  57. final GChart chart = GCharts.newScatterPlot(data);
  58. Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString());
  59. String expectedString = "http://chart.apis.google.com/chart?chd=e:AAGaMz..,AAczGa..&chm=o,000000,0,0,10,0&chs=200x125&cht=s";
  60. assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString()));
  61. }
  62. @Test
  63. public void test1() {
  64. final Data xData = Data.newData(0, 10, 20, 100);
  65. final Data yData = Data.newData(0, 45, 10, 100);
  66. final ScatterPlotData data = Plots.newScatterPlotData(xData, yData);
  67. data.addShapeMarkers(Shape.DIAMOND, BLUE, 20);
  68. data.setPointSizes(Data.newData(100, 50, 100, 10));
  69. final ScatterPlot 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..,..gA..Ga&chm=d,0000FF,0,-1,20,0&chs=200x125&cht=s";
  72. assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString()));
  73. }
  74. @Test
  75. public void test2() {
  76. final Data xData = Data.newData(0, 10, 20, 100);
  77. final Data yData = Data.newData(0, 45, 10, 100);
  78. final ScatterPlotData data = Plots.newScatterPlotData(xData, yData);
  79. data.addShapeMarker(Shape.DIAMOND, BLUE, 20,2);
  80. final ScatterPlot chart = GCharts.newScatterPlot(data);
  81. Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString());
  82. 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";
  83. assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString()));
  84. }
  85. }