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.grid;
21  
22  import org.apache.myfaces.tobago.internal.layout.Grid;
23  import org.apache.myfaces.tobago.internal.layout.OriginCell;
24  import org.apache.myfaces.tobago.layout.LayoutTokens;
25  import org.apache.myfaces.tobago.layout.Orientation;
26  import org.junit.Assert;
27  import org.junit.Test;
28  
29  public class GridUnitTest {
30  
31    @Test
32    public void test1x1() {
33  
34      final Grid grid = new Grid(LayoutTokens.parse("*"), LayoutTokens.parse("*"));
35      Assert.assertEquals(1, grid.getBankHeads(Orientation.HORIZONTAL).length);
36      Assert.assertEquals(1, grid.getBankHeads(Orientation.VERTICAL).length);
37      Assert.assertEquals(""
38          + "┌─┐\n"
39          + "│◌│\n"
40          + "└─┘\n", grid.gridAsString());
41  
42      grid.add(new OriginCell(null), 1, 1);
43      Assert.assertEquals(1, grid.getBankHeads(Orientation.HORIZONTAL).length);
44      Assert.assertEquals(1, grid.getBankHeads(Orientation.VERTICAL).length);
45      Assert.assertEquals(""
46          + "┏━┓\n"
47          + "┃█┃\n"
48          + "┗━┛\n", grid.gridAsString());
49  
50      grid.add(new OriginCell(null), 1, 1);
51      Assert.assertEquals(1, grid.getBankHeads(Orientation.HORIZONTAL).length);
52      Assert.assertEquals(2, grid.getBankHeads(Orientation.VERTICAL).length);
53      Assert.assertEquals(""
54          + "┏━┓\n"
55          + "┃█┃\n"
56          + "┣━┫\n"
57          + "┃█┃\n"
58          + "┗━┛\n", grid.gridAsString());
59  
60      grid.add(new OriginCell(null), 1, 2);
61      Assert.assertEquals(1, grid.getBankHeads(Orientation.HORIZONTAL).length);
62      Assert.assertEquals(4, grid.getBankHeads(Orientation.VERTICAL).length);
63      Assert.assertEquals(""
64          + "┏━┓\n"
65          + "┃█┃\n"
66          + "┣━┫\n"
67          + "┃█┃\n"
68          + "┣━┫\n"
69          + "┃█┃\n"
70          + "┠─┨\n"
71          + "┃⬇┃\n"
72          + "┗━┛\n", grid.gridAsString());
73  
74      // with warning
75      grid.add(new OriginCell(null), 2, 1);
76      Assert.assertEquals(1, grid.getBankHeads(Orientation.HORIZONTAL).length);
77      Assert.assertEquals(5, grid.getBankHeads(Orientation.VERTICAL).length);
78      Assert.assertEquals(""
79          + "┏━┓\n"
80          + "┃█┃\n"
81          + "┣━┫\n"
82          + "┃█┃\n"
83          + "┣━┫\n"
84          + "┃█┃\n"
85          + "┠─┨\n"
86          + "┃⬇┃\n"
87          + "┣━┫\n"
88          + "┃✖┃\n"
89          + "┗━┛\n", grid.gridAsString());
90    }
91  
92    @Test
93    public void test2x1() {
94  
95      final Grid grid = new Grid(LayoutTokens.parse("*;*"), LayoutTokens.parse("*"));
96      Assert.assertEquals(2, grid.getBankHeads(Orientation.HORIZONTAL).length);
97      Assert.assertEquals(1, grid.getBankHeads(Orientation.VERTICAL).length);
98      Assert.assertEquals(""
99          + "┌─┬─┐\n"
100         + "│◌│◌│\n"
101         + "└─┴─┘\n", grid.gridAsString());
102 
103     grid.add(new OriginCell(null), 1, 1);
104     Assert.assertEquals(2, grid.getBankHeads(Orientation.HORIZONTAL).length);
105     Assert.assertEquals(1, grid.getBankHeads(Orientation.VERTICAL).length);
106     Assert.assertEquals(""
107         + "┏━┱─┐\n"
108         + "┃█┃◌│\n"
109         + "┗━┹─┘\n", grid.gridAsString());
110 
111     grid.add(new OriginCell(null), 1, 1);
112     Assert.assertEquals(2, grid.getBankHeads(Orientation.HORIZONTAL).length);
113     Assert.assertEquals(1, grid.getBankHeads(Orientation.VERTICAL).length);
114     Assert.assertEquals(""
115         + "┏━┳━┓\n"
116         + "┃█┃█┃\n"
117         + "┗━┻━┛\n", grid.gridAsString());
118 
119     grid.add(new OriginCell(null), 2, 2);
120     Assert.assertEquals(2, grid.getBankHeads(Orientation.HORIZONTAL).length);
121     Assert.assertEquals(3, grid.getBankHeads(Orientation.VERTICAL).length);
122     Assert.assertEquals(""
123         + "┏━┳━┓\n"
124         + "┃█┃█┃\n"
125         + "┣━╇━┫\n"
126         + "┃█│➞┃\n"
127         + "┠─┼─┨\n"
128         + "┃⬇│⬇┃\n"
129         + "┗━┷━┛\n", grid.gridAsString());
130 
131     grid.add(new OriginCell(null), 1, 2);
132     Assert.assertEquals(2, grid.getBankHeads(Orientation.HORIZONTAL).length);
133     Assert.assertEquals(5, grid.getBankHeads(Orientation.VERTICAL).length);
134     Assert.assertEquals(""
135         + "┏━┳━┓\n"
136         + "┃█┃█┃\n"
137         + "┣━╇━┫\n"
138         + "┃█│➞┃\n"
139         + "┠─┼─┨\n"
140         + "┃⬇│⬇┃\n"
141         + "┣━╈━┩\n"
142         + "┃█┃◌│\n"
143         + "┠─╂─┤\n"
144         + "┃⬇┃◌│\n"
145         + "┗━┹─┘\n", grid.gridAsString());
146 
147     grid.add(new OriginCell(null), 1, 1);
148     Assert.assertEquals(2, grid.getBankHeads(Orientation.HORIZONTAL).length);
149     Assert.assertEquals(5, grid.getBankHeads(Orientation.VERTICAL).length);
150     Assert.assertEquals(""
151         + "┏━┳━┓\n"
152         + "┃█┃█┃\n"
153         + "┣━╇━┫\n"
154         + "┃█│➞┃\n"
155         + "┠─┼─┨\n"
156         + "┃⬇│⬇┃\n"
157         + "┣━╈━┫\n"
158         + "┃█┃█┃\n"
159         + "┠─╊━┩\n"
160         + "┃⬇┃◌│\n"
161         + "┗━┹─┘\n", grid.gridAsString());
162 
163     grid.add(new OriginCell(null), 1, 2);
164     Assert.assertEquals(2, grid.getBankHeads(Orientation.HORIZONTAL).length);
165     Assert.assertEquals(6, grid.getBankHeads(Orientation.VERTICAL).length);
166     Assert.assertEquals(""
167         + "┏━┳━┓\n"
168         + "┃█┃█┃\n"
169         + "┣━╇━┫\n"
170         + "┃█│➞┃\n"
171         + "┠─┼─┨\n"
172         + "┃⬇│⬇┃\n"
173         + "┣━╈━┫\n"
174         + "┃█┃█┃\n"
175         + "┠─╊━┫\n"
176         + "┃⬇┃█┃\n"
177         + "┡━╉─┨\n"
178         + "│◌┃⬇┃\n"
179         + "└─┺━┛\n", grid.gridAsString());
180 
181     grid.add(new OriginCell(null), 2, 1);
182     // fehler
183     Assert.assertEquals(2, grid.getBankHeads(Orientation.HORIZONTAL).length);
184     Assert.assertEquals(6, grid.getBankHeads(Orientation.VERTICAL).length);
185   }
186 
187   @Test
188   public void test5x5() {
189 
190     final Grid grid = new Grid(LayoutTokens.parse("*;*;*;*;*"), LayoutTokens.parse("*;*;*;*;*"));
191     Assert.assertEquals(5, grid.getBankHeads(Orientation.HORIZONTAL).length);
192     Assert.assertEquals(5, grid.getBankHeads(Orientation.VERTICAL).length);
193     Assert.assertEquals(""
194         + "┌─┬─┬─┬─┬─┐\n"
195         + "│◌│◌│◌│◌│◌│\n"
196         + "├─┼─┼─┼─┼─┤\n"
197         + "│◌│◌│◌│◌│◌│\n"
198         + "├─┼─┼─┼─┼─┤\n"
199         + "│◌│◌│◌│◌│◌│\n"
200         + "├─┼─┼─┼─┼─┤\n"
201         + "│◌│◌│◌│◌│◌│\n"
202         + "├─┼─┼─┼─┼─┤\n"
203         + "│◌│◌│◌│◌│◌│\n"
204         + "└─┴─┴─┴─┴─┘\n", grid.gridAsString());
205 
206     grid.add(new OriginCell(null), 1, 2);
207     grid.add(new OriginCell(null), 1, 3);
208     grid.add(new OriginCell(null), 1, 1);
209     grid.add(new OriginCell(null), 2, 1);
210     grid.add(new OriginCell(null), 3, 1);
211     grid.add(new OriginCell(null), 1, 1);
212     grid.add(new OriginCell(null), 1, 1);
213     grid.add(new OriginCell(null), 1, 3);
214     grid.add(new OriginCell(null), 1, 1);
215     grid.add(new OriginCell(null), 3, 1);
216     grid.add(new OriginCell(null), 1, 2);
217     grid.add(new OriginCell(null), 2, 1);
218     grid.add(new OriginCell(null), 1, 1);
219     Assert.assertEquals(5, grid.getBankHeads(Orientation.HORIZONTAL).length);
220     Assert.assertEquals(5, grid.getBankHeads(Orientation.VERTICAL).length);
221     Assert.assertEquals(""
222         + "┏━┳━┳━┳━┯━┓\n"
223         + "┃█┃█┃█┃█│➞┃\n"
224         + "┠─╂─╊━╇━┿━┫\n"
225         + "┃⬇┃⬇┃█│➞│➞┃\n"
226         + "┣━╉─╊━╈━╈━┫\n"
227         + "┃█┃⬇┃█┃█┃█┃\n"
228         + "┣━╇━╇━╉─╊━┫\n"
229         + "┃█│➞│➞┃⬇┃█┃\n"
230         + "┣━┿━╈━╉─╂─┨\n"
231         + "┃█│➞┃█┃⬇┃⬇┃\n"
232         + "┗━┷━┻━┻━┻━┛\n", grid.gridAsString());
233   }
234 }
235 
236