ModelWriter implements IModelWriter { @Override public String toString() { return allElements().map(Element::declare) .collect(Collectors.joining(System.lineSeparator())); } ModelWriter(IModelBuilder modelBuilder); @Override SolvingStrategy getSolvingStrategy(); @Override void setSolvingStrategy(SolvingStrategy solvingStrategy); @Override @Deprecated OutputStatement getOutputStatement(); @Override @Deprecated void setOutputStatement(OutputStatement outputStatement); @Override String toString(); @Override void toFile(File file); @Override void toOutputStream(OutputStream outputStream); @Override File toTempFile(); @Override Collection<Path> getSearchDirectories();  }
@Test public void testCreateSingleConstantToString() { modelBuilder.add(new IntegerConstant(1).toNamedConstant("i")); String output = modelWriter.toString(); Assert.assertEquals("int: i = 1;", output); }
@Test public void testCreateTwoLinesToString() { BasicInteger i = new IntegerConstant(2).toNamedConstant("i"); Set<Integer> s = new RangeExpression(1, i).toNamedConstant("s"); modelBuilder.add(i, s); String output = modelWriter.toString(); StringBuilder expectedOutput = new StringBuilder(); expectedOutput.append("int: i = 2;"); expectedOutput.append(System.lineSeparator()); expectedOutput.append("set of int: s = 1..i;"); Assert.assertEquals(expectedOutput.toString(), output); }
@Test public void testCreateIntVarToString() { modelBuilder.add(new IntegerVariable("i")); String output = modelWriter.toString(); Assert.assertEquals("var int: i;", output); }
@Test public void testCreateRestrictedIntVarToString() { Set<Integer> setOneTwoThree = new RangeExpression(1, 3).toNamedConstant("OneTwoThree"); IntegerVariable i = new IntegerVariable("i", setOneTwoThree); modelBuilder.add(setOneTwoThree, i); String output = modelWriter.toString(); StringBuilder expectedOutput = new StringBuilder(); expectedOutput.append("set of int: OneTwoThree = 1..3;"); expectedOutput.append(System.lineSeparator()); expectedOutput.append("var OneTwoThree: i;"); Assert.assertEquals(expectedOutput.toString(), output); }
@Test public void testCreateIntArrayConstantToString() { String setRangeName = "Range"; String arrayName = "a"; Set<Integer> setRange = new RangeExpression(1, 3).toNamedConstant(setRangeName); List<Integer> values = Arrays.asList(1, 2, 3); IntegerArray iac = IntegerArray.createConstant(arrayName, new ExplicitIntegerList(setRange, values)); modelBuilder.add(setRange, iac); String output = modelWriter.toString(); StringBuilder expectedOutput = new StringBuilder(); expectedOutput.append("set of int: Range = 1..3;"); expectedOutput.append(System.lineSeparator()); expectedOutput.append( "array[" + setRangeName + "] of int: " + arrayName + " = " + values.toString() + ";"); Assert.assertEquals(expectedOutput.toString(), output); }
@Test public void testCreateIntArrayVarToString() { String setRangeName = "Range"; String arrayName = "a"; Set<Integer> setRange = new RangeExpression(1, 3).toNamedConstant(setRangeName); IntegerArray iav = IntegerArray.createVariable(arrayName, setRange); modelBuilder.add(setRange, iav); String output = modelWriter.toString(); StringBuilder expectedOutput = new StringBuilder(); expectedOutput.append("set of int: Range = 1..3;"); expectedOutput.append(System.lineSeparator()); expectedOutput.append( "array[" + setRangeName + "] of var int: " + arrayName + ";"); Assert.assertEquals(expectedOutput.toString(), output); }