DoubleQuantizer { public static Quantizer<Double> withCompressionFactor(int compressionFactor) { return compressionFactor < 2 ? new TruncatingQuantizer() : new TruncatingAndCompressingQuantizer(compressionFactor); } DoubleQuantizer(); static Quantizer<Double> withCompressionFactor(int compressionFactor);  }
@Test public void testWithCompressionFactor_5() throws Exception { Quantizer<Double> quantizer = DoubleQuantizer.withCompressionFactor(5); Assert.assertEquals("0.0", quantizer.getQuantizedValue(0.0).toString()); Assert.assertEquals("0.0", quantizer.getQuantizedValue(4.2).toString()); Assert.assertEquals("5.0", quantizer.getQuantizedValue(5.0).toString()); Assert.assertEquals("5.0", quantizer.getQuantizedValue(9.9).toString()); Assert.assertEquals("0.0", quantizer.getQuantizedValue(-0.0).toString()); Assert.assertEquals("0.0", quantizer.getQuantizedValue(-4.2).toString()); Assert.assertEquals("-5.0", quantizer.getQuantizedValue(-5.0).toString()); Assert.assertEquals("-5.0", quantizer.getQuantizedValue(-9.9).toString()); }
@Test public void testWithCompressionFactor_1() throws Exception { Quantizer<Double> quantizer = DoubleQuantizer.withCompressionFactor(1); Assert.assertEquals("0.0", quantizer.getQuantizedValue(0.0).toString()); Assert.assertEquals("4.0", quantizer.getQuantizedValue(4.2).toString()); Assert.assertEquals("5.0", quantizer.getQuantizedValue(5.0).toString()); Assert.assertEquals("9.0", quantizer.getQuantizedValue(9.9).toString()); Assert.assertEquals("0.0", quantizer.getQuantizedValue(-0.0).toString()); Assert.assertEquals("-4.0", quantizer.getQuantizedValue(-4.2).toString()); Assert.assertEquals("-5.0", quantizer.getQuantizedValue(-5.0).toString()); Assert.assertEquals("-9.0", quantizer.getQuantizedValue(-9.9).toString()); }