Save This Page
Home » jcommon-1.0.13 » org.jfree » chart » block » junit » [javadoc | source]
    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 
   10    * under the terms of the GNU Lesser General Public License as published by 
   11    * the Free Software Foundation; either version 2.1 of the License, or 
   12    * (at your option) any later version.
   13    *
   14    * This library is distributed in the hope that it will be useful, but 
   15    * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
   16    * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
   17    * License for more details.
   18    *
   19    * You should have received a copy of the GNU Lesser General Public License 
   20    * along with this library; if not, write to the Free Software Foundation, 
   21    * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
   22    *
   23    * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
   24    * in the United States and other countries.]
   25    *
   26    * ---------------------------
   27    * BorderArrangementTests.java
   28    * ---------------------------
   29    * (C) Copyright 2004, 2005, by Object Refinery Limited and Contributors.
   30    *
   31    * Original Author:  David Gilbert (for Object Refinery Limited);
   32    * Contributor(s):   -;
   33    *
   34    * $Id: BorderArrangementTests.java,v 1.7 2005/05/13 15:16:39 mungady Exp $
   35    *
   36    * Changes
   37    * -------
   38    * 22-Oct-2004 : Version 1 (DG);
   39    *
   40    */
   41   
   42   package org.jfree.chart.block.junit;
   43   
   44   import java.awt.Graphics2D;
   45   import java.awt.image.BufferedImage;
   46   import java.io.ByteArrayInputStream;
   47   import java.io.ByteArrayOutputStream;
   48   import java.io.ObjectInput;
   49   import java.io.ObjectInputStream;
   50   import java.io.ObjectOutput;
   51   import java.io.ObjectOutputStream;
   52   
   53   import junit.framework.Test;
   54   import junit.framework.TestCase;
   55   import junit.framework.TestSuite;
   56   
   57   import org.jfree.chart.block.Block;
   58   import org.jfree.chart.block.BlockContainer;
   59   import org.jfree.chart.block.BorderArrangement;
   60   import org.jfree.chart.block.EmptyBlock;
   61   import org.jfree.chart.block.LengthConstraintType;
   62   import org.jfree.chart.block.RectangleConstraint;
   63   import org.jfree.data.Range;
   64   import org.jfree.ui.RectangleEdge;
   65   import org.jfree.ui.Size2D;
   66   
   67   /**
   68    * Tests for the {@link BorderArrangement} class.
   69    */
   70   public class BorderArrangementTests extends TestCase {
   71   
   72       private static final double EPSILON = 0.0000000001;
   73       
   74       /**
   75        * Returns the tests as a test suite.
   76        *
   77        * @return The test suite.
   78        */
   79       public static Test suite() {
   80           return new TestSuite(BorderArrangementTests.class);
   81       }
   82   
   83       /**
   84        * Constructs a new set of tests.
   85        *
   86        * @param name  the name of the tests.
   87        */
   88       public BorderArrangementTests(String name) {
   89           super(name);
   90       }
   91       
   92       /**
   93        * Confirm that the equals() method can distinguish all the required fields.
   94        */
   95       public void testEquals() {
   96           BorderArrangement b1 = new BorderArrangement();
   97           BorderArrangement b2 = new BorderArrangement();
   98           assertTrue(b1.equals(b2));
   99           assertTrue(b2.equals(b1));
  100   
  101           b1.add(new EmptyBlock(99.0, 99.0), null);
  102           assertFalse(b1.equals(b2));
  103           b2.add(new EmptyBlock(99.0, 99.0), null);
  104           assertTrue(b1.equals(b2));
  105   
  106           b1.add(new EmptyBlock(1.0, 1.0), RectangleEdge.LEFT);
  107           assertFalse(b1.equals(b2));
  108           b2.add(new EmptyBlock(1.0, 1.0), RectangleEdge.LEFT);
  109           assertTrue(b1.equals(b2));
  110   
  111           b1.add(new EmptyBlock(2.0, 2.0), RectangleEdge.RIGHT);
  112           assertFalse(b1.equals(b2));
  113           b2.add(new EmptyBlock(2.0, 2.0), RectangleEdge.RIGHT);
  114           assertTrue(b1.equals(b2));
  115   
  116           b1.add(new EmptyBlock(3.0, 3.0), RectangleEdge.TOP);
  117           assertFalse(b1.equals(b2));
  118           b2.add(new EmptyBlock(3.0, 3.0), RectangleEdge.TOP);
  119           assertTrue(b1.equals(b2));
  120   
  121           b1.add(new EmptyBlock(4.0, 4.0), RectangleEdge.BOTTOM);
  122           assertFalse(b1.equals(b2));
  123           b2.add(new EmptyBlock(4.0, 4.0), RectangleEdge.BOTTOM);
  124           assertTrue(b1.equals(b2));
  125       }
  126   
  127       /**
  128        * Immutable - cloning is not necessary.
  129        */
  130       public void testCloning() {
  131           BorderArrangement b1 = new BorderArrangement();
  132           assertFalse(b1 instanceof Cloneable);
  133       }
  134   
  135       /**
  136        * Serialize an instance, restore it, and check for equality.
  137        */
  138       public void testSerialization() {
  139           BorderArrangement b1 = new BorderArrangement();
  140           BorderArrangement b2 = null;
  141           try {
  142               ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  143               ObjectOutput out = new ObjectOutputStream(buffer);
  144               out.writeObject(b1);
  145               out.close();
  146   
  147               ObjectInput in = new ObjectInputStream(
  148                   new ByteArrayInputStream(buffer.toByteArray())
  149               );
  150               b2 = (BorderArrangement) in.readObject();
  151               in.close();
  152           }
  153           catch (Exception e) {
  154               fail(e.toString());
  155           }
  156           assertEquals(b1, b2);
  157       }
  158       
  159       /**
  160        * Run some checks on sizing.
  161        */
  162       public void testSizing() {
  163           BlockContainer container = new BlockContainer(new BorderArrangement());
  164           BufferedImage image = new BufferedImage(
  165               200, 100, BufferedImage.TYPE_INT_RGB
  166           );
  167           Graphics2D g2 = image.createGraphics();
  168           
  169           // TBLRC
  170           // 00000 - no items
  171           Size2D size = container.arrange(g2);
  172           assertEquals(0.0, size.width, EPSILON);
  173           assertEquals(0.0, size.height, EPSILON);
  174           
  175           // TBLRC
  176           // 00001 - center item only
  177           container.add(new EmptyBlock(123.4, 567.8));
  178           size = container.arrange(g2);
  179           assertEquals(123.4, size.width, EPSILON);
  180           assertEquals(567.8, size.height, EPSILON);
  181   
  182           // TBLRC
  183           // 00010 - right item only
  184           container.clear();
  185           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.RIGHT);
  186           size = container.arrange(g2);
  187           assertEquals(12.3, size.width, EPSILON);
  188           assertEquals(45.6, size.height, EPSILON);
  189           
  190           // TBLRC
  191           // 00011 - right and center items
  192           container.clear();
  193           container.add(new EmptyBlock(10.0, 20.0));
  194           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.RIGHT);
  195           size = container.arrange(g2);
  196           assertEquals(22.3, size.width, EPSILON);
  197           assertEquals(45.6, size.height, EPSILON);
  198           
  199           // try case where right item is shorter than center item
  200           container.clear();
  201           Block rb = new EmptyBlock(12.3, 15.6);
  202           container.add(new EmptyBlock(10.0, 20.0));
  203           container.add(rb, RectangleEdge.RIGHT);
  204           size = container.arrange(g2);
  205           assertEquals(22.3, size.width, EPSILON);
  206           assertEquals(20.0, size.height, EPSILON);
  207           assertEquals(20.0, rb.getBounds().getHeight(), EPSILON);
  208   
  209           // TBLRC
  210           // 00100 - left item only
  211           container.clear();
  212           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
  213           size = container.arrange(g2);
  214           assertEquals(12.3, size.width, EPSILON);
  215           assertEquals(45.6, size.height, EPSILON);
  216           
  217           // TBLRC
  218           // 00101 - left and center items
  219           container.clear();
  220           container.add(new EmptyBlock(10.0, 20.0));
  221           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
  222           size = container.arrange(g2);
  223           assertEquals(22.3, size.width, EPSILON);
  224           assertEquals(45.6, size.height, EPSILON);
  225           
  226           // try case where left item is shorter than center item
  227           container.clear();
  228           Block lb = new EmptyBlock(12.3, 15.6);
  229           container.add(new EmptyBlock(10.0, 20.0));
  230           container.add(lb, RectangleEdge.LEFT);
  231           size = container.arrange(g2);
  232           assertEquals(22.3, size.width, EPSILON);
  233           assertEquals(20.0, size.height, EPSILON);
  234           assertEquals(20.0, lb.getBounds().getHeight(), EPSILON);
  235           
  236           // TBLRC
  237           // 00110 - left and right items
  238           container.clear();
  239           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
  240           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
  241           size = container.arrange(g2);
  242           assertEquals(22.3, size.width, EPSILON);
  243           assertEquals(45.6, size.height, EPSILON);
  244           
  245           // TBLRC
  246           // 00111 - left, right and center items
  247           container.clear();
  248           container.add(new EmptyBlock(10.0, 20.0));
  249           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
  250           container.add(new EmptyBlock(5.4, 3.2), RectangleEdge.RIGHT);
  251           size = container.arrange(g2);
  252           assertEquals(27.7, size.width, EPSILON);
  253           assertEquals(45.6, size.height, EPSILON);
  254           
  255           // TBLRC
  256           // 01000 - bottom item only
  257           container.clear();
  258           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
  259           size = container.arrange(g2);
  260           assertEquals(12.3, size.width, EPSILON);
  261           assertEquals(45.6, size.height, EPSILON);
  262           
  263           // TBLRC
  264           // 01001 - bottom and center only
  265           container.clear();
  266           container.add(new EmptyBlock(10.0, 20.0));
  267           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
  268           size = container.arrange(g2);
  269           assertEquals(12.3, size.width, EPSILON);
  270           assertEquals(65.6, size.height, EPSILON);
  271           
  272           // TBLRC
  273           // 01010 - bottom and right only
  274           container.clear();
  275           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
  276           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
  277           size = container.arrange(g2);
  278           assertEquals(12.3, size.width, EPSILON);
  279           assertEquals(65.6, size.height, EPSILON);
  280           
  281           // TBLRC
  282           // 01011 - bottom, right and center
  283           container.clear();
  284           container.add(new EmptyBlock(21.0, 12.3));
  285           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
  286           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
  287           size = container.arrange(g2);
  288           assertEquals(31.0, size.width, EPSILON);
  289           assertEquals(65.6, size.height, EPSILON);
  290           
  291           // TBLRC
  292           // 01100
  293           container.clear();
  294           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
  295           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
  296           size = container.arrange(g2);
  297           assertEquals(12.3, size.width, EPSILON);
  298           assertEquals(65.6, size.height, EPSILON);
  299           
  300           // TBLRC
  301           // 01101 - bottom, left and center
  302           container.clear();
  303           container.add(new EmptyBlock(21.0, 12.3));
  304           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
  305           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
  306           size = container.arrange(g2);
  307           assertEquals(31.0, size.width, EPSILON);
  308           assertEquals(65.6, size.height, EPSILON);
  309           
  310           // TBLRC
  311           // 01110 - bottom. left and right
  312           container.clear();
  313           container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.RIGHT);
  314           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
  315           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
  316           size = container.arrange(g2);
  317           assertEquals(31.0, size.width, EPSILON);
  318           assertEquals(65.6, size.height, EPSILON);
  319           
  320           // TBLRC
  321           // 01111
  322           container.clear();
  323           container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
  324           container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
  325           container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
  326           container.add(new EmptyBlock(9.0, 10.0));
  327           size = container.arrange(g2);
  328           assertEquals(21.0, size.width, EPSILON);
  329           assertEquals(14.0, size.height, EPSILON);
  330           
  331           // TBLRC
  332           // 10000 - top item only
  333           container.clear();
  334           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
  335           size = container.arrange(g2);
  336           assertEquals(12.3, size.width, EPSILON);
  337           assertEquals(45.6, size.height, EPSILON);
  338           
  339           // TBLRC
  340           // 10001 - top and center only
  341           container.clear();
  342           container.add(new EmptyBlock(10.0, 20.0));
  343           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
  344           size = container.arrange(g2);
  345           assertEquals(12.3, size.width, EPSILON);
  346           assertEquals(65.6, size.height, EPSILON);
  347                   
  348           // TBLRC
  349           // 10010 - right and top only
  350           container.clear();
  351           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
  352           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
  353           size = container.arrange(g2);
  354           assertEquals(12.3, size.width, EPSILON);
  355           assertEquals(65.6, size.height, EPSILON);
  356           
  357           // TBLRC
  358           // 10011 - top, right and center
  359           container.clear();
  360           container.add(new EmptyBlock(21.0, 12.3));
  361           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
  362           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.RIGHT);
  363           size = container.arrange(g2);
  364           assertEquals(33.3, size.width, EPSILON);
  365           assertEquals(65.6, size.height, EPSILON);
  366   
  367           // TBLRC
  368           // 10100 - top and left only
  369           container.clear();
  370           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
  371           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
  372           size = container.arrange(g2);
  373           assertEquals(12.3, size.width, EPSILON);
  374           assertEquals(65.6, size.height, EPSILON);
  375           
  376           // TBLRC
  377           // 10101 - top, left and center
  378           container.clear();
  379           container.add(new EmptyBlock(21.0, 12.3));
  380           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
  381           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
  382           size = container.arrange(g2);
  383           assertEquals(33.3, size.width, EPSILON);
  384           assertEquals(65.6, size.height, EPSILON);
  385           
  386           // TBLRC
  387           // 10110 - top, left and right
  388           container.clear();
  389           container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.RIGHT);
  390           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
  391           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
  392           size = container.arrange(g2);
  393           assertEquals(33.3, size.width, EPSILON);
  394           assertEquals(65.6, size.height, EPSILON);
  395           
  396           // TBLRC
  397           // 10111
  398           container.clear();
  399           container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
  400           container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
  401           container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
  402           container.add(new EmptyBlock(9.0, 10.0));
  403           size = container.arrange(g2);
  404           assertEquals(21.0, size.width, EPSILON);
  405           assertEquals(12.0, size.height, EPSILON);
  406   
  407           // TBLRC
  408           // 11000 - top and bottom only
  409           container.clear();
  410           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
  411           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
  412           size = container.arrange(g2);
  413           assertEquals(12.3, size.width, EPSILON);
  414           assertEquals(65.6, size.height, EPSILON);
  415           
  416           // TBLRC
  417           // 11001
  418           container.clear();
  419           container.add(new EmptyBlock(21.0, 12.3));
  420           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
  421           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
  422           size = container.arrange(g2);
  423           assertEquals(21.0, size.width, EPSILON);
  424           assertEquals(77.9, size.height, EPSILON);
  425           
  426           // TBLRC
  427           // 11010 - top, bottom and right
  428           container.clear();
  429           container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.RIGHT);
  430           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
  431           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
  432           size = container.arrange(g2);
  433           assertEquals(21.0, size.width, EPSILON);
  434           assertEquals(77.9, size.height, EPSILON);
  435                   
  436           // TBLRC
  437           // 11011
  438           container.clear();
  439           container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
  440           container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
  441           container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
  442           container.add(new EmptyBlock(9.0, 10.0));
  443           size = container.arrange(g2);
  444           assertEquals(16.0, size.width, EPSILON);
  445           assertEquals(16.0, size.height, EPSILON);
  446           
  447           // TBLRC
  448           // 11100
  449           container.clear();
  450           container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.LEFT);
  451           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
  452           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
  453           size = container.arrange(g2);
  454           assertEquals(21.0, size.width, EPSILON);
  455           assertEquals(77.9, size.height, EPSILON);
  456   
  457           // TBLRC
  458           // 11101
  459           container.clear();
  460           container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
  461           container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
  462           container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
  463           container.add(new EmptyBlock(9.0, 10.0));
  464           size = container.arrange(g2);
  465           assertEquals(14.0, size.width, EPSILON);
  466           assertEquals(16.0, size.height, EPSILON);
  467           
  468           // TBLRC
  469           // 11110
  470           container.clear();
  471           container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
  472           container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
  473           container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
  474           container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
  475           size = container.arrange(g2);
  476           assertEquals(12.0, size.width, EPSILON);
  477           assertEquals(14.0, size.height, EPSILON);
  478           
  479           // TBLRC
  480           // 11111 - all
  481           container.clear();
  482           container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
  483           container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
  484           container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
  485           container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
  486           container.add(new EmptyBlock(9.0, 10.0));
  487           size = container.arrange(g2);
  488           assertEquals(21.0, size.width, EPSILON);
  489           assertEquals(16.0, size.height, EPSILON);
  490   
  491       }
  492       
  493       /**
  494        * Run some checks on sizing when there is a fixed width constraint.
  495        */
  496       public void testSizingWithWidthConstraint() {
  497           RectangleConstraint constraint = new RectangleConstraint(
  498               10.0, new Range(10.0, 10.0), LengthConstraintType.FIXED,
  499               0.0, new Range(0.0, 0.0), LengthConstraintType.NONE
  500           );
  501                   
  502           BlockContainer container = new BlockContainer(new BorderArrangement());
  503           BufferedImage image = new BufferedImage(
  504               200, 100, BufferedImage.TYPE_INT_RGB
  505           );
  506           Graphics2D g2 = image.createGraphics();
  507           
  508           // TBLRC
  509           // 00001 - center item only
  510           container.add(new EmptyBlock(5.0, 6.0));
  511           Size2D size = container.arrange(g2, constraint);
  512           assertEquals(10.0, size.width, EPSILON);
  513           assertEquals(6.0, size.height, EPSILON);
  514           
  515           container.clear();
  516           container.add(new EmptyBlock(15.0, 16.0));
  517           size = container.arrange(g2, constraint);
  518           assertEquals(10.0, size.width, EPSILON);
  519           assertEquals(16.0, size.height, EPSILON);
  520   
  521           // TBLRC
  522           // 00010 - right item only
  523           container.clear();
  524           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.RIGHT);
  525           size = container.arrange(g2, constraint);
  526           assertEquals(10.0, size.width, EPSILON);
  527           assertEquals(45.6, size.height, EPSILON);
  528           
  529           // TBLRC
  530           // 00011 - right and center items
  531           container.clear();
  532           container.add(new EmptyBlock(7.0, 20.0));
  533           container.add(new EmptyBlock(8.0, 45.6), RectangleEdge.RIGHT);
  534           size = container.arrange(g2, constraint);
  535           assertEquals(10.0, size.width, EPSILON);
  536           assertEquals(45.6, size.height, EPSILON);
  537           
  538           // TBLRC
  539           // 00100 - left item only
  540           container.clear();
  541           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
  542           size = container.arrange(g2, constraint);
  543           assertEquals(10.0, size.width, EPSILON);
  544           assertEquals(45.6, size.height, EPSILON);
  545           
  546           // TBLRC
  547           // 00101 - left and center items
  548           container.clear();
  549           container.add(new EmptyBlock(10.0, 20.0));
  550           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
  551           size = container.arrange(g2, constraint);
  552           assertEquals(10.0, size.width, EPSILON);
  553           assertEquals(45.6, size.height, EPSILON);
  554           
  555           // TBLRC
  556           // 00110 - left and right items
  557           container.clear();
  558           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
  559           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
  560           size = container.arrange(g2, constraint);
  561           assertEquals(10.0, size.width, EPSILON);
  562           assertEquals(45.6, size.height, EPSILON);
  563           
  564           // TBLRC
  565           // 00111 - left, right and center items
  566           container.clear();
  567           container.add(new EmptyBlock(10.0, 20.0));
  568           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
  569           container.add(new EmptyBlock(5.4, 3.2), RectangleEdge.RIGHT);
  570           size = container.arrange(g2, constraint);
  571           assertEquals(10.0, size.width, EPSILON);
  572           assertEquals(45.6, size.height, EPSILON);
  573           
  574           // TBLRC
  575           // 01000 - bottom item only
  576           container.clear();
  577           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
  578           size = container.arrange(g2, constraint);
  579           assertEquals(10.0, size.width, EPSILON);
  580           assertEquals(45.6, size.height, EPSILON);
  581           
  582           // TBLRC
  583           // 01001 - bottom and center only
  584           container.clear();
  585           container.add(new EmptyBlock(10.0, 20.0));
  586           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
  587           size = container.arrange(g2, constraint);
  588           assertEquals(10.0, size.width, EPSILON);
  589           assertEquals(65.6, size.height, EPSILON);
  590           
  591           // TBLRC
  592           // 01010 - bottom and right only
  593           container.clear();
  594           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
  595           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
  596           size = container.arrange(g2, constraint);
  597           assertEquals(10.0, size.width, EPSILON);
  598           assertEquals(65.6, size.height, EPSILON);
  599           
  600           // TBLRC
  601           // 01011 - bottom, right and center
  602           container.clear();
  603           container.add(new EmptyBlock(21.0, 12.3));
  604           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
  605           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
  606           size = container.arrange(g2, constraint);
  607           assertEquals(10.0, size.width, EPSILON);
  608           assertEquals(65.6, size.height, EPSILON);
  609           
  610           // TBLRC
  611           // 01100
  612           container.clear();
  613           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
  614           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
  615           size = container.arrange(g2, constraint);
  616           assertEquals(10.0, size.width, EPSILON);
  617           assertEquals(65.6, size.height, EPSILON);
  618           
  619           // TBLRC
  620           // 01101 - bottom, left and center
  621           container.clear();
  622           container.add(new EmptyBlock(21.0, 12.3));
  623           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
  624           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
  625           size = container.arrange(g2, constraint);
  626           assertEquals(10.0, size.width, EPSILON);
  627           assertEquals(65.6, size.height, EPSILON);
  628           
  629           // TBLRC
  630           // 01110 - bottom. left and right
  631           container.clear();
  632           container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.RIGHT);
  633           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
  634           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
  635           size = container.arrange(g2, constraint);
  636           assertEquals(10.0, size.width, EPSILON);
  637           assertEquals(65.6, size.height, EPSILON);
  638           
  639           // TBLRC
  640           // 01111
  641           container.clear();
  642           container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
  643           container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
  644           container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
  645           container.add(new EmptyBlock(9.0, 10.0));
  646           size = container.arrange(g2, constraint);
  647           assertEquals(10.0, size.width, EPSILON);
  648           assertEquals(14.0, size.height, EPSILON);
  649           
  650           // TBLRC
  651           // 10000 - top item only
  652           container.clear();
  653           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
  654           size = container.arrange(g2, constraint);
  655           assertEquals(10.0, size.width, EPSILON);
  656           assertEquals(45.6, size.height, EPSILON);
  657           
  658           // TBLRC
  659           // 10001 - top and center only
  660           container.clear();
  661           container.add(new EmptyBlock(10.0, 20.0));
  662           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
  663           size = container.arrange(g2, constraint);
  664           assertEquals(10.0, size.width, EPSILON);
  665           assertEquals(65.6, size.height, EPSILON);
  666                   
  667           // TBLRC
  668           // 10010 - right and top only
  669           container.clear();
  670           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
  671           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
  672           size = container.arrange(g2, constraint);
  673           assertEquals(10.0, size.width, EPSILON);
  674           assertEquals(65.6, size.height, EPSILON);
  675           
  676           // TBLRC
  677           // 10011 - top, right and center
  678           container.clear();
  679           container.add(new EmptyBlock(21.0, 12.3));
  680           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
  681           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.RIGHT);
  682           size = container.arrange(g2, constraint);
  683           assertEquals(10.0, size.width, EPSILON);
  684           assertEquals(65.6, size.height, EPSILON);
  685   
  686           // TBLRC
  687           // 10100 - top and left only
  688           container.clear();
  689           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
  690           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
  691           size = container.arrange(g2, constraint);
  692           assertEquals(10.0, size.width, EPSILON);
  693           assertEquals(65.6, size.height, EPSILON);
  694           
  695           // TBLRC
  696           // 10101 - top, left and center
  697           container.clear();
  698           container.add(new EmptyBlock(21.0, 12.3));
  699           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
  700           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
  701           size = container.arrange(g2, constraint);
  702           assertEquals(10.0, size.width, EPSILON);
  703           assertEquals(65.6, size.height, EPSILON);
  704           
  705           // TBLRC
  706           // 10110 - top, left and right
  707           container.clear();
  708           container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.RIGHT);
  709           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
  710           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
  711           size = container.arrange(g2, constraint);
  712           assertEquals(10.0, size.width, EPSILON);
  713           assertEquals(65.6, size.height, EPSILON);
  714           
  715           // TBLRC
  716           // 10111
  717           container.clear();
  718           container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
  719           container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
  720           container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
  721           container.add(new EmptyBlock(9.0, 10.0));
  722           size = container.arrange(g2, constraint);
  723           assertEquals(10.0, size.width, EPSILON);
  724           assertEquals(12.0, size.height, EPSILON);
  725   
  726           // TBLRC
  727           // 11000 - top and bottom only
  728           container.clear();
  729           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
  730           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
  731           size = container.arrange(g2, constraint);
  732           assertEquals(10.0, size.width, EPSILON);
  733           assertEquals(65.6, size.height, EPSILON);
  734           
  735           // TBLRC
  736           // 11001
  737           container.clear();
  738           container.add(new EmptyBlock(21.0, 12.3));
  739           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
  740           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
  741           size = container.arrange(g2, constraint);
  742           assertEquals(10.0, size.width, EPSILON);
  743           assertEquals(77.9, size.height, EPSILON);
  744           
  745           // TBLRC
  746           // 11010 - top, bottom and right
  747           container.clear();
  748           container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.RIGHT);
  749           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
  750           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
  751           size = container.arrange(g2, constraint);
  752           assertEquals(10.0, size.width, EPSILON);
  753           assertEquals(77.9, size.height, EPSILON);
  754                   
  755           // TBLRC
  756           // 11011
  757           container.clear();
  758           container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
  759           container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
  760           container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
  761           container.add(new EmptyBlock(9.0, 10.0));
  762           size = container.arrange(g2, constraint);
  763           assertEquals(10.0, size.width, EPSILON);
  764           assertEquals(16.0, size.height, EPSILON);
  765           
  766           // TBLRC
  767           // 11100
  768           container.clear();
  769           container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.LEFT);
  770           container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
  771           container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
  772           size = container.arrange(g2, constraint);
  773           assertEquals(10.0, size.width, EPSILON);
  774           assertEquals(77.9, size.height, EPSILON);
  775   
  776           // TBLRC
  777           // 11101
  778           container.clear();
  779           container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
  780           container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
  781           container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
  782           container.add(new EmptyBlock(9.0, 10.0));
  783           size = container.arrange(g2, constraint);
  784           assertEquals(10.0, size.width, EPSILON);
  785           assertEquals(16.0, size.height, EPSILON);
  786           
  787           // TBLRC
  788           // 11110
  789           container.clear();
  790           container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
  791           container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
  792           container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
  793           container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
  794           size = container.arrange(g2, constraint);
  795           assertEquals(10.0, size.width, EPSILON);
  796           assertEquals(14.0, size.height, EPSILON);
  797           
  798           // TBLRC
  799           // 11111 - all
  800           container.clear();
  801           container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
  802           container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
  803           container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
  804           container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
  805           container.add(new EmptyBlock(9.0, 10.0));
  806           size = container.arrange(g2, constraint);
  807           assertEquals(10.0, size.width, EPSILON);
  808           assertEquals(16.0, size.height, EPSILON);
  809   
  810           // TBLRC
  811           // 00000 - no items
  812           container.clear();
  813           size = container.arrange(g2, constraint);
  814           assertEquals(10.0, size.width, EPSILON);
  815           assertEquals(0.0, size.height, EPSILON);
  816           
  817       }
  818   }
  819   

Save This Page
Home » jcommon-1.0.13 » org.jfree » chart » block » junit » [javadoc | source]