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