Exhaustive input sets for every integral type. @author Louis Wasserman
| 42 | * @author Louis Wasserman |
| 43 | */ |
| 44 | @GwtCompatible |
| 45 | @NullUnmarked |
| 46 | public final class MathTesting { |
| 47 | static final ImmutableSet<RoundingMode> ALL_ROUNDING_MODES = |
| 48 | ImmutableSet.copyOf(RoundingMode.values()); |
| 49 | |
| 50 | static final ImmutableList<RoundingMode> ALL_SAFE_ROUNDING_MODES = |
| 51 | ImmutableList.of(DOWN, UP, FLOOR, CEILING, HALF_EVEN, HALF_UP, HALF_DOWN); |
| 52 | |
| 53 | // Exponents to test for the pow() function. |
| 54 | static final ImmutableList<Integer> EXPONENTS = |
| 55 | ImmutableList.of(0, 1, 2, 3, 4, 7, 10, 15, 20, 25, 40, 70); |
| 56 | |
| 57 | /* |
| 58 | * This list contains values that attempt to provoke overflow in integer operations. It contains |
| 59 | * positive values on or near 2^N for N near multiples of 8 (near byte boundaries). |
| 60 | */ |
| 61 | static final ImmutableSet<Integer> POSITIVE_INTEGER_CANDIDATES; |
| 62 | |
| 63 | static final Iterable<Integer> NEGATIVE_INTEGER_CANDIDATES; |
| 64 | |
| 65 | static final Iterable<Integer> NONZERO_INTEGER_CANDIDATES; |
| 66 | |
| 67 | static final Iterable<Integer> ALL_INTEGER_CANDIDATES; |
| 68 | |
| 69 | static { |
| 70 | ImmutableSet.Builder<Integer> intValues = ImmutableSet.builder(); |
| 71 | // Add boundary values manually to avoid over/under flow (this covers 2^N for 0 and 31). |
| 72 | intValues.add(Integer.MAX_VALUE - 1, Integer.MAX_VALUE); |
| 73 | // Add values up to 40. This covers cases like "square of a prime" and such. |
| 74 | for (int i = 1; i <= 40; i++) { |
| 75 | intValues.add(i); |
| 76 | } |
| 77 | // Now add values near 2^N for lots of values of N. |
| 78 | for (int exponent : asList(2, 3, 4, 9, 15, 16, 17, 24, 25, 30)) { |
| 79 | int x = 1 << exponent; |
| 80 | intValues.add(x, x + 1, x - 1); |
| 81 | } |
| 82 | intValues.add(9999).add(10000).add(10001).add(1000000); // near powers of 10 |
| 83 | intValues.add(5792).add(5793); // sqrt(2^25) rounded up and down |
| 84 | POSITIVE_INTEGER_CANDIDATES = intValues.build(); |
| 85 | NEGATIVE_INTEGER_CANDIDATES = |
| 86 | ImmutableList.copyOf( |
| 87 | Iterables.concat( |
| 88 | Iterables.transform(POSITIVE_INTEGER_CANDIDATES, x -> -x), |
| 89 | ImmutableList.of(Integer.MIN_VALUE))); |
| 90 | NONZERO_INTEGER_CANDIDATES = |
| 91 | ImmutableList.copyOf( |
| 92 | Iterables.concat(POSITIVE_INTEGER_CANDIDATES, NEGATIVE_INTEGER_CANDIDATES)); |
| 93 | ALL_INTEGER_CANDIDATES = Iterables.concat(NONZERO_INTEGER_CANDIDATES, ImmutableList.of(0)); |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | * This list contains values that attempt to provoke overflow in long operations. It contains |
| 98 | * positive values on or near 2^N for N near multiples of 8 (near byte boundaries). This list is |
| 99 | * a superset of POSITIVE_INTEGER_CANDIDATES. |
| 100 | */ |
| 101 | static final ImmutableSet<Long> POSITIVE_LONG_CANDIDATES; |
nothing calls this directly
no test coverage detected