// Path: src/main/java/javafixes/collection/CollectionUtil.java
// @SafeVarargs
// public static <T> ArrayList<T> newList(T... values) {
//     ArrayList<T> list = new ArrayList<T>(values.length);
//     Collections.addAll(list, values);
//     return list;
// }
// 
// Path: src/main/java/javafixes/math/Decimal.java
// public static Decimal d(long unscaledValue, int scale) throws ArithmeticException {
//     return decimal(unscaledValue, scale);
// }
// 
// Path: src/main/java/javafixes/math/Decimal.java
// public static Decimal decimal(long unscaledValue, int scale) throws ArithmeticException {
//     while (unscaledValue != 0
//             && ((int) unscaledValue & 1) == 0
//             && unscaledValue % 10 == 0) {
//         unscaledValue /= 10;
// 
//         if (scale == Integer.MIN_VALUE) {
//             throw new ArithmeticException(format("Scale underflow - can't set scale to less than '%d'", Integer.MIN_VALUE));
//         }
//         scale--;
//     }
// 
//     return new LongDecimal(unscaledValue, scale);
// }
// 
// Path: src/test/java/javafixes/test/Random.java
// @SafeVarargs
// public static int randomInt(int from, int to, Function<Integer, Boolean>... validityConditions) {
//     return generateValidValue(
//             // typecast it to long as otherwise we could get int overflow
//             () -> (int) ((long) (Math.random() * ((long) to - (long) from + 1L)) + (long) from),
//             validityConditions
//     );
// }


import org.junit.Test;
import java.math.RoundingMode;
import java.util.List;
import static javafixes.collection.CollectionUtil.newList;
import static javafixes.math.Decimal.d;
import static javafixes.math.Decimal.decimal;
import static javafixes.test.Random.randomInt;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
        try { decimal("2.5").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("1.6").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("1.1").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        assertThat(decimal("1.0").descaleTo(0, RoundingMode.UNNECESSARY), equalTo(decimal("1")));
        assertThat(decimal("-1.0").descaleTo(0, RoundingMode.UNNECESSARY), equalTo(decimal("-1")));
        try { decimal("-1.1").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("-1.6").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("-2.5").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("-5.5").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }

        try { decimal("5.501").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("2.501").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("1.001").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("0.001").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("-0.001").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("-1.001").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("-2.501").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("-5.501").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
    }

    @Test
    public void shouldDoNothingWhenDescaleOfLongDecimalIsNotNeeded() {
        newList(
                "5.5",
                "2.5",
                "1.6",
                "1.1",
                "1.0",
                "-1.0",
                "-1.1",
// Path: src/main/java/javafixes/collection/CollectionUtil.java
// @SafeVarargs
// public static <T> ArrayList<T> newList(T... values) {
//     ArrayList<T> list = new ArrayList<T>(values.length);
//     Collections.addAll(list, values);
//     return list;
// }
// 
// Path: src/main/java/javafixes/math/Decimal.java
// public static Decimal d(long unscaledValue, int scale) throws ArithmeticException {
//     return decimal(unscaledValue, scale);
// }
// 
// Path: src/main/java/javafixes/math/Decimal.java
// public static Decimal decimal(long unscaledValue, int scale) throws ArithmeticException {
//     while (unscaledValue != 0
//             && ((int) unscaledValue & 1) == 0
//             && unscaledValue % 10 == 0) {
//         unscaledValue /= 10;
// 
//         if (scale == Integer.MIN_VALUE) {
//             throw new ArithmeticException(format("Scale underflow - can't set scale to less than '%d'", Integer.MIN_VALUE));
//         }
//         scale--;
//     }
// 
//     return new LongDecimal(unscaledValue, scale);
// }
// 
// Path: src/test/java/javafixes/test/Random.java
// @SafeVarargs
// public static int randomInt(int from, int to, Function<Integer, Boolean>... validityConditions) {
//     return generateValidValue(
//             // typecast it to long as otherwise we could get int overflow
//             () -> (int) ((long) (Math.random() * ((long) to - (long) from + 1L)) + (long) from),
//             validityConditions
//     );
// }


// Path: src/test/java/javafixes/math/DecimalDescaleTest.java
import org.junit.Test;
import java.math.RoundingMode;
import java.util.List;
import static javafixes.collection.CollectionUtil.newList;
import static javafixes.math.Decimal.d;
import static javafixes.math.Decimal.decimal;
import static javafixes.test.Random.randomInt;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

        try { decimal("2.5").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("1.6").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("1.1").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        assertThat(decimal("1.0").descaleTo(0, RoundingMode.UNNECESSARY), equalTo(decimal("1")));
        assertThat(decimal("-1.0").descaleTo(0, RoundingMode.UNNECESSARY), equalTo(decimal("-1")));
        try { decimal("-1.1").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("-1.6").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("-2.5").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("-5.5").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }

        try { decimal("5.501").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("2.501").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("1.001").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("0.001").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("-0.001").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("-1.001").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("-2.501").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
        try { decimal("-5.501").descaleTo(0, RoundingMode.UNNECESSARY); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { }
    }

    @Test
    public void shouldDoNothingWhenDescaleOfLongDecimalIsNotNeeded() {
        newList(
                "5.5",
                "2.5",
                "1.6",
                "1.1",
                "1.0",
                "-1.0",
                "-1.1",
                "-1.6",