### Question:
DnaCompressor { public static byte[] compress(String dna){ BitWriter writer = new BitWriter(); writer.write(dna.length()); for(int i=0; i<dna.length(); i++){ char c = dna.charAt(i); if(c== 'A'){ writer.write(true); writer.write(true); } else if(c== 'C'){ writer.write(true); writer.write(false); }else if(c== 'G'){ writer.write(false); writer.write(true); }else if(c== 'T'){ writer.write(false); writer.write(false); } else { throw new IllegalArgumentException("Unrecognized character: " + c); } } return writer.extract(); }  static byte[] compress(String dna); static String decompress(byte[] data);  }### Answer:
@Test public void testDecreaseSize(){ String dna = "AAAGTACCTGAGTAAAGTACCTGAGTAAAGTACCTGAGTTTTGCTGCTGCTGCTGCTGCTGCTGCTGCTGCTTTTTTT"; checkPreserveInformation(dna); int nonCompressedSize = dna.getBytes(StandardCharsets.UTF_8).length; byte[] compressed = DnaCompressor.compress(dna); assertTrue(compressed.length < nonCompressedSize); double ratio = (double) compressed.length / (double) nonCompressedSize; assertTrue(ratio < 0.33); assertTrue(ratio >= 0.25); }
@Test public void testIncreaseSize(){ String dna = "A"; checkPreserveInformation(dna); int nonCompressedSize = dna.getBytes(StandardCharsets.UTF_8).length; byte[] compressed = DnaCompressor.compress(dna); assertTrue(compressed.length > nonCompressedSize); }