Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Rebase
Browse files Browse the repository at this point in the history
* Incorporated atomic constraint factory
  • Loading branch information
cdowding-sl committed Nov 1, 2019
1 parent 89ca26b commit 4a6ffd6
Show file tree
Hide file tree
Showing 29 changed files with 553 additions and 671 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Field getField() {

@Override
public AtomicConstraint negate() {
return new IsLessThanOrEqualToConstantConstraint(field, referenceValue);
return new LessThanOrEqualToConstraint(field, referenceValue);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createNumericRestrictions;
import static com.scottlogic.deg.generator.utils.Defaults.NUMERIC_MIN_LIMIT;

public class IsLessThanOrEqualToConstantConstraint implements AtomicConstraint {
public class LessThanOrEqualToConstraint implements AtomicConstraint {
public final Field field;
public final HelixNumber referenceValue;

public IsLessThanOrEqualToConstantConstraint(Field field, HelixNumber referenceValue) {
public LessThanOrEqualToConstraint(Field field, HelixNumber referenceValue) {
this.referenceValue = referenceValue;
this.field = field;
}
Expand Down Expand Up @@ -61,7 +61,7 @@ public boolean equals(Object o){
return o.equals(this);
}
if (o == null || getClass() != o.getClass()) return false;
IsLessThanOrEqualToConstantConstraint constraint = (IsLessThanOrEqualToConstantConstraint) o;
LessThanOrEqualToConstraint constraint = (LessThanOrEqualToConstraint) o;
return Objects.equals(field, constraint.field) && Objects.equals(referenceValue, constraint.referenceValue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

import java.util.Objects;

public class IsStringLongerThanConstraint implements AtomicConstraint {
public class LongerThanConstraint implements AtomicConstraint {
public final Field field;
public final HelixStringLength referenceValue;

public IsStringLongerThanConstraint(Field field, HelixStringLength referenceValue) {
public LongerThanConstraint(Field field, HelixStringLength referenceValue) {
this.referenceValue = referenceValue;
this.field = field;
}
Expand All @@ -41,7 +41,7 @@ public Field getField() {
@Override
public AtomicConstraint negate()
{
return new IsStringShorterThanConstraint(field, HelixStringLength.create(referenceValue.getValue() + 1));
return new ShorterThanConstraint(field, HelixStringLength.create(referenceValue.getValue() + 1));
}

@Override
Expand All @@ -56,7 +56,7 @@ public boolean equals(Object o){
return o.equals(this);
}
if (o == null || getClass() != o.getClass()) return false;
IsStringLongerThanConstraint constraint = (IsStringLongerThanConstraint) o;
LongerThanConstraint constraint = (LongerThanConstraint) o;
return Objects.equals(field, constraint.field) && Objects.equals(referenceValue, constraint.referenceValue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Field getField() {

@Override
public AtomicConstraint negate() {
return new StringHasLengthConstraint(field, referenceValue);
return new OfLengthConstraint(field, referenceValue);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

import java.util.Objects;

public class StringHasLengthConstraint implements AtomicConstraint {
public class OfLengthConstraint implements AtomicConstraint {
public final Field field;
public final HelixStringLength referenceValue;

public StringHasLengthConstraint(Field field, HelixStringLength referenceValue) {
public OfLengthConstraint(Field field, HelixStringLength referenceValue) {
this.referenceValue = referenceValue;
this.field = field;
}
Expand All @@ -55,7 +55,7 @@ public boolean equals(Object o){
return o.equals(this);
}
if (o == null || getClass() != o.getClass()) return false;
StringHasLengthConstraint constraint = (StringHasLengthConstraint) o;
OfLengthConstraint constraint = (OfLengthConstraint) o;
return Objects.equals(field, constraint.field) && Objects.equals(referenceValue.getValue(), constraint.referenceValue.getValue());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

import java.util.Objects;

public class IsStringShorterThanConstraint implements AtomicConstraint {
public class ShorterThanConstraint implements AtomicConstraint {
public final Field field;
public final HelixStringLength referenceValue;

public IsStringShorterThanConstraint(Field field, HelixStringLength referenceValue) {
public ShorterThanConstraint(Field field, HelixStringLength referenceValue) {
this.referenceValue = referenceValue;
this.field = field;
}
Expand All @@ -40,7 +40,7 @@ public Field getField() {

@Override
public AtomicConstraint negate() {
return new IsStringLongerThanConstraint(field, HelixStringLength.create(referenceValue.getValue() - 1));
return new LongerThanConstraint(field, HelixStringLength.create(referenceValue.getValue() - 1));
}

@Override
Expand All @@ -55,7 +55,7 @@ public boolean equals(Object o){
return o.equals(this);
}
if (o == null || getClass() != o.getClass()) return false;
IsStringShorterThanConstraint constraint = (IsStringShorterThanConstraint) o;
ShorterThanConstraint constraint = (ShorterThanConstraint) o;
return Objects.equals(field, constraint.field) && Objects.equals(referenceValue, constraint.referenceValue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public ConstraintChainBuilder<T> withInSetConstraint(Field field, Object[] legal
}

public ConstraintChainBuilder<T> withOfLengthConstraint(Field fooField, int length) {
return saveAndSet(new StringHasLengthConstraint(fooField, HelixStringLength.create(length)));
return saveAndSet(new OfLengthConstraint(fooField, HelixStringLength.create(length)));
}

public ConstraintChainBuilder<T> withAfterConstraint(Field field, OffsetDateTime dateTime) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@

import com.scottlogic.deg.common.profile.Field;
import com.scottlogic.deg.common.profile.HelixStringLength;
import com.scottlogic.deg.generator.fieldspecs.FieldSpec;
import com.scottlogic.deg.generator.fieldspecs.RestrictionsFieldSpec;
import com.scottlogic.deg.generator.profile.constraints.atomic.IsStringLongerThanConstraint;
import com.scottlogic.deg.generator.profile.constraints.atomic.IsStringShorterThanConstraint;
import com.scottlogic.deg.generator.profile.constraints.atomic.StringHasLengthConstraint;
import com.scottlogic.deg.generator.profile.constraints.atomic.LongerThanConstraint;
import com.scottlogic.deg.generator.profile.constraints.atomic.ShorterThanConstraint;
import com.scottlogic.deg.generator.profile.constraints.atomic.OfLengthConstraint;
import com.scottlogic.deg.generator.profile.constraints.atomic.ViolatedAtomicConstraint;
import org.junit.jupiter.api.Test;

Expand All @@ -34,7 +33,7 @@ class ConstraintToFieldSpecTests {

@Test
void construct_stringHasLengthConstraintRetrievedTwice_returnsTheSameGeneratorInstance() {
StringHasLengthConstraint constraint = new StringHasLengthConstraint(testField, HelixStringLength.create(10));
OfLengthConstraint constraint = new OfLengthConstraint(testField, HelixStringLength.create(10));

final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec)constraint.toFieldSpec();
final RestrictionsFieldSpec secondInstance = (RestrictionsFieldSpec)constraint.toFieldSpec();
Expand All @@ -44,7 +43,7 @@ void construct_stringHasLengthConstraintRetrievedTwice_returnsTheSameGeneratorIn

@Test
void construct_stringHasLengthConstraintViolatedTwice_returnsTheSameGeneratorInstance() {
ViolatedAtomicConstraint constraint = new ViolatedAtomicConstraint(new StringHasLengthConstraint(testField,HelixStringLength.create(10)));
ViolatedAtomicConstraint constraint = new ViolatedAtomicConstraint(new OfLengthConstraint(testField,HelixStringLength.create(10)));

final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) constraint.toFieldSpec();
final RestrictionsFieldSpec secondInstance = (RestrictionsFieldSpec) constraint.toFieldSpec();
Expand All @@ -54,8 +53,8 @@ void construct_stringHasLengthConstraintViolatedTwice_returnsTheSameGeneratorIns

@Test
void construct_twoInstancesOfStringHasLengthConstraintCalledWithEqualValues_returnsTheSameGeneratorInstance() {
StringHasLengthConstraint firstConstraint = new StringHasLengthConstraint(testField,HelixStringLength.create(20));
StringHasLengthConstraint secondConstraint = new StringHasLengthConstraint( testField, HelixStringLength.create(20));
OfLengthConstraint firstConstraint = new OfLengthConstraint(testField,HelixStringLength.create(20));
OfLengthConstraint secondConstraint = new OfLengthConstraint( testField, HelixStringLength.create(20));

final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) firstConstraint.toFieldSpec();
final RestrictionsFieldSpec secondInstance = (RestrictionsFieldSpec) secondConstraint.toFieldSpec();
Expand All @@ -65,7 +64,7 @@ void construct_twoInstancesOfStringHasLengthConstraintCalledWithEqualValues_retu

@Test
void construct_isStringLongerThanConstraintRetrievedTwice_returnsTheSameGeneratorInstance() {
IsStringLongerThanConstraint constraint = new IsStringLongerThanConstraint(testField, HelixStringLength.create(15));
LongerThanConstraint constraint = new LongerThanConstraint(testField, HelixStringLength.create(15));

final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) constraint.toFieldSpec();
final RestrictionsFieldSpec secondInstance = (RestrictionsFieldSpec) constraint.toFieldSpec();
Expand All @@ -76,7 +75,7 @@ void construct_isStringLongerThanConstraintRetrievedTwice_returnsTheSameGenerato
@Test
void construct_isStringLongerThanConstraintViolatedTwice_returnsTheSameGeneratorInstance() {
ViolatedAtomicConstraint constraint = new ViolatedAtomicConstraint(
new IsStringLongerThanConstraint( testField,HelixStringLength.create(10))
new LongerThanConstraint( testField,HelixStringLength.create(10))
);

final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) constraint.toFieldSpec();
Expand All @@ -87,8 +86,8 @@ void construct_isStringLongerThanConstraintViolatedTwice_returnsTheSameGenerator

@Test
void construct_twoInstancesOfIsStringLongerThanConstraintCalledWithEqualValues_returnsTheSameGeneratorInstance() {
IsStringLongerThanConstraint firstConstraint = new IsStringLongerThanConstraint(testField, HelixStringLength.create(20));
IsStringLongerThanConstraint secondConstraint = new IsStringLongerThanConstraint(testField, HelixStringLength.create(20));
LongerThanConstraint firstConstraint = new LongerThanConstraint(testField, HelixStringLength.create(20));
LongerThanConstraint secondConstraint = new LongerThanConstraint(testField, HelixStringLength.create(20));

final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) firstConstraint.toFieldSpec();
final RestrictionsFieldSpec secondInstance = (RestrictionsFieldSpec) secondConstraint.toFieldSpec();
Expand All @@ -98,7 +97,7 @@ void construct_twoInstancesOfIsStringLongerThanConstraintCalledWithEqualValues_r

@Test
void construct_isStringShorterThanConstraintRetrievedTwice_returnsTheSameGeneratorInstance() {
IsStringShorterThanConstraint constraint = new IsStringShorterThanConstraint(testField, HelixStringLength.create(25));
ShorterThanConstraint constraint = new ShorterThanConstraint(testField, HelixStringLength.create(25));

final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) constraint.toFieldSpec();
final RestrictionsFieldSpec secondInstance = (RestrictionsFieldSpec) constraint.toFieldSpec();
Expand All @@ -109,7 +108,7 @@ void construct_isStringShorterThanConstraintRetrievedTwice_returnsTheSameGenerat
@Test
void construct_isStringShorterThanConstraintViolatedTwice_returnsTheSameGeneratorInstance() {
ViolatedAtomicConstraint constraint = new ViolatedAtomicConstraint(
new IsStringShorterThanConstraint(testField, HelixStringLength.create(10))
new ShorterThanConstraint(testField, HelixStringLength.create(10))
);

final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) constraint.toFieldSpec();
Expand All @@ -120,8 +119,8 @@ void construct_isStringShorterThanConstraintViolatedTwice_returnsTheSameGenerato

@Test
void construct_twoInstancesOfIsStringShorterThanConstraintCalledWithEqualValues_returnsTheSameGeneratorInstance() {
IsStringShorterThanConstraint firstConstraint = new IsStringShorterThanConstraint(testField, HelixStringLength.create(20));
IsStringShorterThanConstraint secondConstraint = new IsStringShorterThanConstraint(testField, HelixStringLength.create(20));
ShorterThanConstraint firstConstraint = new ShorterThanConstraint(testField, HelixStringLength.create(20));
ShorterThanConstraint secondConstraint = new ShorterThanConstraint(testField, HelixStringLength.create(20));

final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) firstConstraint.toFieldSpec();
final RestrictionsFieldSpec secondInstance = (RestrictionsFieldSpec) secondConstraint.toFieldSpec();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import com.scottlogic.deg.generator.fieldspecs.FieldSpecMerger;
import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList;
import com.scottlogic.deg.generator.generation.databags.DataBagValue;
import com.scottlogic.deg.generator.profile.constraints.atomic.IsStringLongerThanConstraint;
import com.scottlogic.deg.generator.profile.constraints.atomic.IsStringShorterThanConstraint;
import com.scottlogic.deg.generator.profile.constraints.atomic.LongerThanConstraint;
import com.scottlogic.deg.generator.profile.constraints.atomic.ShorterThanConstraint;
import com.scottlogic.deg.generator.reducer.ConstraintReducer;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -68,7 +68,7 @@ class TreePrunerTests {
public void pruneConstraintNode_leafNodeContradictionsWithParent_returnsContradictory() {
//Arrange
Set<Object> inputWhitelist = new HashSet<>(Arrays.asList("a", "b"));
ConstraintNode tree = new ConstraintNodeBuilder().addAtomicConstraints(new IsStringLongerThanConstraint(field, HelixStringLength.create(5))).build();
ConstraintNode tree = new ConstraintNodeBuilder().addAtomicConstraints(new LongerThanConstraint(field, HelixStringLength.create(5))).build();
FieldSpec inputFieldSpec = FieldSpecFactory.fromList(DistributedList.uniform(inputWhitelist))
.withNotNull();

Expand All @@ -87,7 +87,7 @@ public void pruneConstraintNode_leafNodeContradictionsWithParent_returnsContradi
public void pruneConstraintNode_leafNodeNoContradictionsWithParent_returnsLeafNode() {
//Arrange
Set<Object> inputWhitelist = new HashSet<>(Arrays.asList("a", "b"));
ConstraintNode tree = new ConstraintNodeBuilder().addAtomicConstraints(new IsStringShorterThanConstraint(field, HelixStringLength.create(5))).build();
ConstraintNode tree = new ConstraintNodeBuilder().addAtomicConstraints(new ShorterThanConstraint(field, HelixStringLength.create(5))).build();
FieldSpec inputFieldSpec = FieldSpecFactory.fromList(
(DistributedList.uniform(inputWhitelist)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ public Class toConstraintClass(ConstraintType type) {
case CONTAINS_REGEX:
return ContainsRegexConstraint.class;
case OF_LENGTH:
return StringHasLengthConstraint.class;
return OfLengthConstraint.class;
case LONGER_THAN:
return IsStringLongerThanConstraint.class;
return LongerThanConstraint.class;
case SHORTER_THAN:
return IsStringShorterThanConstraint.class;
return ShorterThanConstraint.class;
case GREATER_THAN:
return GreaterThanConstraint.class;
case GREATER_THAN_OR_EQUAL_TO:
return GreaterThanOrEqualToConstraint.class;
case LESS_THAN:
return LessThanConstraint.class;
case LESS_THAN_OR_EQUAL_TO:
return IsLessThanOrEqualToConstantConstraint.class;
return LessThanOrEqualToConstraint.class;
case AFTER:
return AfterConstraint.class;
case AFTER_OR_AT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private ConstraintDTO createConstraint(String fieldName, ConstraintType type, Ob
values = (Collection<Object>) _value;
}};
case IS_NULL:
return new NullConstraintDTO() {{
return new IsNullConstraintDTO() {{
field = fieldName;
isNull = (boolean) _value;
}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ private static Stream<Arguments> allAtomicConstraints() {

Arguments.of(ContainsRegexConstraint.class, Pattern.compile("\\w+")),
Arguments.of(MatchesRegexConstraint.class, Pattern.compile("\\d+")),
Arguments.of(IsStringLongerThanConstraint.class, HelixStringLength.create(10)),
Arguments.of(IsStringShorterThanConstraint.class, HelixStringLength.create(20)),
Arguments.of(StringHasLengthConstraint.class, HelixStringLength.create(15)),
Arguments.of(LongerThanConstraint.class, HelixStringLength.create(10)),
Arguments.of(ShorterThanConstraint.class, HelixStringLength.create(20)),
Arguments.of(OfLengthConstraint.class, HelixStringLength.create(15)),

Arguments.of(AfterConstraint.class, HelixDateTime.create(sampleDate)),
Arguments.of(AfterOrAtConstraint.class, HelixDateTime.create(sampleDate.plusDays(1))),
Expand All @@ -98,7 +98,7 @@ private static Stream<Arguments> allAtomicConstraints() {
Arguments.of(GreaterThanConstraint.class, HelixNumber.create(100)),
Arguments.of(GreaterThanOrEqualToConstraint.class, HelixNumber.create(200)),
Arguments.of(LessThanConstraint.class, HelixNumber.create(300)),
Arguments.of(IsLessThanOrEqualToConstantConstraint.class, HelixNumber.create(400))
Arguments.of(LessThanOrEqualToConstraint.class, HelixNumber.create(400))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package com.scottlogic.deg.orchestrator.violation;

import com.scottlogic.deg.common.profile.HelixStringLength;
import com.scottlogic.deg.generator.profile.constraints.atomic.IsStringShorterThanConstraint;
import com.scottlogic.deg.generator.profile.constraints.atomic.StringHasLengthConstraint;
import com.scottlogic.deg.generator.profile.constraints.atomic.ShorterThanConstraint;
import com.scottlogic.deg.generator.profile.constraints.atomic.OfLengthConstraint;
import com.scottlogic.deg.generator.violations.filters.ConstraintTypeViolationFilter;
import com.scottlogic.deg.generator.violations.filters.ViolationFilter;
import com.scottlogic.deg.orchestrator.violate.AtomicConstraintTypeMapper;
Expand Down Expand Up @@ -72,11 +72,11 @@ void hasLengthConstraintsToViolate_ReturnsOneFilter_ThatDoesNotAcceptHasLengthCo


assertThat(filter.canViolate(
new StringHasLengthConstraint(null, HelixStringLength.create(2))),
new OfLengthConstraint(null, HelixStringLength.create(2))),
is(false));

assertThat(filter.canViolate(
new IsStringShorterThanConstraint(null, HelixStringLength.create(5))),
new ShorterThanConstraint(null, HelixStringLength.create(5))),
is(true));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
import com.scottlogic.deg.profile.common.ConstraintType;
import com.scottlogic.deg.profile.common.ConstraintTypeJsonProperty;

@JsonDeserialize(as = NullConstraintDTO.class)
public class NullConstraintDTO extends AtomicConstraintDTO {
@JsonDeserialize(as = IsNullConstraintDTO.class)
public class IsNullConstraintDTO extends AtomicConstraintDTO {
@JsonProperty(ConstraintTypeJsonProperty.IS_NULL)
public boolean isNull;

public NullConstraintDTO() {
public IsNullConstraintDTO() {
super(ConstraintType.IS_NULL);
}
}
Loading

0 comments on commit 4a6ffd6

Please sign in to comment.