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

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

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