/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. * 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 XYLineChartTest {
  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. double[] x = new double[10];
  55. double[] y = new double[10];
  56. int cnt = 0;
  57. for (double i = 0; i < 10; i = i + 1) {
  58. x[cnt] = 50 + 49 * Math.sin(i / 18);
  59. y[cnt] = 50 + 49 * Math.cos(i / 20);
  60. cnt++;
  61. }
  62. Data data1 = Data.newData(x);
  63. Data data2 = Data.newData(y);
  64. XYLine line = Plots.newXYLine(data1, data2);
  65. line.setColor(BLUE);
  66. XYLineChart chart = GCharts.newXYLineChart(line);
  67. chart.setSize(400, 400);
  68. Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString());
  69. String expectedString = "http://chart.apis.google.com/chart?cht=lxy&chco=0000FF&chs=400x400&chd=e:gAhvjelMm6omqQr4tevB,.W.U.M.A-u-Y989c848O";
  70. assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString()));
  71. }
  72. @Test
  73. public void testEvenlySpacedDataPoints() {
  74. Data data1 = Data.newData(10, 11, 12, 50);
  75. Data data2 = Data.newData(30, 10, 30, 20);
  76. XYLine line = Plots.newXYLine(data1, data2);
  77. line.setColor(BLUE);
  78. XYLineChart chart = GCharts.newXYLineChart(line);
  79. chart.setSize(400, 400);
  80. Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString());
  81. String expectedString = "http://chart.apis.google.com/chart?cht=lxy&chco=0000FF&chs=400x400&chd=e:GaHCHrgA,TNGaTNMz";
  82. assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString()));
  83. }
  84. @Test
  85. public void testLineStyle() {
  86. Data data1 = Data.newData(10, 11, 12, 50);
  87. Data data2 = Data.newData(30, 10, 30, 20);
  88. XYLine line = Plots.newXYLine(data1, data2);
  89. line.setLineStyle(LineStyle.MEDIUM_DOTTED_LINE);
  90. line.setColor(BLUE);
  91. XYLineChart chart = GCharts.newXYLineChart(line);
  92. chart.setSize(400, 400);
  93. Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(chart.toURLString());
  94. String expectedString = "http://chart.apis.google.com/chart?cht=lxy&chls=3,5,3&chco=0000FF&chs=400x400&chd=e:GaHCHrgA,TNGaTNMz";
  95. assertEquals("Junit error", normalize(expectedString), normalize(chart.toURLString()));
  96. }
  97. }