Commit 2e554245 authored by Vladislav Kiselev's avatar Vladislav Kiselev

Добавлено тестирование типизированных тестов, исправлено оформление.

parent c8542a5d
......@@ -69,7 +69,7 @@ public class Berth {
@Override
public String toString() {
return id + ";" + name;
return id + "; " + name;
}
public Berth(String s) {
......
......@@ -79,7 +79,7 @@ public class Cargo {
@Override
public String toString() {
return id + ";" + name + ";" + cost;
return id + "; " + name + "; " + cost;
}
public Cargo(String s) {
......
......@@ -117,7 +117,7 @@ public class CargoFlow {
res += s + ":" + flow.get(s);
first = false;
}
return storage.getId() + ";[" + res +"]";
return storage.getId() + "; [" + res +"]";
}
public CargoFlow(String s, Map<Integer, Storage> mp, Map<Integer, Cargo> cp) {
......
......@@ -1175,12 +1175,6 @@ public class ConversionUtil {
}
}
private static class OperationsComparator implements Comparator<Operation> {
public int compare(Operation op1, Operation op2) {
return Double.compare(op1.getStart(), op2.getStart());
}
}
public static void resolveMiniZincResults(TaskCase task, String fileName) {
ArrayList<Operation> operations = null;
Integer result = null;
......@@ -1330,8 +1324,6 @@ public class ConversionUtil {
}
}
}
operations.sort(new OperationsComparator());
task.setSolution(operations);
task.setSolution_result(result);
} catch (IOException e) {
......
......@@ -32,8 +32,8 @@ public class LoadingEquipment extends MovingObject{
public LoadingEquipment(String s) {
super(s);
String[] tokens = s.split(";");
if (tokens.length >= 4) {
setType(OptionalInt.of(Integer.parseInt(tokens[3].trim())));
if (tokens.length >= 3) {
setType(OptionalInt.of(Integer.parseInt(tokens[2].trim())));
}
}
......
......@@ -125,7 +125,7 @@ public class LoadingTemplate extends OperationTemplate {
}
for (Integer t : getResourcesTypes()) {
if (!first)
res += "," + t;
res += ", " + t;
else
res += t;
first = false;
......
......@@ -5,9 +5,7 @@ import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;
import static inport.Testing.solveTask_1;
import static inport.Testing.solveTask_2;
import static inport.Testing.test_1;
import static inport.Testing.*;
import inport.ConversionUtil.*;
public class Main {
......@@ -117,7 +115,7 @@ public class Main {
break;
}
case "testing" :
test_1();
test_2();
break;
default:
System.out.println("Unknown type \"" + type + "\"");
......
......@@ -64,7 +64,7 @@ public class MovingObjectState {
@Override
public String toString() {
return getVessel().getId() + ";" + getLocation().getId();
return getVessel().getId() + "; " + getLocation().getId();
}
......
......@@ -101,7 +101,7 @@ public class Storage {
@Override
public String toString() {
return id + ";" + name + ";" + cargo.getId() + ";" +volume;
return id + "; " + name + "; " + cargo.getId() + "; " +volume;
}
public Storage(String s, Map<Integer, Cargo> cargoes) {
......
......@@ -76,9 +76,9 @@ public class StorageState {
@Override
public String toString() {
if (storage instanceof Storage)
return cargo.getId() + ";" + ((Storage)storage).getId() + ";" + cargoState;
return cargo.getId() + "; " + ((Storage)storage).getId() + "; " + cargoState;
if (storage instanceof TransportShip)
return cargo.getId() + ";" + ((TransportShip)storage).getId() + ";" + cargoState;
return cargo.getId() + "; " + ((TransportShip)storage).getId() + "; " + cargoState;
return "";
}
......
......@@ -662,7 +662,13 @@ public class TaskCase {
Logger.getLogger(TaskCase.class.getName()).log(Level.SEVERE, null, ex);
}
}
private static class OperationsComparator implements Comparator<Operation> {
public int compare(Operation op1, Operation op2) {
return Double.compare(op1.getStart(), op2.getStart());
}
}
public void serialize(String fileName)
{
try(FileWriter writer = new FileWriter(fileName, false))
......@@ -670,67 +676,69 @@ public class TaskCase {
// запись всего
writer.write(Tag.Typified.text + "\n" + (isTypified()? "1" : "0") + "\n");
writer.write("Cargoes"+"\n");
writer.write("\nCargoes"+"\n");
for (Cargo c : cargoes)
writer.write(c.toString()+"\n");
writer.write("Berths"+"\n");
writer.write("\nBerths"+"\n");
for (Berth c : berths)
writer.write(c.toString()+"\n");
writer.write("Storages"+"\n");
writer.write("\nStorages"+"\n");
for (Storage c : storages) {
writer.write(c.toString() + "\n");
}
if (isTypified()) {
writer.write(Tag.Vessel_Types.text + "\n");
writer.write("\n" + Tag.Vessel_Types.text + "\n");
for (Map.Entry<Integer, String> e : vesselTypes.entrySet()) {
writer.write(e.getKey() + "; " + e.getValue() + "\n");
}
}
writer.write("Bunkers"+"\n");
writer.write("\nBunkers"+"\n");
for (Bunker c : bunkers)
writer.write(c.toString()+"\n");
writer.write("Tows"+"\n");
writer.write("\nTows"+"\n");
for (Tow c : tows) {
writer.write(c.toString() + "\n");
}
if (isTypified()) {
writer.write(Tag.Loading_Equipment_Types.text + "\n");
writer.write("\n" + Tag.Loading_Equipment_Types.text + "\n");
for (Map.Entry<Integer, String> e : equipmentTypes.entrySet()) {
writer.write(e.getKey() + "; " + e.getValue() + "\n");
}
}
writer.write("Loading Equipments"+"\n");
writer.write("\nLoading Equipments"+"\n");
for (LoadingEquipment c : equipments)
writer.write(c.toString()+"\n");
writer.write("Transport Ships"+"\n");
writer.write("\nTransport Ships"+"\n");
for (TransportShip c : ships)
writer.write(c.toString()+"\n");
writer.write("\n");
writer.write("Templates"+"\n");
writer.write("\nTemplates"+"\n");
for (OperationTemplate c : templates)
writer.write(c.toString()+"\n");
writer.write("\n");
writer.write("Cargo Flows"+"\n");
writer.write("\nCargo Flows"+"\n");
for (CargoFlow c : cargoFlows)
writer.write(c.toString()+"\n");
writer.write("Initial Vessel State"+"\n");
writer.write("\nInitial Vessel State"+"\n");
for (MovingObjectState c : vesselInitialState)
writer.write(c.toString()+"\n");
writer.write("Initial Storage State"+"\n");
writer.write("\nInitial Storage State"+"\n");
for (StorageState c : storageInitialState)
writer.write(c.toString()+"\n");
writer.write("Final Vessel State"+"\n");
writer.write("\nFinal Vessel State"+"\n");
for (MovingObjectState c : vesselEndState)
writer.write(c.toString()+"\n");
writer.write("Final Storage State"+"\n");
writer.write("\nFinal Storage State"+"\n");
for (StorageState c : storageEndState)
writer.write(c.toString()+"\n");
writer.write("\n");
writer.write("Task Properties"+"\n");
writer.write(planningInterval+";"+criterionType+"\n");
writer.write("\nTask Properties"+"\n");
writer.write(planningInterval+"; "+criterionType+"\n");
writer.write("\n");
writer.write("Solution"+"\n");
writer.write("\nSolution"+"\n");
writer.write(solution_result+"\n");
solution.sort(new OperationsComparator());
for (Operation c : solution)
writer.write(c.toString()+"\n");
writer.flush();
......
......@@ -3,6 +3,7 @@ package inport;
import java.io.*;
import java.util.ArrayList;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Collectors;
public class Testing {
......@@ -71,12 +72,12 @@ public class Testing {
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
String output = br.lines().collect(Collectors.joining("\n"));
BufferedReader br2 = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String errors = br.lines().collect(Collectors.joining("\n"));
// BufferedReader br2 = new BufferedReader(new InputStreamReader(process.getErrorStream()));
// String errors = br.lines().collect(Collectors.joining("\n"));
System.out.println("output : " + output);
System.out.println("errors : " + errors);
// System.out.println("output : " + output);
// System.out.println("errors : " + errors);
if (output.trim().equals("=====UNSATISFIABLE=====")) {
task.setSolution(new ArrayList<>());
......@@ -92,7 +93,7 @@ public class Testing {
return "";
}
public static String testCase(String file) {
private static String testCase(String file, Function<TaskCase, String> solver) {
TaskCase task = new TaskCase();
try {
task.deserialize(file);
......@@ -100,7 +101,7 @@ public class Testing {
return "Error : " + e.getMessage();
}
double expected_result = task.getSolution_result();
String error = solveTask_1(task);
String error = solver.apply(task);
double result = task.getSolution_result();
if (!error.isEmpty()) {
return "Error : " + error;
......@@ -111,8 +112,8 @@ public class Testing {
return "OK";
}
public static void test_1() {
File testDir = new File("tests/without_typing/");
public static void testGroup(String group, Function<TaskCase, String> solver) {
File testDir = new File("tests/" + group + "/");
System.out.println(testDir.toString() + " :");
int nPassedTests = 0;
......@@ -122,7 +123,7 @@ public class Testing {
long start = System.currentTimeMillis();
String res = testCase(testDir.toString() + "/" + file.getName());
String res = testCase(testDir.toString() + "/" + file.getName(), solver);
long finish = System.currentTimeMillis();
System.out.println(" " + res + ", " + (finish - start) + " ms");
......@@ -132,4 +133,12 @@ public class Testing {
}
System.out.println("Passed tests : " + nPassedTests + "/" + testDir.listFiles().length);
}
public static void test_1() {
testGroup("without_typing", Testing::solveTask_1);
}
public static void test_2() {
testGroup("with_typing", Testing::solveTask_2);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment