From 5b86874e0ce913fee763a833880c7fd095424609 Mon Sep 17 00:00:00 2001 From: Johanna Stuber Date: Sun, 7 Mar 2021 22:20:18 +0100 Subject: [PATCH] new line after each 10 constraints --- .../latexcreator/LatexCreatorConstraints.java | 36 ++++++++++++++----- .../LatexCreatorConstraintsTest.java | 17 +++++---- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/LatexCreatorConstraints.java b/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/LatexCreatorConstraints.java index 701d257..aae2285 100644 --- a/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/LatexCreatorConstraints.java +++ b/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/LatexCreatorConstraints.java @@ -24,6 +24,7 @@ import static edu.kit.typicalc.view.content.typeinferencecontent.latexcreator.La public class LatexCreatorConstraints implements StepVisitor { private static final String FIRST_PREFIX = ""; + private static final int BREAK_AFTER = 10; private final List constraints; private final TypeInfererInterface typeInferer; @@ -35,6 +36,7 @@ public class LatexCreatorConstraints implements StepVisitor { private final Optional> newTypeAssumption; private String prevStep; private final Function translationProvider; + private int constraintsInCurrLine; /** * Initializes the LatexCreatorConstraints with the right values calculates the strings @@ -66,6 +68,7 @@ public class LatexCreatorConstraints implements StepVisitor { this.constraintSetIndex = constraintSetIndexFactory.nextConstraintSetIndex(); this.typeInferer = typeInferer; this.translationProvider = translationProvider; + this.constraintsInCurrLine = 0; constraints = new ArrayList<>(); if (FIRST_PREFIX.equals(prefix)) { constraints.add(AMPERSAND + CONSTRAINT_SET + EQUALS + LATEX_CURLY_LEFT + LATEX_CURLY_RIGHT); @@ -132,12 +135,21 @@ public class LatexCreatorConstraints implements StepVisitor { } private void addConstraint(InferenceStep step) { - String currentConstraint = createSingleConstraint(step.getConstraint()); - prevStep = prevStep.equals("") ? currentConstraint : prevStep + COMMA + currentConstraint; - currentConstraint = prefix + AMPERSAND + CONSTRAINT_SET + constraintSetIndex + EQUALS + LATEX_CURLY_LEFT - + prevStep + LATEX_CURLY_RIGHT; - constraints.add(currentConstraint); + String currentSingleConstraint = createSingleConstraint(step.getConstraint()); + if (!prevStep.equals("")) { + prevStep += COMMA; + } + if (constraintsInCurrLine >= BREAK_AFTER) { + prevStep += LATEX_NEW_LINE + AMPERSAND; + constraintsInCurrLine = 0; + } + prevStep += currentSingleConstraint; + + String currentConstraints = prefix + AMPERSAND + SPLIT_BEGIN + CONSTRAINT_SET + constraintSetIndex + + EQUALS + LATEX_CURLY_LEFT + AMPERSAND + prevStep + LATEX_CURLY_RIGHT + SPLIT_END; + constraints.add(currentConstraints); numberGenerator.incrementPush(); + constraintsInCurrLine++; } @Override @@ -195,8 +207,8 @@ public class LatexCreatorConstraints implements StepVisitor { // adds one step in which all let constraints are added to 'outer' constraint set String letConstraints = createLetConstraints(letD.getTypeInferer().getLetConstraints()); prevStep = prevStep.equals("") ? letConstraints : prevStep + COMMA + letConstraints; - letConstraints = prefix + AMPERSAND + CONSTRAINT_SET + constraintSetIndex + EQUALS + LATEX_CURLY_LEFT - + prevStep + LATEX_CURLY_RIGHT; + letConstraints = prefix + AMPERSAND + SPLIT_BEGIN + CONSTRAINT_SET + constraintSetIndex + EQUALS + + LATEX_CURLY_LEFT + AMPERSAND + prevStep + LATEX_CURLY_RIGHT + SPLIT_END; constraints.add(letConstraints); numberGenerator.push(); @@ -205,7 +217,15 @@ public class LatexCreatorConstraints implements StepVisitor { private String createLetConstraints(List letConstraints) { StringBuilder result = new StringBuilder(); - letConstraints.forEach(constraint -> result.append(createSingleConstraint(constraint)).append(COMMA)); + letConstraints.forEach(constraint -> { + if (constraintsInCurrLine >= BREAK_AFTER) { + result.append(LATEX_NEW_LINE) + .append(AMPERSAND); + constraintsInCurrLine = 0; + } + result.append(createSingleConstraint(constraint)).append(COMMA); + constraintsInCurrLine++; + }); if (!letConstraints.isEmpty()) { result.deleteCharAt(result.length() - 1); } diff --git a/src/test/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/LatexCreatorConstraintsTest.java b/src/test/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/LatexCreatorConstraintsTest.java index 14ef53d..9ea2401 100644 --- a/src/test/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/LatexCreatorConstraintsTest.java +++ b/src/test/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/LatexCreatorConstraintsTest.java @@ -26,8 +26,9 @@ class LatexCreatorConstraintsTest { typeInferer = model.getTypeInferer("x", new HashMap<>()).unwrap(); List actual = new LatexCreatorConstraints(typeInferer, Enum::toString).getEverything(); - String constraintSet = AMPERSAND + CONSTRAINT_SET + EQUALS + LATEX_CURLY_LEFT + TREE_VARIABLE + "_{1}" + EQUALS - + GENERATED_ASSUMPTION_VARIABLE + "_{1}" + LATEX_CURLY_RIGHT; + String constraintSet = AMPERSAND + SPLIT_BEGIN + CONSTRAINT_SET + EQUALS + LATEX_CURLY_LEFT + AMPERSAND + + TREE_VARIABLE + "_{1}" + EQUALS + GENERATED_ASSUMPTION_VARIABLE + "_{1}" + LATEX_CURLY_RIGHT + + SPLIT_END; String mgu = "" + EQUALS + BRACKET_LEFT + AMPERSAND + TREE_VARIABLE + "_{1}" @@ -55,12 +56,14 @@ class LatexCreatorConstraintsTest { typeInferer = model.getTypeInferer("λx.y", new HashMap<>()).unwrap(); List actual = new LatexCreatorConstraints(typeInferer, Enum::toString).getEverything(); - String constraintSet1 = AMPERSAND + CONSTRAINT_SET + EQUALS + LATEX_CURLY_LEFT + TREE_VARIABLE + "_{1}" + EQUALS - + TREE_VARIABLE + "_{2}" + SPACE + RIGHT_ARROW + SPACE + TREE_VARIABLE + "_{3}" + LATEX_CURLY_RIGHT; + String constraintSet1 = AMPERSAND + SPLIT_BEGIN + CONSTRAINT_SET + EQUALS + LATEX_CURLY_LEFT + AMPERSAND + + TREE_VARIABLE + "_{1}" + EQUALS + TREE_VARIABLE + "_{2}" + SPACE + RIGHT_ARROW + SPACE + + TREE_VARIABLE + "_{3}" + LATEX_CURLY_RIGHT + SPLIT_END; - String constraintSet2 = AMPERSAND + CONSTRAINT_SET + EQUALS + LATEX_CURLY_LEFT + TREE_VARIABLE + "_{1}" + EQUALS - + TREE_VARIABLE + "_{2}" + SPACE + RIGHT_ARROW + SPACE + TREE_VARIABLE + "_{3}" + COMMA + TREE_VARIABLE - + "_{3}" + EQUALS + GENERATED_ASSUMPTION_VARIABLE + "_{1}" + LATEX_CURLY_RIGHT; + String constraintSet2 = AMPERSAND + SPLIT_BEGIN + CONSTRAINT_SET + EQUALS + LATEX_CURLY_LEFT + AMPERSAND + + TREE_VARIABLE + "_{1}" + EQUALS + TREE_VARIABLE + "_{2}" + SPACE + RIGHT_ARROW + SPACE + + TREE_VARIABLE + "_{3}" + COMMA + TREE_VARIABLE + "_{3}" + EQUALS + GENERATED_ASSUMPTION_VARIABLE + + "_{1}" + LATEX_CURLY_RIGHT + SPLIT_END; String unify1 = MGU_START + EQUALS + UNIFY + PAREN_LEFT + LATEX_CURLY_LEFT + AMPERSAND + TREE_VARIABLE + "_{3}" + EQUALS + GENERATED_ASSUMPTION_VARIABLE + "_{1}";