Commit 17d9c91b authored by Daniel Le Berre's avatar Daniel Le Berre

Another fix for #151. Need to go through the whole type hierarchy to

retrieve all private fields.
parent 20c8f7f7
Pipeline #3653 passed with stages
in 40 minutes and 45 seconds
...@@ -126,18 +126,24 @@ public class SolverStats implements Serializable { ...@@ -126,18 +126,24 @@ public class SolverStats implements Serializable {
public Map<String, Number> toMap() { public Map<String, Number> toMap() {
Map<String, Number> map = new HashMap<String, Number>(); Map<String, Number> map = new HashMap<String, Number>();
for (Field f : this.getClass().getDeclaredFields()) { Class<?> clazz = this.getClass();
try { do {
Object value = f.get(this); for (Field f : clazz.getDeclaredFields()) {
if (value instanceof Number) { try {
map.put(f.getName(), (Number) value); f.setAccessible(true);
Object value = f.get(this);
if (!"serialVersionUID".equals(f.getName())
&& value instanceof Number) {
map.put(f.getName(), (Number) value);
}
} catch (IllegalArgumentException e) {
// ignores silently
} catch (IllegalAccessException e) {
// ignores silently
} }
} catch (IllegalArgumentException e) {
// ignores silently
} catch (IllegalAccessException e) {
// ignores silently
} }
} clazz = clazz.getSuperclass();
} while (clazz != null);
return map; return map;
} }
......
...@@ -21,9 +21,9 @@ public class BugSAT151 { ...@@ -21,9 +21,9 @@ public class BugSAT151 {
solver.newVar(3); solver.newVar(3);
solver.addAtMost(lits, 2); solver.addAtMost(lits, 2);
assertTrue(solver.getStat().keySet().size() > 0); assertTrue(solver.getStat().keySet().size() >= 17);
solver.isSatisfiable(); solver.isSatisfiable();
assertTrue(solver.getStat().keySet().size() > 0); assertTrue(solver.getStat().keySet().size() >= 17);
} }
......
package org.sat4j.pb;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.sat4j.core.VecInt;
import org.sat4j.specs.ContradictionException;
import org.sat4j.specs.IVecInt;
import org.sat4j.specs.TimeoutException;
public class BugSAT151 {
@Test
public void testNonEmptyStats()
throws ContradictionException, TimeoutException {
IVecInt lits = new VecInt(new int[] { 1, 2, 3 });
IPBSolver solver = SolverFactory.newDefault();
solver.newVar(3);
solver.addAtMost(lits, 2);
assertTrue(solver.getStat().keySet().size() >= 31);
solver.isSatisfiable();
assertTrue(solver.getStat().keySet().size() >= 31);
}
}
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