|
47 | 47 | public class TablesTest { |
48 | 48 |
|
49 | 49 | @Test |
50 | | - public void testWrap() { |
| 50 | + public void testWrapList() { |
| 51 | + final List<?> names = // |
| 52 | + Arrays.asList("Phoebe", "Jezebel", "Daphne", "Fiona"); |
| 53 | + final String colHeader = "Name"; |
| 54 | + final List<String> rowHeaders = Arrays.asList("A", "B", "C", "D"); |
| 55 | + final Table<?, ?> table = Tables.wrap(names, colHeader, rowHeaders); |
| 56 | + |
| 57 | + // check table dimensions |
| 58 | + assertEquals(1, table.size()); |
| 59 | + assertEquals(1, table.getColumnCount()); |
| 60 | + assertEquals(4, table.getRowCount()); |
| 61 | + |
| 62 | + // check row headers |
| 63 | + for (int r = 0; r < rowHeaders.size(); r++) |
| 64 | + assertEquals(rowHeaders.get(r), table.getRowHeader(r)); |
| 65 | + |
| 66 | + // check direct data access |
| 67 | + for (int i = 0; i < names.size(); i++) |
| 68 | + assertEquals(names.get(i), table.get(0, i)); |
| 69 | + |
| 70 | + // check first column |
| 71 | + assertEquals("Name", table.getColumnHeader(0)); |
| 72 | + final Column<?> nameColumn = table.get("Name"); |
| 73 | + assertEquals(4, nameColumn.size()); |
| 74 | + for (int i = 0; i < names.size(); i++) |
| 75 | + assertEquals(names.get(i), nameColumn.get(i)); |
| 76 | + assertEquals(nameColumn, table.get(0)); |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + public void testWrapMaps() { |
51 | 81 | final List<Map<Object, Object>> towns = Arrays.asList( // |
52 | 82 | map("Town", "Shanghai", "Population", 24_256_800), // |
53 | 83 | map("Town", "Karachi", "Population", 23_500_000), // |
|
0 commit comments