|
34 | 34 | import static org.junit.Assert.assertEquals; |
35 | 35 | import static org.junit.Assert.assertSame; |
36 | 36 |
|
| 37 | +import java.util.List; |
| 38 | + |
37 | 39 | import org.junit.Test; |
38 | 40 |
|
39 | 41 | /** |
@@ -133,6 +135,78 @@ public void testInsertColumn() { |
133 | 135 | checkTableModifiedColumn(table, values, 1); |
134 | 136 | } |
135 | 137 |
|
| 138 | + @Test |
| 139 | + public void testAppendColumns() { |
| 140 | + final BoolTable table = createTable(); |
| 141 | + final boolean[][] values = |
| 142 | + { |
| 143 | + { true, true, true, true, false, true, false, true }, |
| 144 | + { true, false, true, false, false, true, false, true }, |
| 145 | + { false, true, true, true, false, true, false, false }, |
| 146 | + { true, false, false, true, false, false, false, true } }; |
| 147 | + |
| 148 | + final String[] headers = { "Header4", "Header5", "Header6", "Header7" }; |
| 149 | + final List<BoolColumn> col = table.appendColumns(headers); |
| 150 | + col.get(0).fill(values[0]); |
| 151 | + col.get(1).fill(values[1]); |
| 152 | + col.get(2).fill(values[2]); |
| 153 | + col.get(3).fill(values[3]); |
| 154 | + |
| 155 | + // Test appending a column |
| 156 | + assertEquals(table.getColumnCount(), 7); |
| 157 | + assertEquals(table.get(3).getHeader(), "Header4"); |
| 158 | + assertEquals(table.get(4).getHeader(), "Header5"); |
| 159 | + assertEquals(table.get(5).getHeader(), "Header6"); |
| 160 | + assertEquals(table.get(6).getHeader(), "Header7"); |
| 161 | + |
| 162 | + checkTableModifiedColumns(table, values, 3, 6); |
| 163 | + } |
| 164 | + |
| 165 | + @Test |
| 166 | + public void testRemoveColumns() { |
| 167 | + final BoolTable table = createTable(); |
| 168 | + |
| 169 | + final List<BoolColumn> col = table.removeColumns(1, 2); |
| 170 | + |
| 171 | + // Test removing a column |
| 172 | + for (int q = 0; q < col.size(); q++) { |
| 173 | + for (int i = 0; i < col.get(0).size(); i++) { |
| 174 | + assertEquals(col.get(q).getValue(i), DATA[i][q + 1]); |
| 175 | + } |
| 176 | + } |
| 177 | + assertEquals(table.getColumnCount(), 1); |
| 178 | + |
| 179 | + checkTableModifiedColumns(table, null, 1, 3); |
| 180 | + } |
| 181 | + |
| 182 | + @Test |
| 183 | + public void testInsertColumns() { |
| 184 | + final BoolTable table = createTable(); |
| 185 | + final boolean[][] values = |
| 186 | + { |
| 187 | + { true, true, true, true, false, true, false, true }, |
| 188 | + { true, false, true, false, false, true, false, true }, |
| 189 | + { false, true, true, true, false, true, false, false }, |
| 190 | + { true, false, false, true, false, false, false, true } }; |
| 191 | + |
| 192 | + |
| 193 | + final String[] headers = { "Header4", "Header5", "Header6", "Header7" }; |
| 194 | + final List<BoolColumn> col = table.insertColumns(0, headers); |
| 195 | + col.get(0).fill(values[0]); |
| 196 | + col.get(1).fill(values[1]); |
| 197 | + col.get(2).fill(values[2]); |
| 198 | + col.get(3).fill(values[3]); |
| 199 | + |
| 200 | + // Test appending a column |
| 201 | + assertEquals(table.getColumnCount(), 7); |
| 202 | + assertEquals(table.get(0).getHeader(), "Header4"); |
| 203 | + assertEquals(table.get(1).getHeader(), "Header5"); |
| 204 | + assertEquals(table.get(2).getHeader(), "Header6"); |
| 205 | + assertEquals(table.get(3).getHeader(), "Header7"); |
| 206 | + |
| 207 | + checkTableModifiedColumns(table, values, 0, 3); |
| 208 | + } |
| 209 | + |
136 | 210 | @Test |
137 | 211 | public void testAppendRow() { |
138 | 212 | final BoolTable table = createTable(); |
@@ -178,6 +252,55 @@ public void testInsertRow() { |
178 | 252 | checkTableModifiedRow(table, values, 6); |
179 | 253 | } |
180 | 254 |
|
| 255 | + @Test |
| 256 | + public void testAppendRows() { |
| 257 | + final BoolTable table = createTable(); |
| 258 | + final boolean[][] values = |
| 259 | + { { true, true, false }, { false, true, false }, { true, false, true }, |
| 260 | + { true, false, false }, { false, false, false } }; |
| 261 | + |
| 262 | + // Test appending a row |
| 263 | + table.appendRows(5); |
| 264 | + assertEquals(table.getRowCount(), 13); |
| 265 | + for (int r = 0; r < values.length; r++) { |
| 266 | + for (int c = 0; c < values[0].length; c++) { |
| 267 | + table.setValue(c, r + 8, values[r][c]); |
| 268 | + assertEquals(table.getValue(c, r + 8), values[r][c]); |
| 269 | + } |
| 270 | + } |
| 271 | + |
| 272 | + checkTableModifiedRows(table, values, 8, 12); |
| 273 | + } |
| 274 | + |
| 275 | + @Test |
| 276 | + public void testRemoveRows() { |
| 277 | + final BoolTable table = createTable(); |
| 278 | + table.removeRows(4, 3); |
| 279 | + assertEquals(table.getRowCount(), 5); |
| 280 | + |
| 281 | + checkTableModifiedRows(table, null, 4, 6); |
| 282 | + } |
| 283 | + |
| 284 | + @Test |
| 285 | + public void testInsertRows() { |
| 286 | + final BoolTable table = createTable(); |
| 287 | + final boolean[][] values = |
| 288 | + { { true, true, false }, { false, true, false }, { true, false, true }, |
| 289 | + { true, false, false }, { false, false, false } }; |
| 290 | + |
| 291 | + table.insertRows(5, 5); |
| 292 | + |
| 293 | + assertEquals(table.getRowCount(), 13); |
| 294 | + for (int r = 0; r < values.length; r++) { |
| 295 | + for (int c = 0; c < values[0].length; c++) { |
| 296 | + table.setValue(c, r + 5, values[r][c]); |
| 297 | + assertEquals(table.getValue(c, r + 5), values[r][c]); |
| 298 | + } |
| 299 | + } |
| 300 | + |
| 301 | + checkTableModifiedRows(table, values, 5, 9); |
| 302 | + } |
| 303 | + |
181 | 304 | // TODO - Add more tests. |
182 | 305 |
|
183 | 306 | // -- Helper methods -- |
@@ -240,4 +363,47 @@ else if ( r >= mod && values == null ) { |
240 | 363 | } |
241 | 364 | } |
242 | 365 |
|
| 366 | + private void checkTableModifiedColumns(final BoolTable table, |
| 367 | + final boolean[][] values, final int startMod, final int endMod) |
| 368 | + { |
| 369 | + for (int r = 0; r < table.getRowCount(); r++) { |
| 370 | + for (int c = 0; c < table.getColumnCount(); c++) { |
| 371 | + if (c >= startMod && c <= endMod && values != null) { |
| 372 | + assertEquals(table.getValue(c, r), values[c - startMod][r]); |
| 373 | + } |
| 374 | + else if (c > endMod && values != null) { |
| 375 | + assertEquals(table.getValue(c, r), DATA[r][c - values.length]); |
| 376 | + } |
| 377 | + else if (c >= startMod && values == null) { |
| 378 | + assertEquals(table.getValue(c, r), DATA[r][c + (endMod - startMod)]); |
| 379 | + } |
| 380 | + else { |
| 381 | + assertEquals(table.getValue(c, r), DATA[r][c]); |
| 382 | + } |
| 383 | + } |
| 384 | + } |
| 385 | + } |
| 386 | + |
| 387 | + private void checkTableModifiedRows(final BoolTable table, |
| 388 | + final boolean[][] values, final int startMod, final int endMod) |
| 389 | + { |
| 390 | + for (int r = 0; r < table.getRowCount(); r++) { |
| 391 | + for (int c = 0; c < table.getColumnCount(); c++) { |
| 392 | + if (r >= startMod && r <= endMod && values != null) { |
| 393 | + assertEquals(table.getValue(c, r), values[r - startMod][c]); |
| 394 | + } |
| 395 | + else if (r > endMod && values != null) { |
| 396 | + assertEquals(table.getValue(c, r), DATA[r - values.length][c]); |
| 397 | + } |
| 398 | + else if (r >= startMod && values == null) { |
| 399 | + assertEquals(table.getValue(c, r), |
| 400 | + DATA[r + (endMod - startMod + 1)][c]); |
| 401 | + } |
| 402 | + else { |
| 403 | + assertEquals(table.getValue(c, r), DATA[r][c]); |
| 404 | + } |
| 405 | + } |
| 406 | + } |
| 407 | + } |
| 408 | + |
243 | 409 | } |
0 commit comments