1 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 57 public class RectangleConstraintTests extends TestCase { 58 59 private static final double EPSILON = 0.0000000001; 60 61 66 public static Test suite() { 67 return new TestSuite(RectangleConstraintTests.class); 68 } 69 70 75 public RectangleConstraintTests(String name) { 76 super(name); 77 } 78 79 82 public void testCalculateConstrainedSize() { 83 Size2D s; 84 85 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 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 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 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 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 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 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 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 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 |