1. /* ===========================================================
  2. * JFreeChart : a free chart library for the Java(tm) platform
  3. * ===========================================================
  4. *
  5. * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
  6. *
  7. * Project Info: http://www.jfree.org/jfreechart/index.html
  8. *
  9. * This library is free software; you can redistribute it and/or modify it under the terms
  10. * of the GNU Lesser General Public License as published by the Free Software Foundation;
  11. * either version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  14. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License along with this
  18. * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. *
  21. * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  22. * in the United States and other countries.]
  23. *
  24. * ---------------------------------
  25. * BoxAndWhiskerCalculatorTests.java
  26. * ---------------------------------
  27. * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
  28. *
  29. * Original Author: David Gilbert (for Object Refinery Limited);
  30. * Contributor(s): -;
  31. *
  32. * $Id: BoxAndWhiskerCalculatorTests.java,v 1.3 2005/01/14 17:29:51 mungady Exp $
  33. *
  34. * Changes
  35. * -------
  36. * 28-Aug-2003 : Version 1 (DG);
  37. *
  38. */
  39. package org.jfree.data.statistics.junit;
  40. import java.util.ArrayList;
  41. import java.util.List;
  42. import junit.framework.Test;
  43. import junit.framework.TestCase;
  44. import junit.framework.TestSuite;
  45. import org.jfree.data.statistics.BoxAndWhiskerCalculator;
  46. /**
  47. * Tests for the {@link BoxAndWhiskerCalculator} class.
  48. */
  49. public class BoxAndWhiskerCalculatorTests extends TestCase {
  50. /**
  51. * Returns the tests as a test suite.
  52. *
  53. * @return The test suite.
  54. */
  55. public static Test suite() {
  56. return new TestSuite(BoxAndWhiskerCalculatorTests.class);
  57. }
  58. /**
  59. * Constructs a new set of tests.
  60. *
  61. * @param name the name of the tests.
  62. */
  63. public BoxAndWhiskerCalculatorTests(String name) {
  64. super(name);
  65. }
  66. private static final double EPSILON = 0.000000001;
  67. /**
  68. * Tests the Q1 calculation.
  69. */
  70. public void testCalculateQ1() {
  71. List values = new ArrayList();
  72. double q1 = BoxAndWhiskerCalculator.calculateQ1(values);
  73. assertTrue(Double.isNaN(q1));
  74. values.add(new Double(1.0));
  75. q1 = BoxAndWhiskerCalculator.calculateQ1(values);
  76. assertEquals(q1, 1.0, EPSILON);
  77. values.add(new Double(2.0));
  78. q1 = BoxAndWhiskerCalculator.calculateQ1(values);
  79. assertEquals(q1, 1.0, EPSILON);
  80. values.add(new Double(3.0));
  81. q1 = BoxAndWhiskerCalculator.calculateQ1(values);
  82. assertEquals(q1, 1.5, EPSILON);
  83. values.add(new Double(4.0));
  84. q1 = BoxAndWhiskerCalculator.calculateQ1(values);
  85. assertEquals(q1, 1.5, EPSILON);
  86. }
  87. /**
  88. * Tests the Q3 calculation.
  89. */
  90. public void testCalculateQ3() {
  91. List values = new ArrayList();
  92. double q3 = BoxAndWhiskerCalculator.calculateQ3(values);
  93. assertTrue(Double.isNaN(q3));
  94. values.add(new Double(1.0));
  95. q3 = BoxAndWhiskerCalculator.calculateQ3(values);
  96. assertEquals(q3, 1.0, EPSILON);
  97. values.add(new Double(2.0));
  98. q3 = BoxAndWhiskerCalculator.calculateQ3(values);
  99. assertEquals(q3, 2.0, EPSILON);
  100. values.add(new Double(3.0));
  101. q3 = BoxAndWhiskerCalculator.calculateQ3(values);
  102. assertEquals(q3, 2.5, EPSILON);
  103. values.add(new Double(4.0));
  104. q3 = BoxAndWhiskerCalculator.calculateQ3(values);
  105. assertEquals(q3, 3.5, EPSILON);
  106. }
  107. }