diff --git a/common/src/main/java/com/scottlogic/deg/common/util/Defaults.java b/common/src/main/java/com/scottlogic/deg/common/util/Defaults.java index 0e032f451..209b42cdd 100644 --- a/common/src/main/java/com/scottlogic/deg/common/util/Defaults.java +++ b/common/src/main/java/com/scottlogic/deg/common/util/Defaults.java @@ -32,6 +32,7 @@ public class Defaults { public static final BigDecimal NUMERIC_MAX = new BigDecimal("1e20"); public static final BigDecimal NUMERIC_MIN = new BigDecimal("-1e20"); + public static final int MAX_STRING_LENGTH = 1000; public static final OffsetDateTime ISO_MAX_DATE = OffsetDateTime.of(9999, 12, 31, 23, 59, 59, 999_000_000, ZoneOffset.UTC); public static final OffsetDateTime ISO_MIN_DATE = OffsetDateTime.of(1, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC); diff --git a/generator/src/main/java/com/scottlogic/deg/generator/generation/string/factorys/RandomStringFactory.java b/generator/src/main/java/com/scottlogic/deg/generator/generation/string/factorys/RandomStringFactory.java index a39651522..89c8c5204 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/generation/string/factorys/RandomStringFactory.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/generation/string/factorys/RandomStringFactory.java @@ -16,62 +16,46 @@ package com.scottlogic.deg.generator.generation.string.factorys; +import com.scottlogic.deg.common.ValidationException; import com.scottlogic.deg.generator.generation.string.StringUtils; import com.scottlogic.deg.generator.utils.RandomNumberGenerator; import dk.brics.automaton.State; import dk.brics.automaton.Transition; +import java.util.LinkedList; import java.util.List; public class RandomStringFactory { - public String createRandomString( - String currentString, - State state, - int minLength, - int maxLength, - RandomNumberGenerator random) { + public String createRandomString(State state, RandomNumberGenerator random) { + List validIndices = new LinkedList<>(); - if (finishCreating(currentString, state, minLength, maxLength, random)) { - return currentString; - } - - List transitions = state.getSortedTransitions(false); - - Transition randomTransition = transitions.get(random.nextInt(transitions.size())); - - char randomChar = getRandomChar(random, randomTransition); - - return createRandomString( - currentString + randomChar, - randomTransition.getDest(), - minLength, - maxLength, - random); - } - - private boolean finishCreating( - String currentString, - State state, - int minLength, - int maxLength, - RandomNumberGenerator random) { + StringBuilder builder = new StringBuilder(); if (state.isAccept()) { - if (currentString.length() == maxLength) { - return true; - } - if (currentString.length() >= minLength && randomlyStop(random)) { - return true; + validIndices.add(0); + } + + for (int i = 1; !finishCreating(state); i++) { + List transitions = state.getSortedTransitions(false); + Transition randomTransition = transitions.get(random.nextInt(transitions.size())); + builder.append(getRandomChar(random, randomTransition)); + state = randomTransition.getDest(); + if (state.isAccept()) { + validIndices.add(i); } } - return state.getTransitions().isEmpty(); - } + if (validIndices.isEmpty()) { + throw new ValidationException("No possible states from the current regex"); + } + int randomIndex = random.nextInt(validIndices.size()); + return builder.toString().substring(0, validIndices.get(randomIndex)); + } - private boolean randomlyStop(RandomNumberGenerator random) { - return random.nextInt(10) < 3; // 3 in 10 chance of stopping + private boolean finishCreating(State state) { + return state.getTransitions().isEmpty(); } /** diff --git a/generator/src/main/java/com/scottlogic/deg/generator/generation/string/generators/RegexStringGenerator.java b/generator/src/main/java/com/scottlogic/deg/generator/generation/string/generators/RegexStringGenerator.java index fa47d9e9e..c4960a352 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/generation/string/generators/RegexStringGenerator.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/generation/string/generators/RegexStringGenerator.java @@ -16,10 +16,13 @@ package com.scottlogic.deg.generator.generation.string.generators; +import com.scottlogic.deg.common.profile.FieldType; +import com.scottlogic.deg.generator.fieldspecs.FieldSpecFactory; import com.scottlogic.deg.generator.generation.string.AutomatonUtils; import com.scottlogic.deg.generator.generation.string.iterators.FiniteStringAutomatonIterator; import com.scottlogic.deg.generator.generation.string.factorys.InterestingStringFactory; import com.scottlogic.deg.generator.generation.string.factorys.RandomStringFactory; +import com.scottlogic.deg.generator.restrictions.string.StringRestrictions; import com.scottlogic.deg.generator.utils.RandomNumberGenerator; import dk.brics.automaton.Automaton; @@ -39,6 +42,8 @@ public class RegexStringGenerator implements StringGenerator { */ private static final Map containingRegexAutomatonCache = new HashMap<>(); + private static final RegexStringGenerator DEFAULT = (RegexStringGenerator) ((StringRestrictions) FieldSpecFactory.fromType(FieldType.STRING).getRestrictions()).createGenerator(); + private Automaton automaton; private final String regexRepresentation; @@ -119,7 +124,7 @@ RegexStringGenerator union(RegexStringGenerator otherGenerator) { @Override public StringGenerator complement() { return new RegexStringGenerator( - this.automaton.clone().complement(), + this.automaton.clone().complement().intersection(DEFAULT.automaton), complementaryRepresentation(this.regexRepresentation)); } @@ -150,10 +155,7 @@ public Stream generateAllValues() { public Stream generateRandomValues(RandomNumberGenerator randomNumberGenerator) { return Stream.generate( () -> randomStringFactory.createRandomString( - "", automaton.getInitialState(), - 1, - Integer.MAX_VALUE, randomNumberGenerator)); } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterConstantTimeConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterConstantTimeConstraint.java index 0abb70824..c7a5a6cf5 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterConstantTimeConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterConstantTimeConstraint.java @@ -22,7 +22,7 @@ import com.scottlogic.deg.generator.restrictions.linear.Limit; import com.scottlogic.deg.generator.restrictions.linear.LinearRestrictions; import com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory; -import com.scottlogic.deg.generator.utils.Defaults; +import com.scottlogic.deg.generator.utils.GeneratorDefaults; import java.time.LocalTime; @@ -50,7 +50,7 @@ public AtomicConstraint negate() { public FieldSpec toFieldSpec() { final Limit min = new Limit<>(referenceValue.getValue(), false); final LinearRestrictions timeRestrictions = - LinearRestrictionsFactory.createTimeRestrictions(min, Defaults.TIME_MAX_LIMIT); + LinearRestrictionsFactory.createTimeRestrictions(min, GeneratorDefaults.TIME_MAX_LIMIT); return FieldSpecFactory.fromRestriction(timeRestrictions); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterConstraint.java index 66fead496..58ff7760e 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterConstraint.java @@ -26,7 +26,7 @@ import java.util.Objects; import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createDateTimeRestrictions; -import static com.scottlogic.deg.generator.utils.Defaults.DATETIME_MAX_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.DATETIME_MAX_LIMIT; public class AfterConstraint implements AtomicConstraint { public final Field field; diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterOrAtConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterOrAtConstraint.java index 05af94961..47f19314c 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterOrAtConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterOrAtConstraint.java @@ -27,7 +27,7 @@ import java.util.Objects; import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createDateTimeRestrictions; -import static com.scottlogic.deg.generator.utils.Defaults.DATETIME_MAX_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.DATETIME_MAX_LIMIT; public class AfterOrAtConstraint implements AtomicConstraint { public final Field field; diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterOrEqualToConstantTimeConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterOrEqualToConstantTimeConstraint.java index c08d83a9c..2470a968b 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterOrEqualToConstantTimeConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterOrEqualToConstantTimeConstraint.java @@ -22,7 +22,7 @@ import com.scottlogic.deg.generator.restrictions.linear.Limit; import com.scottlogic.deg.generator.restrictions.linear.LinearRestrictions; import com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory; -import com.scottlogic.deg.generator.utils.Defaults; +import com.scottlogic.deg.generator.utils.GeneratorDefaults; import java.time.LocalTime; @@ -50,7 +50,7 @@ public AtomicConstraint negate() { public FieldSpec toFieldSpec() { final Limit min = new Limit<>(referenceValue.getValue(), true); final LinearRestrictions timeRestrictions = - LinearRestrictionsFactory.createTimeRestrictions(min, Defaults.TIME_MAX_LIMIT); + LinearRestrictionsFactory.createTimeRestrictions(min, GeneratorDefaults.TIME_MAX_LIMIT); return FieldSpecFactory.fromRestriction(timeRestrictions); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeConstantTimeConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeConstantTimeConstraint.java index 953013142..c7dd8f25d 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeConstantTimeConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeConstantTimeConstraint.java @@ -22,7 +22,7 @@ import com.scottlogic.deg.generator.restrictions.linear.Limit; import com.scottlogic.deg.generator.restrictions.linear.LinearRestrictions; import com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory; -import com.scottlogic.deg.generator.utils.Defaults; +import com.scottlogic.deg.generator.utils.GeneratorDefaults; import java.time.LocalTime; @@ -51,7 +51,7 @@ public FieldSpec toFieldSpec() { final Limit max = new Limit<>(referenceValue.getValue(), false); final LinearRestrictions timeRestriction = - LinearRestrictionsFactory.createTimeRestrictions(Defaults.TIME_MIN_LIMIT, max); + LinearRestrictionsFactory.createTimeRestrictions(GeneratorDefaults.TIME_MIN_LIMIT, max); if (timeRestriction.isContradictory()) { return FieldSpecFactory.nullOnly(); } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeConstraint.java index ed1f28bc1..6561302d4 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeConstraint.java @@ -26,7 +26,7 @@ import java.util.Objects; import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createDateTimeRestrictions; -import static com.scottlogic.deg.generator.utils.Defaults.DATETIME_MIN_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.DATETIME_MIN_LIMIT; public class BeforeConstraint implements AtomicConstraint { public final Field field; diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeOrAtConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeOrAtConstraint.java index 4aba195b2..1d8bf250b 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeOrAtConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeOrAtConstraint.java @@ -26,7 +26,7 @@ import java.util.Objects; import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createDateTimeRestrictions; -import static com.scottlogic.deg.generator.utils.Defaults.DATETIME_MIN_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.DATETIME_MIN_LIMIT; public class BeforeOrAtConstraint implements AtomicConstraint { public final Field field; diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeOrEqualToConstantTimeConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeOrEqualToConstantTimeConstraint.java index 4e69d3d5f..5c02b6791 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeOrEqualToConstantTimeConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeOrEqualToConstantTimeConstraint.java @@ -22,7 +22,7 @@ import com.scottlogic.deg.generator.restrictions.linear.Limit; import com.scottlogic.deg.generator.restrictions.linear.LinearRestrictions; import com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory; -import com.scottlogic.deg.generator.utils.Defaults; +import com.scottlogic.deg.generator.utils.GeneratorDefaults; import java.time.LocalTime; @@ -49,7 +49,7 @@ public AtomicConstraint negate() { public FieldSpec toFieldSpec() { final Limit max = new Limit<>(referenceValue.getValue(), true); final LinearRestrictions timeRestriction = - LinearRestrictionsFactory.createTimeRestrictions(Defaults.TIME_MIN_LIMIT, max); + LinearRestrictionsFactory.createTimeRestrictions(GeneratorDefaults.TIME_MIN_LIMIT, max); return FieldSpecFactory.fromRestriction(timeRestriction); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GranularToDateConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GranularToDateConstraint.java index ab97d62ed..7dc107f78 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GranularToDateConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GranularToDateConstraint.java @@ -25,8 +25,8 @@ import java.util.Objects; import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createDateTimeRestrictions; -import static com.scottlogic.deg.generator.utils.Defaults.DATETIME_MAX_LIMIT; -import static com.scottlogic.deg.generator.utils.Defaults.DATETIME_MIN_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.DATETIME_MAX_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.DATETIME_MIN_LIMIT; public class GranularToDateConstraint implements AtomicConstraint { public final Field field; diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GranularToTimeConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GranularToTimeConstraint.java index 679a5a89f..169b7e86c 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GranularToTimeConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GranularToTimeConstraint.java @@ -21,7 +21,7 @@ import com.scottlogic.deg.generator.fieldspecs.FieldSpec; import com.scottlogic.deg.generator.fieldspecs.FieldSpecFactory; import com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory; -import com.scottlogic.deg.generator.utils.Defaults; +import com.scottlogic.deg.generator.utils.GeneratorDefaults; public class GranularToTimeConstraint implements AtomicConstraint { public final TimeGranularity timeGranularity; @@ -51,8 +51,8 @@ public AtomicConstraint negate() { public FieldSpec toFieldSpec() { return FieldSpecFactory.fromRestriction( LinearRestrictionsFactory.createTimeRestrictions( - Defaults.TIME_MIN_LIMIT, - Defaults.TIME_MAX_LIMIT, + GeneratorDefaults.TIME_MIN_LIMIT, + GeneratorDefaults.TIME_MAX_LIMIT, timeGranularity)); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GreaterThanConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GreaterThanConstraint.java index 4faf1a3e5..fc78ab6bd 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GreaterThanConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GreaterThanConstraint.java @@ -26,7 +26,7 @@ import java.util.Objects; import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createNumericRestrictions; -import static com.scottlogic.deg.generator.utils.Defaults.NUMERIC_MAX_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.NUMERIC_MAX_LIMIT; public class GreaterThanConstraint implements AtomicConstraint { public final Field field; diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GreaterThanOrEqualToConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GreaterThanOrEqualToConstraint.java index de10ca62d..64581aa73 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GreaterThanOrEqualToConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GreaterThanOrEqualToConstraint.java @@ -26,7 +26,7 @@ import java.util.Objects; import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createNumericRestrictions; -import static com.scottlogic.deg.generator.utils.Defaults.NUMERIC_MAX_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.NUMERIC_MAX_LIMIT; public class GreaterThanOrEqualToConstraint implements AtomicConstraint { public final Field field; diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LessThanConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LessThanConstraint.java index 5e10a22d8..c0405da01 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LessThanConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LessThanConstraint.java @@ -26,7 +26,7 @@ import java.util.Objects; import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createNumericRestrictions; -import static com.scottlogic.deg.generator.utils.Defaults.NUMERIC_MIN_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.NUMERIC_MIN_LIMIT; public class LessThanConstraint implements AtomicConstraint { public final Field field; diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LessThanOrEqualToConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LessThanOrEqualToConstraint.java index 30b796002..7adc737d3 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LessThanOrEqualToConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LessThanOrEqualToConstraint.java @@ -26,7 +26,7 @@ import java.util.Objects; import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createNumericRestrictions; -import static com.scottlogic.deg.generator.utils.Defaults.NUMERIC_MIN_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.NUMERIC_MIN_LIMIT; public class LessThanOrEqualToConstraint implements AtomicConstraint { public final Field field; diff --git a/generator/src/main/java/com/scottlogic/deg/generator/restrictions/linear/LinearRestrictionsFactory.java b/generator/src/main/java/com/scottlogic/deg/generator/restrictions/linear/LinearRestrictionsFactory.java index 406029f34..16afff78d 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/restrictions/linear/LinearRestrictionsFactory.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/restrictions/linear/LinearRestrictionsFactory.java @@ -22,7 +22,7 @@ import java.time.OffsetDateTime; import static com.scottlogic.deg.common.util.Defaults.*; -import static com.scottlogic.deg.generator.utils.Defaults.*; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.*; public class LinearRestrictionsFactory { diff --git a/generator/src/main/java/com/scottlogic/deg/generator/utils/Defaults.java b/generator/src/main/java/com/scottlogic/deg/generator/utils/GeneratorDefaults.java similarity index 97% rename from generator/src/main/java/com/scottlogic/deg/generator/utils/Defaults.java rename to generator/src/main/java/com/scottlogic/deg/generator/utils/GeneratorDefaults.java index 5bb6f0b27..3e3036576 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/utils/Defaults.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/utils/GeneratorDefaults.java @@ -24,7 +24,7 @@ import static com.scottlogic.deg.common.util.Defaults.*; -public class Defaults { +public class GeneratorDefaults { public static final Limit NUMERIC_MAX_LIMIT = new Limit<>(NUMERIC_MAX, true); public static final Limit NUMERIC_MIN_LIMIT= new Limit<>(NUMERIC_MIN, true); diff --git a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/FieldSpecTests.java b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/FieldSpecTests.java index 8cb6157b2..7c86ee4bf 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/FieldSpecTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/FieldSpecTests.java @@ -33,7 +33,7 @@ import static com.scottlogic.deg.common.profile.FieldType.*; import static com.scottlogic.deg.generator.restrictions.string.StringRestrictionsFactory.forMaxLength; -import static com.scottlogic.deg.generator.utils.Defaults.*; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.*; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertFalse; diff --git a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/RestrictionsMergeOperationTest.java b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/RestrictionsMergeOperationTest.java index 31af6479c..01302203d 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/RestrictionsMergeOperationTest.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/RestrictionsMergeOperationTest.java @@ -33,9 +33,9 @@ import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createDateTimeRestrictions; import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createNumericRestrictions; -import static com.scottlogic.deg.generator.utils.Defaults.NUMERIC_MAX_LIMIT; -import static com.scottlogic.deg.generator.utils.Defaults.DATETIME_MAX_LIMIT; -import static com.scottlogic.deg.generator.utils.Defaults.DATETIME_MIN_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.NUMERIC_MAX_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.DATETIME_MAX_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.DATETIME_MIN_LIMIT; import static org.mockito.Mockito.*; class RestrictionsMergeOperationTest { diff --git a/generator/src/test/java/com/scottlogic/deg/generator/generation/FieldSpecGetFieldValueSourceTests.java b/generator/src/test/java/com/scottlogic/deg/generator/generation/FieldSpecGetFieldValueSourceTests.java index 786ab3194..ea64d308a 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/generation/FieldSpecGetFieldValueSourceTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/generation/FieldSpecGetFieldValueSourceTests.java @@ -37,8 +37,8 @@ import static com.scottlogic.deg.common.profile.FieldType.*; import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createNumericRestrictions; -import static com.scottlogic.deg.generator.utils.Defaults.NUMERIC_MAX_LIMIT; -import static com.scottlogic.deg.generator.utils.Defaults.NUMERIC_MIN_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.NUMERIC_MAX_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.NUMERIC_MIN_LIMIT; public class FieldSpecGetFieldValueSourceTests { diff --git a/generator/src/test/java/com/scottlogic/deg/generator/generation/fieldvaluesources/RealNumberFieldValueSourceTests.java b/generator/src/test/java/com/scottlogic/deg/generator/generation/fieldvaluesources/RealNumberFieldValueSourceTests.java index 53781f7a0..592bee93a 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/generation/fieldvaluesources/RealNumberFieldValueSourceTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/generation/fieldvaluesources/RealNumberFieldValueSourceTests.java @@ -35,8 +35,8 @@ import java.util.stream.Stream; import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createNumericRestrictions; -import static com.scottlogic.deg.generator.utils.Defaults.NUMERIC_MAX_LIMIT; -import static com.scottlogic.deg.generator.utils.Defaults.NUMERIC_MIN_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.NUMERIC_MAX_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.NUMERIC_MIN_LIMIT; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.Matchers.*; diff --git a/generator/src/test/java/com/scottlogic/deg/generator/generation/fieldvaluesources/datetime/DateTimeFieldValueSourceTests.java b/generator/src/test/java/com/scottlogic/deg/generator/generation/fieldvaluesources/datetime/DateTimeFieldValueSourceTests.java index 78eaeb745..f6f2707a8 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/generation/fieldvaluesources/datetime/DateTimeFieldValueSourceTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/generation/fieldvaluesources/datetime/DateTimeFieldValueSourceTests.java @@ -34,8 +34,8 @@ import static com.scottlogic.deg.common.util.Defaults.ISO_MAX_DATE; import static com.scottlogic.deg.common.util.Defaults.ISO_MIN_DATE; -import static com.scottlogic.deg.generator.utils.Defaults.DATETIME_MAX_LIMIT; -import static com.scottlogic.deg.generator.utils.Defaults.DATETIME_MIN_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.DATETIME_MAX_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.DATETIME_MIN_LIMIT; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsNot.not; diff --git a/generator/src/test/java/com/scottlogic/deg/generator/generation/string/RegexStringGeneratorTests.java b/generator/src/test/java/com/scottlogic/deg/generator/generation/string/RegexStringGeneratorTests.java index 8bd599072..7b85a6aa4 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/generation/string/RegexStringGeneratorTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/generation/string/RegexStringGeneratorTests.java @@ -18,12 +18,14 @@ import com.scottlogic.deg.generator.generation.string.generators.RegexStringGenerator; import com.scottlogic.deg.generator.generation.string.generators.StringGenerator; +import com.scottlogic.deg.generator.restrictions.string.StringRestrictionsFactory; import com.scottlogic.deg.generator.utils.JavaUtilRandomNumberGenerator; import org.hamcrest.core.Is; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.*; +import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; @@ -155,7 +157,7 @@ void shouldCreateZeroLengthInterestingValue() { @Test void shouldCorrectlySampleInfiniteResults() { - StringGenerator generator = new RegexStringGenerator("[a]+", false); + StringGenerator generator = StringRestrictionsFactory.forStringMatching(Pattern.compile("[a]+"), false).createGenerator(); Stream results = generator.generateRandomValues(new JavaUtilRandomNumberGenerator(0)); @@ -183,7 +185,8 @@ void shouldProduceIntersection() { @Test void shouldProduceComplement() { - StringGenerator limitedRangeGenerator = new RegexStringGenerator("[a-m]", true); + StringGenerator limitedRangeGenerator = + StringRestrictionsFactory.forStringMatching(Pattern.compile("[a-m]"), false).createGenerator(); StringGenerator complementedGenerator = limitedRangeGenerator.complement(); String sampleValue = complementedGenerator diff --git a/generator/src/test/java/com/scottlogic/deg/generator/restrictions/DateTimeRestrictionsMergerTests.java b/generator/src/test/java/com/scottlogic/deg/generator/restrictions/DateTimeRestrictionsMergerTests.java index b79aa9188..7538d3fbc 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/restrictions/DateTimeRestrictionsMergerTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/restrictions/DateTimeRestrictionsMergerTests.java @@ -25,7 +25,7 @@ import java.util.Optional; import static com.scottlogic.deg.common.util.Defaults.ISO_MAX_DATE; -import static com.scottlogic.deg.generator.utils.Defaults.*; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.*; import static java.time.temporal.ChronoUnit.*; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsEqual.equalTo; diff --git a/generator/src/test/java/com/scottlogic/deg/generator/restrictions/DateTimeRestrictionsTests.java b/generator/src/test/java/com/scottlogic/deg/generator/restrictions/DateTimeRestrictionsTests.java index 84d80b034..7ad5b515e 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/restrictions/DateTimeRestrictionsTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/restrictions/DateTimeRestrictionsTests.java @@ -28,8 +28,8 @@ import static com.scottlogic.deg.common.util.Defaults.ISO_MAX_DATE; import static com.scottlogic.deg.common.util.Defaults.ISO_MIN_DATE; -import static com.scottlogic.deg.generator.utils.Defaults.DATETIME_MAX_LIMIT; -import static com.scottlogic.deg.generator.utils.Defaults.DATETIME_MIN_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.DATETIME_MAX_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.DATETIME_MIN_LIMIT; import static java.time.temporal.ChronoUnit.*; import static org.hamcrest.core.IsEqual.equalTo; diff --git a/generator/src/test/java/com/scottlogic/deg/generator/restrictions/NumericRestrictionsMergerTests.java b/generator/src/test/java/com/scottlogic/deg/generator/restrictions/NumericRestrictionsMergerTests.java index b25398bb0..1e6508589 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/restrictions/NumericRestrictionsMergerTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/restrictions/NumericRestrictionsMergerTests.java @@ -25,8 +25,8 @@ import java.math.BigDecimal; import java.util.Optional; -import static com.scottlogic.deg.generator.utils.Defaults.NUMERIC_MAX_LIMIT; -import static com.scottlogic.deg.generator.utils.Defaults.NUMERIC_MIN_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.NUMERIC_MAX_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.NUMERIC_MIN_LIMIT; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.lessThan; import static org.hamcrest.core.Is.is; diff --git a/generator/src/test/java/com/scottlogic/deg/generator/restrictions/NumericRestrictionsTests.java b/generator/src/test/java/com/scottlogic/deg/generator/restrictions/NumericRestrictionsTests.java index 0ff57ec1c..79d3d266a 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/restrictions/NumericRestrictionsTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/restrictions/NumericRestrictionsTests.java @@ -25,8 +25,8 @@ import java.math.BigDecimal; -import static com.scottlogic.deg.generator.utils.Defaults.NUMERIC_MAX_LIMIT; -import static com.scottlogic.deg.generator.utils.Defaults.NUMERIC_MIN_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.NUMERIC_MAX_LIMIT; +import static com.scottlogic.deg.generator.utils.GeneratorDefaults.NUMERIC_MIN_LIMIT; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNot.not;