@Test
  public void testMultiplyScaleDownTenDestructiveScaleTen() {
    for (int scale = 0; scale < 38; ++scale) {
      UnsignedInt128 right = new UnsignedInt128(1);
      right.scaleUpTenDestructive((short) scale);
      {
        // 10000000....000
        UnsignedInt128 leftJust = new UnsignedInt128(1);
        leftJust.scaleUpTenDestructive((short) 15);
        UnsignedInt128 leftInc = leftJust.incrementConstructive();
        UnsignedInt128 leftDec = leftJust.decrementConstructive();

        if (scale + 10 <= 38) {
          leftJust.multiplyScaleDownTenDestructive(right, (short) (scale + 10));
          assertEquals("scale=" + scale, 100000L, leftJust.asLong());
          leftInc.multiplyScaleDownTenDestructive(right, (short) (scale + 10));
          assertEquals("scale=" + scale, 100000L, leftInc.asLong());
          leftDec.multiplyScaleDownTenDestructive(right, (short) (scale + 10));
          assertEquals("scale=" + scale, 100000L, leftDec.asLong());
        } else {
          leftJust.multiplyScaleDownTenDestructive(right, (short) (scale + 10));
          assertEquals("scale=" + scale, 0L, leftJust.asLong());
          leftInc.multiplyScaleDownTenDestructive(right, (short) (scale + 10));
          assertEquals("scale=" + scale, 0L, leftInc.asLong());
          leftDec.multiplyScaleDownTenDestructive(right, (short) (scale + 10));
          assertEquals("scale=" + scale, 0L, leftDec.asLong());
        }
      }

      {
        // 10000500....00
        UnsignedInt128 leftHalfJust = new UnsignedInt128(1);
        leftHalfJust.scaleUpTenDestructive((short) 6);
        leftHalfJust.addDestructive(new UnsignedInt128(5));
        leftHalfJust.scaleUpTenDestructive((short) 9);
        UnsignedInt128 leftHalfInc = leftHalfJust.incrementConstructive();
        UnsignedInt128 leftHalfDec = leftHalfJust.decrementConstructive();

        if (scale + 10 <= 38) {
          leftHalfJust.multiplyScaleDownTenDestructive(right,
              (short) (scale + 10));
          assertEquals("scale=" + scale, 100001L, leftHalfJust.asLong());
          leftHalfInc.multiplyScaleDownTenDestructive(right,
              (short) (scale + 10));
          assertEquals("scale=" + scale, 100001L, leftHalfInc.asLong());
          leftHalfDec.multiplyScaleDownTenDestructive(right,
              (short) (scale + 10));
          assertEquals("scale=" + scale, 100000L, leftHalfDec.asLong());
        } else {
          leftHalfJust.multiplyScaleDownTenDestructive(right,
              (short) (scale + 10));
          assertEquals("scale=" + scale, 0L, leftHalfJust.asLong());
          leftHalfInc.multiplyScaleDownTenDestructive(right,
              (short) (scale + 10));
          assertEquals("scale=" + scale, 0L, leftHalfInc.asLong());
          leftHalfDec.multiplyScaleDownTenDestructive(right,
              (short) (scale + 10));
          assertEquals("scale=" + scale, 0L, leftHalfDec.asLong());
        }
      }
    }
  }
Testcases for {@link UnsignedInt128}

This code was based on code from Microsoft's PolyBase.
common/src/test/org/apache/hadoop/hive/common/type/TestUnsignedInt128.java