001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * -----------------------------
028: * RectangleConstraintTests.java
029: * -----------------------------
030: * (C) Copyright 2004, 2005, by Object Refinery Limited and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: RectangleConstraintTests.java,v 1.1.2.1 2006/10/03 15:41:44 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 25-Oct-2004 : Version 1 (DG);
040: *
041: */
042:
043: package org.jfree.chart.block.junit;
044:
045: import junit.framework.Test;
046: import junit.framework.TestCase;
047: import junit.framework.TestSuite;
048:
049: import org.jfree.chart.block.LengthConstraintType;
050: import org.jfree.chart.block.RectangleConstraint;
051: import org.jfree.data.Range;
052: import org.jfree.ui.Size2D;
053:
054: /**
055: * Tests for the {@link RectangleConstraint} class.
056: */
057: public class RectangleConstraintTests extends TestCase {
058:
059: private static final double EPSILON = 0.0000000001;
060:
061: /**
062: * Returns the tests as a test suite.
063: *
064: * @return The test suite.
065: */
066: public static Test suite() {
067: return new TestSuite(RectangleConstraintTests.class);
068: }
069:
070: /**
071: * Constructs a new set of tests.
072: *
073: * @param name the name of the tests.
074: */
075: public RectangleConstraintTests(String name) {
076: super (name);
077: }
078:
079: /**
080: * Run some checks on the constrained size calculation.
081: */
082: public void testCalculateConstrainedSize() {
083: Size2D s;
084:
085: // NONE / NONE
086: RectangleConstraint c1 = RectangleConstraint.NONE;
087: s = c1.calculateConstrainedSize(new Size2D(1.2, 3.4));
088: assertEquals(s.width, 1.2, EPSILON);
089: assertEquals(s.height, 3.4, EPSILON);
090:
091: // NONE / RANGE
092: RectangleConstraint c2 = new RectangleConstraint(0.0,
093: new Range(0.0, 0.0), LengthConstraintType.NONE, 0.0,
094: new Range(2.0, 3.0), LengthConstraintType.RANGE);
095: s = c2.calculateConstrainedSize(new Size2D(1.2, 3.4));
096: assertEquals(s.width, 1.2, EPSILON);
097: assertEquals(s.height, 3.0, EPSILON);
098:
099: // NONE / FIXED
100: RectangleConstraint c3 = new RectangleConstraint(0.0, null,
101: LengthConstraintType.NONE, 9.9, null,
102: LengthConstraintType.FIXED);
103: s = c3.calculateConstrainedSize(new Size2D(1.2, 3.4));
104: assertEquals(s.width, 1.2, EPSILON);
105: assertEquals(s.height, 9.9, EPSILON);
106:
107: // RANGE / NONE
108: RectangleConstraint c4 = new RectangleConstraint(0.0,
109: new Range(2.0, 3.0), LengthConstraintType.RANGE, 0.0,
110: new Range(0.0, 0.0), LengthConstraintType.NONE);
111: s = c4.calculateConstrainedSize(new Size2D(1.2, 3.4));
112: assertEquals(s.width, 2.0, EPSILON);
113: assertEquals(s.height, 3.4, EPSILON);
114:
115: // RANGE / RANGE
116: RectangleConstraint c5 = new RectangleConstraint(0.0,
117: new Range(2.0, 3.0), LengthConstraintType.RANGE, 0.0,
118: new Range(2.0, 3.0), LengthConstraintType.RANGE);
119: s = c5.calculateConstrainedSize(new Size2D(1.2, 3.4));
120: assertEquals(s.width, 2.0, EPSILON);
121: assertEquals(s.height, 3.0, EPSILON);
122:
123: // RANGE / FIXED
124: RectangleConstraint c6 = new RectangleConstraint(0.0, null,
125: LengthConstraintType.NONE, 9.9, null,
126: LengthConstraintType.FIXED);
127: s = c6.calculateConstrainedSize(new Size2D(1.2, 3.4));
128: assertEquals(s.width, 1.2, EPSILON);
129: assertEquals(s.height, 9.9, EPSILON);
130:
131: // FIXED / NONE
132: RectangleConstraint c7 = RectangleConstraint.NONE;
133: s = c7.calculateConstrainedSize(new Size2D(1.2, 3.4));
134: assertEquals(s.width, 1.2, EPSILON);
135: assertEquals(s.height, 3.4, EPSILON);
136:
137: // FIXED / RANGE
138: RectangleConstraint c8 = new RectangleConstraint(0.0,
139: new Range(0.0, 0.0), LengthConstraintType.NONE, 0.0,
140: new Range(2.0, 3.0), LengthConstraintType.RANGE);
141: s = c8.calculateConstrainedSize(new Size2D(1.2, 3.4));
142: assertEquals(s.width, 1.2, EPSILON);
143: assertEquals(s.height, 3.0, EPSILON);
144:
145: // FIXED / FIXED
146: RectangleConstraint c9 = new RectangleConstraint(0.0, null,
147: LengthConstraintType.NONE, 9.9, null,
148: LengthConstraintType.FIXED);
149: s = c9.calculateConstrainedSize(new Size2D(1.2, 3.4));
150: assertEquals(s.width, 1.2, EPSILON);
151: assertEquals(s.height, 9.9, EPSILON);
152:
153: }
154: }
|