KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > block > junit > RectangleConstraintTests


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
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * -----------------------------
28  * RectangleConstraintTests.java
29  * -----------------------------
30  * (C) Copyright 2004, 2005, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: RectangleConstraintTests.java,v 1.1.2.1 2006/10/03 15:41:44 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 25-Oct-2004 : Version 1 (DG);
40  *
41  */

42
43 package org.jfree.chart.block.junit;
44
45 import junit.framework.Test;
46 import junit.framework.TestCase;
47 import junit.framework.TestSuite;
48
49 import org.jfree.chart.block.LengthConstraintType;
50 import org.jfree.chart.block.RectangleConstraint;
51 import org.jfree.data.Range;
52 import org.jfree.ui.Size2D;
53
54 /**
55  * Tests for the {@link RectangleConstraint} class.
56  */

57 public class RectangleConstraintTests extends TestCase {
58
59     private static final double EPSILON = 0.0000000001;
60     
61     /**
62      * Returns the tests as a test suite.
63      *
64      * @return The test suite.
65      */

66     public static Test suite() {
67         return new TestSuite(RectangleConstraintTests.class);
68     }
69
70     /**
71      * Constructs a new set of tests.
72      *
73      * @param name the name of the tests.
74      */

75     public RectangleConstraintTests(String JavaDoc name) {
76         super(name);
77     }
78     
79     /**
80      * Run some checks on the constrained size calculation.
81      */

82     public void testCalculateConstrainedSize() {
83         Size2D s;
84         
85         // NONE / NONE
86
RectangleConstraint c1 = RectangleConstraint.NONE;
87         s = c1.calculateConstrainedSize(new Size2D(1.2, 3.4));
88         assertEquals(s.width, 1.2, EPSILON);
89         assertEquals(s.height, 3.4, EPSILON);
90         
91         // NONE / RANGE
92
RectangleConstraint c2 = new RectangleConstraint(
93             0.0, new Range(0.0, 0.0), LengthConstraintType.NONE,
94             0.0, new Range(2.0, 3.0), LengthConstraintType.RANGE
95         );
96         s = c2.calculateConstrainedSize(new Size2D(1.2, 3.4));
97         assertEquals(s.width, 1.2, EPSILON);
98         assertEquals(s.height, 3.0, EPSILON);
99
100         // NONE / FIXED
101
RectangleConstraint c3 = new RectangleConstraint(
102             0.0, null, LengthConstraintType.NONE,
103             9.9, null, LengthConstraintType.FIXED
104         );
105         s = c3.calculateConstrainedSize(new Size2D(1.2, 3.4));
106         assertEquals(s.width, 1.2, EPSILON);
107         assertEquals(s.height, 9.9, EPSILON);
108
109         // RANGE / NONE
110
RectangleConstraint c4 = new RectangleConstraint(
111             0.0, new Range(2.0, 3.0), LengthConstraintType.RANGE,
112             0.0, new Range(0.0, 0.0), LengthConstraintType.NONE
113         );
114         s = c4.calculateConstrainedSize(new Size2D(1.2, 3.4));
115         assertEquals(s.width, 2.0, EPSILON);
116         assertEquals(s.height, 3.4, EPSILON);
117         
118         // RANGE / RANGE
119
RectangleConstraint c5 = new RectangleConstraint(
120             0.0, new Range(2.0, 3.0), LengthConstraintType.RANGE,
121             0.0, new Range(2.0, 3.0), LengthConstraintType.RANGE
122         );
123         s = c5.calculateConstrainedSize(new Size2D(1.2, 3.4));
124         assertEquals(s.width, 2.0, EPSILON);
125         assertEquals(s.height, 3.0, EPSILON);
126
127         // RANGE / FIXED
128
RectangleConstraint c6 = new RectangleConstraint(
129             0.0, null, LengthConstraintType.NONE,
130             9.9, null, LengthConstraintType.FIXED
131         );
132         s = c6.calculateConstrainedSize(new Size2D(1.2, 3.4));
133         assertEquals(s.width, 1.2, EPSILON);
134         assertEquals(s.height, 9.9, EPSILON);
135         
136         // FIXED / NONE
137
RectangleConstraint c7 = RectangleConstraint.NONE;
138         s = c7.calculateConstrainedSize(new Size2D(1.2, 3.4));
139         assertEquals(s.width, 1.2, EPSILON);
140         assertEquals(s.height, 3.4, EPSILON);
141         
142         // FIXED / RANGE
143
RectangleConstraint c8 = new RectangleConstraint(
144             0.0, new Range(0.0, 0.0), LengthConstraintType.NONE,
145             0.0, new Range(2.0, 3.0), LengthConstraintType.RANGE
146         );
147         s = c8.calculateConstrainedSize(new Size2D(1.2, 3.4));
148         assertEquals(s.width, 1.2, EPSILON);
149         assertEquals(s.height, 3.0, EPSILON);
150
151         // FIXED / FIXED
152
RectangleConstraint c9 = new RectangleConstraint(
153             0.0, null, LengthConstraintType.NONE,
154             9.9, null, LengthConstraintType.FIXED
155         );
156         s = c9.calculateConstrainedSize(new Size2D(1.2, 3.4));
157         assertEquals(s.width, 1.2, EPSILON);
158         assertEquals(s.height, 9.9, EPSILON);
159        
160     }
161 }
162
Popular Tags