BigDecimalQuantizer { public static Quantizer<BigDecimal> withCompressionFactor(int compressionFactor) { return compressionFactor < 2 ? new TruncatingQuantizer() : new TruncatingAndCompressingQuantizer(compressionFactor); } BigDecimalQuantizer(); static Quantizer<BigDecimal> withCompressionFactor(int compressionFactor);  }
@Test public void testWithCompressionFactor_5() throws Exception { Quantizer<BigDecimal> quantizer = BigDecimalQuantizer.withCompressionFactor(5); Assert.assertEquals("0", quantizer.getQuantizedValue(BigDecimal.valueOf(0.0)).toString()); Assert.assertEquals("0", quantizer.getQuantizedValue(BigDecimal.valueOf(4.2)).toString()); Assert.assertEquals("5", quantizer.getQuantizedValue(BigDecimal.valueOf(5.0)).toString()); Assert.assertEquals("5", quantizer.getQuantizedValue(BigDecimal.valueOf(9.9)).toString()); Assert.assertEquals("10", quantizer.getQuantizedValue(BigDecimal.valueOf(11.3)).toString()); Assert.assertEquals("0", quantizer.getQuantizedValue(BigDecimal.valueOf(-0.0)).toString()); Assert.assertEquals("0", quantizer.getQuantizedValue(BigDecimal.valueOf(-4.2)).toString()); Assert.assertEquals("-5", quantizer.getQuantizedValue(BigDecimal.valueOf(-5.0)).toString()); Assert.assertEquals("-5", quantizer.getQuantizedValue(BigDecimal.valueOf(-9.9)).toString()); Assert.assertEquals("-10", quantizer.getQuantizedValue(BigDecimal.valueOf(-11.3)).toString()); }
@Test public void testWithCompressionFactor_1() throws Exception { Quantizer<BigDecimal> quantizer = BigDecimalQuantizer.withCompressionFactor(1); Assert.assertEquals("0", quantizer.getQuantizedValue(BigDecimal.valueOf(0.0)).toString()); Assert.assertEquals("4", quantizer.getQuantizedValue(BigDecimal.valueOf(4.2)).toString()); Assert.assertEquals("5", quantizer.getQuantizedValue(BigDecimal.valueOf(5.0)).toString()); Assert.assertEquals("9", quantizer.getQuantizedValue(BigDecimal.valueOf(9.9)).toString()); Assert.assertEquals("11", quantizer.getQuantizedValue(BigDecimal.valueOf(11.3)).toString()); Assert.assertEquals("0", quantizer.getQuantizedValue(BigDecimal.valueOf(-0.0)).toString()); Assert.assertEquals("-4", quantizer.getQuantizedValue(BigDecimal.valueOf(-4.2)).toString()); Assert.assertEquals("-5", quantizer.getQuantizedValue(BigDecimal.valueOf(-5.0)).toString()); Assert.assertEquals("-9", quantizer.getQuantizedValue(BigDecimal.valueOf(-9.9)).toString()); Assert.assertEquals("-11", quantizer.getQuantizedValue(BigDecimal.valueOf(-11.3)).toString()); }