Skip to content

Commit c501f08

Browse files
committed
fixed validateSuccessor messages
1 parent e022a60 commit c501f08

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

src/main/java/net/itarray/automotion/internal/UIElement.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import net.itarray.automotion.internal.geometry.Rectangle;
88
import net.itarray.automotion.internal.geometry.Scalar;
99
import net.itarray.automotion.internal.geometry.Vector;
10-
import net.itarray.automotion.internal.properties.ConstantExpression;
1110
import net.itarray.automotion.internal.properties.Context;
1211
import net.itarray.automotion.tools.general.SystemHelper;
1312
import net.itarray.automotion.tools.helpers.TextFinder;
@@ -337,15 +336,14 @@ public void validateIsAbove(UIElement element, Condition<Scalar> condition, Cont
337336

338337
public void validateSuccessor(Direction direction, UIElement toBeValidatedSuccessor, Condition<Scalar> condition, Context context) {
339338
Expression<Scalar> signedDistance = Expression.signedDistance(end(direction), toBeValidatedSuccessor.begin(direction), direction);
340-
if (!condition.isSatisfiedOn(signedDistance, context, direction)) {
341-
context.add(String.format("%s element aligned not properly. Expected margin should be %s. Actual margin is %s",
342-
direction.afterName(),
343-
condition.getDescription(context, direction),
344-
signedDistance.evaluateIn(context, direction).toStringWithUnits(PIXELS)));
339+
Expression<Boolean> assertion = condition.applyTo(signedDistance, direction.afterName() + " element aligned not properly. Expected margin should be %2$s. Actual margin is %4$s");
340+
if (!assertion.evaluateIn(context, direction)) {
341+
context.add(assertion.getDescription(context, direction));
345342
context.draw(toBeValidatedSuccessor);
346343
}
347344
}
348345

346+
349347
public void validateOverlappingWithElement(UIElement element, Context context) {
350348
if (!overlaps(element, context)) {
351349
context.add(String.format("Element %s is not overlapped with element %s but should be",

src/main/java/net/itarray/automotion/internal/properties/ConditionedExpression.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ public class ConditionedExpression<T> implements Expression<Boolean> {
1010

1111
private final Expression<T> toBeConditioned;
1212
private final Condition<T> toBeApplied;
13+
private final String messageFormat;
1314

1415
public ConditionedExpression(Expression<T> toBeConditioned, Condition<T> toBeApplied) {
16+
this(toBeConditioned, toBeApplied, "Expected %1$s to be %2$s. Actual %3$s is: %4$s");
17+
}
18+
19+
public ConditionedExpression(Expression<T> toBeConditioned, Condition<T> toBeApplied, String messageFormat) {
1520
this.toBeConditioned = toBeConditioned;
1621
this.toBeApplied = toBeApplied;
22+
this.messageFormat = messageFormat;
1723
}
1824

1925
@Override
@@ -24,7 +30,7 @@ public <V extends MetricSpace<V>> Boolean evaluateIn(Context context, ExtendGivi
2430
@Override
2531
public <V extends MetricSpace<V>> String getDescription(Context context, ExtendGiving<V> direction) {
2632
T t = toBeConditioned.evaluateIn(context, direction);
27-
return String.format("Expected %s to be %s. Actual %s is: %s",
33+
return String.format(messageFormat,
2834
toBeConditioned.getDescription(context, direction),
2935
toBeApplied.getDescription(context, direction),
3036
toBeConditioned.getRepeatedDescription(context, direction),

src/main/java/net/itarray/automotion/validation/properties/Condition.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,9 @@ default Expression<Boolean> applyTo(Expression<T> toBeConditioned) {
127127
return new ConditionedExpression<>(toBeConditioned, this);
128128
}
129129

130+
default Expression<Boolean> applyTo(Expression<T> toBeConditioned, String messageFormat) {
131+
return new ConditionedExpression<>(toBeConditioned, this, messageFormat);
132+
}
133+
130134
<V extends MetricSpace<V>> String getDescription(Context context, ExtendGiving<V> direction);
131135
}

src/main/java/net/itarray/automotion/validation/properties/Expression.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ static <V extends MetricSpace<V>> Expression<Boolean> equalTo(Expression<V> left
4040
return new BinaryExpression<>(
4141
left,
4242
right,
43-
(scalar, other, context) -> scalar.minus(other).norm().isLessOrEqualTo(context.getTolerance()),
43+
(vector, other, context) -> vector.minus(other).norm().isLessOrEqualTo(context.getTolerance()),
4444
"Expected %1$s to be equal to %2$s.");
4545
}
4646

4747
static <V extends MetricSpace<V>> Expression<V> signedDistance(Expression<V> left, Expression<V> right, ExtendGiving<V> extendGiving) {
4848
return new BinaryExpression<>(
4949
left,
5050
right,
51-
(scalar, other, context) -> extendGiving.signedDistance(scalar, other),
52-
"Expected %1$s to be equal to %2$s.");
51+
(vector, other, context) -> extendGiving.signedDistance(vector, other),
52+
"offset of %1$s from %2$s");
5353
}
5454

5555
<V extends MetricSpace<V>> T evaluateIn(Context context, ExtendGiving<V> direction);

0 commit comments

Comments
 (0)