View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.layout;
21  
22  import org.apache.myfaces.tobago.internal.layout.Interval;
23  import org.apache.myfaces.tobago.internal.layout.IntervalList;
24  import org.junit.Assert;
25  import org.junit.Test;
26  
27  import java.util.ArrayList;
28  
29  public class IntervalListUnitTest extends ArrayList<Interval> {
30  
31    /**
32     * nothing defined
33     */
34    @Test
35    public void test0() {
36      IntervalList list = new IntervalList();
37      list.evaluate();
38      Assert.assertEquals(Measure.ZERO, list.getCurrent());
39      Assert.assertEquals(Measure.ZERO, list.getMinimum());
40    }
41  
42    /**
43     * f=100
44     */
45    @Test
46    public void test1Fixed() {
47      IntervalList list = new IntervalList();
48      list.add(new Interval(null, null, null, px(100)));
49      list.evaluate();
50      Assert.assertEquals(px(100), list.getCurrent());
51      Assert.assertEquals(px(100), list.getMinimum());
52    }
53  
54    /**
55     * f=100
56     * f=200
57     * f=300
58     */
59    @Test
60    public void test3Fixed() {
61      IntervalList list = new IntervalList();
62      list.add(new Interval(null, null, null, px(100)));
63      list.add(new Interval(null, null, null, px(200)));
64      list.add(new Interval(null, null, null, px(300)));
65      list.evaluate();
66      Assert.assertEquals(px(300), list.getCurrent());
67      Assert.assertEquals(px(300), list.getMinimum());
68    }
69  
70    /**
71     * 10/100/1000
72     */
73    @Test
74    public void test1MinPrefMax() {
75      IntervalList list = new IntervalList();
76      list.add(new Interval(px(10), px(100), px(1000), null));
77      list.evaluate();
78      Assert.assertEquals(px(100), list.getCurrent());
79      Assert.assertEquals(px(10), list.getMinimum());
80    }
81  
82    /**
83     * 10/100/1000
84     * 20/200/2000
85     * 30/300/3000
86     */
87    @Test
88    public void test3MinPrefMax() {
89      IntervalList list = new IntervalList();
90      list.add(new Interval(px(10), px(100), px(1000), null));
91      list.add(new Interval(px(20), px(200), px(2000), null));
92      list.add(new Interval(px(30), px(300), px(3000), null));
93      list.evaluate();
94      Assert.assertEquals(px(300), list.getCurrent());
95      Assert.assertEquals(px(30), list.getMinimum());
96    }
97  
98    /**
99     * 10/100/1000
100    * 1000/10000/100000
101    */
102   @Test
103   public void test2MinPrefMax() {
104     IntervalList list = new IntervalList();
105     list.add(new Interval(px(10), px(100), px(1000), null));
106     list.add(new Interval(px(1000), px(10000), px(100000), null));
107     list.evaluate();
108     Assert.assertEquals(px(1000), list.getCurrent());
109     Assert.assertEquals(px(1000), list.getMinimum());
110   }
111 
112   /**
113    * 10/100/1000
114    * 2000/20000/200000
115    */
116   @Test
117   public void test4MinPrefMax() {
118     IntervalList list = new IntervalList();
119     list.add(new Interval(px(10), px(100), px(1000), null));
120     list.add(new Interval(px(2000), px(20000), px(200000), null));
121     list.evaluate();
122     Assert.assertEquals(px(2000), list.getCurrent());
123     Assert.assertEquals(px(2000), list.getMinimum());
124   }
125 
126   /**
127    * 10/./.
128    * ./200/.
129    * ././3000
130    */
131   @Test
132   public void test3MinPrefMaxWithGaps() {
133     IntervalList list = new IntervalList();
134     list.add(new Interval(px(10), null, null, null));
135     list.add(new Interval(null, px(200), null, null));
136     list.add(new Interval(null, null, px(3000), null));
137     list.evaluate();
138     Assert.assertEquals(px(200), list.getCurrent());
139     Assert.assertEquals(px(10), list.getMinimum());
140   }
141 
142   /**
143    * f=100
144    * f=200
145    * f=300
146    * 10/111/1000
147    * 20/222/2000
148    * 30/333/3000
149    */
150   @Test
151   public void test6Mixed() {
152     IntervalList list = new IntervalList();
153     list.add(new Interval(null, null, null, px(100)));
154     list.add(new Interval(null, null, null, px(200)));
155     list.add(new Interval(null, null, null, px(300)));
156     list.add(new Interval(px(10), px(111), px(1000), null));
157     list.add(new Interval(px(20), px(222), px(2000), null));
158     list.add(new Interval(px(30), px(333), px(3000), null));
159     list.evaluate();
160     Assert.assertEquals(px(333), list.getCurrent());
161     Assert.assertEquals(px(300), list.getMinimum());
162   }
163 
164   /**
165    * f=100
166    * f=200
167    * f=300
168    * 10/111/210
169    * 120/222/220
170    * 130/333/230
171    */
172   @Test
173   public void test6Squeeze() {
174     IntervalList list = new IntervalList();
175     list.add(new Interval(null, null, null, px(100)));
176     list.add(new Interval(null, null, null, px(200)));
177     list.add(new Interval(null, null, null, px(300)));
178     list.add(new Interval(px(10), px(111), px(210), null));
179     list.add(new Interval(px(120), px(222), px(220), null));
180     list.add(new Interval(px(130), px(333), px(230), null));
181     list.evaluate();
182     Assert.assertEquals(px(300), list.getCurrent());
183     Assert.assertEquals(px(300), list.getMinimum());
184   }
185 
186   /**
187    * f=100
188    * f=300
189    * 10/111/210
190    * 120/222/220
191    * 130/333/230
192    */
193   @Test
194   public void test5Squeeze() {
195     IntervalList list = new IntervalList();
196     list.add(new Interval(null, null, null, px(100)));
197     list.add(new Interval(null, null, null, px(300)));
198     list.add(new Interval(px(10), px(111), px(210), null));
199     list.add(new Interval(px(120), px(222), px(220), null));
200     list.add(new Interval(px(130), px(333), px(230), null));
201     list.evaluate();
202     Assert.assertEquals(px(300), list.getCurrent());
203     Assert.assertEquals(px(300), list.getMinimum());
204   }
205 
206   private Measure px(int pixel) {
207     return Measure.valueOf(pixel);
208   }
209 }