### Question:
Compressor { CompressedRelation compress(Iterable<Row> input) { input.forEach(this::add); return toRelation(); }    }### Answer:
@Test public void testDictionaryA() { mock(); CompressedRelation compressed = compress(); CompressedColumn<String> column = compressed.getColumn(0); Dictionary<String> dictionary = column.getDictionary(); assertThat(dictionary.values()).hasSize(3); assertThat(dictionary.values()).contains("foo"); assertThat(dictionary.values()).contains("bar"); assertThat(dictionary.values()).contains("baz"); assertThat(dictionary.getOrAdd("foo")).isEqualTo(0); assertThat(dictionary.getOrAdd("bar")).isEqualTo(1); assertThat(dictionary.getOrAdd("baz")).isEqualTo(2); }
@Test public void testDictionaryB() { mock(); CompressedRelation compressed = compress(); CompressedColumn<Integer> column = compressed.getColumn(1); Dictionary<Integer> dictionary = column.getDictionary(); assertThat(dictionary.values()).hasSize(2); assertThat(dictionary.values()).contains(Integer.valueOf(2)); assertThat(dictionary.values()).contains(Integer.valueOf(1)); assertThat(dictionary.getOrAdd(Integer.valueOf(2))).isEqualTo(0); assertThat(dictionary.getOrAdd(Integer.valueOf(1))).isEqualTo(1); }
@Test public void testDictionaryRecords() { mock(); CompressedRelation compressed = compress(); DictionaryRecords dictionaryRecords = compressed.getDictionaryRecords(); assertThat(dictionaryRecords.getAll()).hasSize(3); assertThat(dictionaryRecords.get(0).length).isEqualTo(2); assertThat(dictionaryRecords.get(1)[1]).isNotEqualTo(dictionaryRecords.get(0)[1]); assertThat(dictionaryRecords.get(1)[1]).isEqualTo(dictionaryRecords.get(2)[1]); }
@Test public void testIndexOf() { mock(); CompressedRelation compressed = compress(); assertThat(compressed.indexOf(A)).isEqualTo(0); assertThat(compressed.indexOf(B)).isEqualTo(1); }
@Test(expected = RuntimeException.class) public void testInputCloseException() throws InputCloseException { doThrow(InputCloseException.class).when(input).close(); mock(); compress(); fail(); }
@Test(expected = RuntimeException.class) public void testInputOpenException() throws InputOpenException { doThrow(InputOpenException.class).when(relation).open(); compress(); fail(); }
@Test public void testPliA() { mock(); CompressedRelation compressed = compress(); CompressedColumn<String> column = compressed.getColumn(0); PositionListIndex pli = column.getPli(); assertThat(pli.get(0)).hasSize(1); assertThat(pli.get(1)).hasSize(1); assertThat(pli.get(2)).hasSize(1); assertThat(pli.get(0)).contains(Integer.valueOf(0)); assertThat(pli.get(1)).contains(Integer.valueOf(1)); assertThat(pli.get(2)).contains(Integer.valueOf(2)); }
@Test public void testPliB() { mock(); CompressedRelation compressed = compress(); CompressedColumn<Integer> column = compressed.getColumn(1); PositionListIndex pli = column.getPli(); assertThat(pli.get(0)).hasSize(1); assertThat(pli.get(1)).hasSize(2); assertThat(pli.get(0)).contains(Integer.valueOf(0)); assertThat(pli.get(1)).contains(Integer.valueOf(1)); assertThat(pli.get(1)).contains(Integer.valueOf(2)); }