@Test public void testGreaterThanValue() { // given byte[] val1 = Bytes.toBytes(new BigDecimal("1000000000000000000000000000000.9999999999999999")); byte[] val2 = Bytes.toBytes(new BigDecimal(0)); byte[] val3 = Bytes.toBytes(new BigDecimal(Double.MIN_VALUE)); BigDecimal bd = new BigDecimal(Double.MAX_VALUE); BigDecimalComparator comparator = new BigDecimalComparator(bd); // when int comp1 = comparator.compareTo(val1); int comp2 = comparator.compareTo(val2); int comp3 = comparator.compareTo(val3); // then Assert.assertEquals(1, comp1); Assert.assertEquals(1, comp2); Assert.assertEquals(1, comp3); }
@Test public void testLessThanValue() { // given byte[] val1 = Bytes.toBytes(new BigDecimal("-1000000000000000000000000000000")); byte[] val2 = Bytes.toBytes(new BigDecimal(0)); byte[] val3 = Bytes.toBytes(new BigDecimal(1)); BigDecimal bd = new BigDecimal("-1000000000000000000000000000000.0000000000000001"); BigDecimalComparator comparator = new BigDecimalComparator(bd); // when int comp1 = comparator.compareTo(val1); int comp2 = comparator.compareTo(val2); int comp3 = comparator.compareTo(val3); // then Assert.assertEquals(-1, comp1); Assert.assertEquals(-1, comp2); Assert.assertEquals(-1, comp3); }
@Test public void testEqualsValue() { // given BigDecimal bd1 = new BigDecimal(Double.MAX_VALUE); BigDecimal bd2 = new BigDecimal(Double.MIN_VALUE); byte[] value1 = Bytes.toBytes(bd1); byte[] value2 = Bytes.toBytes(bd2); BigDecimalComparator comparator1 = new BigDecimalComparator(bd1); BigDecimalComparator comparator2 = new BigDecimalComparator(bd2); // when int comp1 = comparator1.compareTo(value1); int comp2 = comparator2.compareTo(value2); // then Assert.assertEquals(0, comp1); Assert.assertEquals(0, comp2); }
@Test public void testGreaterThanValue() { // given byte[] val1 = Bytes.toBytes(new BigDecimal("1000000000000000000000000000000.9999999999999999")); byte[] val2 = Bytes.toBytes(new BigDecimal(0)); byte[] val3 = Bytes.toBytes(new BigDecimal(Double.MIN_VALUE)); BigDecimal bd = new BigDecimal(Double.MAX_VALUE); BigDecimalComparator comparator = new BigDecimalComparator(bd); // when int comp1 = comparator.compareTo(val1); int comp2 = comparator.compareTo(val2); int comp3 = comparator.compareTo(val3); // then Assert.assertEquals(1, comp1); Assert.assertEquals(1, comp2); Assert.assertEquals(1, comp3); }
@Test public void testLessThanValue() { // given byte[] val1 = Bytes.toBytes(new BigDecimal("-1000000000000000000000000000000")); byte[] val2 = Bytes.toBytes(new BigDecimal(0)); byte[] val3 = Bytes.toBytes(new BigDecimal(1)); BigDecimal bd = new BigDecimal("-1000000000000000000000000000000.0000000000000001"); BigDecimalComparator comparator = new BigDecimalComparator(bd); // when int comp1 = comparator.compareTo(val1); int comp2 = comparator.compareTo(val2); int comp3 = comparator.compareTo(val3); // then Assert.assertEquals(-1, comp1); Assert.assertEquals(-1, comp2); Assert.assertEquals(-1, comp3); }
@Test public void testEqualsValue() { // given BigDecimal bd1 = new BigDecimal(Double.MAX_VALUE); BigDecimal bd2 = new BigDecimal(Double.MIN_VALUE); byte[] value1 = Bytes.toBytes(bd1); byte[] value2 = Bytes.toBytes(bd2); BigDecimalComparator comparator1 = new BigDecimalComparator(bd1); BigDecimalComparator comparator2 = new BigDecimalComparator(bd2); // when int comp1 = comparator1.compareTo(value1); int comp2 = comparator2.compareTo(value2); // then Assert.assertEquals(0, comp1); Assert.assertEquals(0, comp2); }