Commit b6b1d75d authored by Daniel Le Berre's avatar Daniel Le Berre

Fix for #156

parent b5b48253
......@@ -31,7 +31,6 @@ package org.sat4j.reader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.Map;
import org.sat4j.specs.ContradictionException;
......@@ -98,6 +97,10 @@ public class InstanceReader extends Reader {
return this.aag;
}
protected String[] getReservedPrefixes() {
return new String[] { "EZCNF" };
}
@Override
public IProblem parseInstance(String filename)
throws ParseFormatException, IOException, ContradictionException {
......@@ -105,17 +108,15 @@ public class InstanceReader extends Reader {
String prefix = "";
if (filename.startsWith("http://")) {
filename = filename.substring(filename.lastIndexOf('/'),
filename.length() - 1);
filename = filename.substring(filename.lastIndexOf('/') + 1);
}
for (String reservedPrefix : getReservedPrefixes()) {
if (filename.startsWith(reservedPrefix + ":")) {
filename = filename.substring(reservedPrefix.length() + 1);
prefix = reservedPrefix;
if (filename.indexOf(':') != -1) {
String[] parts = filename.split(":", 2);
filename = parts[1];
prefix = parts[0].toUpperCase(Locale.getDefault());
}
}
if (filename.endsWith(".gz") || filename.endsWith(".bz2")) {
fname = filename.substring(0, filename.lastIndexOf('.'));
} else {
......
package org.sat4j;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
import org.sat4j.minisat.SolverFactory;
import org.sat4j.reader.InstanceReader;
import org.sat4j.reader.ParseFormatException;
import org.sat4j.reader.Reader;
import org.sat4j.specs.ContradictionException;
public class BugSAT156 {
private InstanceReader instancereader;
private Reader mockedReader;
@Before
public void setUp() {
mockedReader = mock(Reader.class);
instancereader = new InstanceReader(SolverFactory.newDefault(),
mockedReader);
}
@Test
public void testHttpPrefix()
throws ParseFormatException, IOException, ContradictionException {
instancereader.parseInstance("http://path/to/file.cnf");
verify(mockedReader).parseInstance("file.cnf");
}
@Test
public void testWindowsVolume()
throws ParseFormatException, IOException, ContradictionException {
instancereader.parseInstance("j:/myNewBenchmark4711.cnf");
verify(mockedReader).parseInstance("j:/myNewBenchmark4711.cnf");
}
@Test
public void testFixedPrefix()
throws ParseFormatException, IOException, ContradictionException {
instancereader.parseInstance("EZCNF:/path/to/file.cnf");
verify(mockedReader).parseInstance("/path/to/file.cnf");
}
}
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