|
1 | 1 | package it.aboutbits.springboot.testing.testdata.base; |
2 | 2 |
|
| 3 | +import it.aboutbits.springboot.toolbox.type.ScaledBigDecimal; |
3 | 4 | import it.aboutbits.springboot.toolbox.type.identity.EntityId; |
4 | 5 | import lombok.NonNull; |
5 | 6 | import net.datafaker.Faker; |
@@ -60,4 +61,52 @@ public <T extends EntityId<String>> T randomEntityId(@NonNull Function<String, T |
60 | 61 | public String unique(@NonNull String value) { |
61 | 62 | return value + "_" + super.random().nextInt(9999999); |
62 | 63 | } |
| 64 | + |
| 65 | + public RandomNumericRange numericRange() { |
| 66 | + return new RandomNumericRange( |
| 67 | + super.getFaker() |
| 68 | + ); |
| 69 | + } |
| 70 | + |
| 71 | + public static final class RandomNumericRange { |
| 72 | + private final Faker parent; |
| 73 | + |
| 74 | + private RandomNumericRange(Faker parent) { |
| 75 | + this.parent = parent; |
| 76 | + } |
| 77 | + |
| 78 | + public NumericRange random() { |
| 79 | + return random(-999999999, 999999999); |
| 80 | + } |
| 81 | + |
| 82 | + public NumericRange positive() { |
| 83 | + return random(1, 999999999); |
| 84 | + } |
| 85 | + |
| 86 | + public NumericRange positiveOrZero() { |
| 87 | + return random(0, 999999999); |
| 88 | + } |
| 89 | + |
| 90 | + public NumericRange negative() { |
| 91 | + return random(-999999999, -1); |
| 92 | + } |
| 93 | + |
| 94 | + public NumericRange negativeOrZero() { |
| 95 | + return random(-999999999, 0); |
| 96 | + } |
| 97 | + |
| 98 | + public NumericRange random(double min, double max) { |
| 99 | + var lower = parent.random().nextDouble(min, max - 1); |
| 100 | + var upper = parent.random().nextDouble(lower, max); |
| 101 | + |
| 102 | + return new NumericRange( |
| 103 | + ScaledBigDecimal.valueOf(lower), |
| 104 | + ScaledBigDecimal.valueOf(upper) |
| 105 | + ); |
| 106 | + } |
| 107 | + |
| 108 | + public record NumericRange(ScaledBigDecimal lower, ScaledBigDecimal upper) { |
| 109 | + |
| 110 | + } |
| 111 | + } |
63 | 112 | } |
0 commit comments