use of nars.lab.testutils.OutputCondition in project opennars by opennars.
the class NALTest method testNAL.
protected double testNAL(final String path) {
Memory.resetStatic();
final List<OutputCondition> expects = new ArrayList();
NAR n = null;
boolean error = false;
try {
n = newNAR();
String example = getExample(path);
if (showOutput) {
System.out.println(example);
System.out.println();
}
List<OutputCondition> extractedExpects = OutputCondition.getConditions(n, example, similarsToSave);
for (OutputCondition e1 : extractedExpects) expects.add(e1);
if (showOutput)
new TextOutputHandler(n, System.out);
if (showTrace) {
new InferenceLogger(n, System.out);
}
n.addInputFile(path);
n.cycles(minCycles);
} catch (Throwable e) {
System.err.println(e);
if (Parameters.DEBUG) {
e.printStackTrace();
}
error = true;
}
System.err.flush();
System.out.flush();
boolean success = expects.size() > 0 && (!error);
for (OutputCondition e : expects) {
if (!e.succeeded)
success = false;
}
double score = Double.POSITIVE_INFINITY;
if (success) {
long lastSuccess = -1;
for (OutputCondition e : expects) {
if (e.getTrueTime() != -1) {
if (lastSuccess < e.getTrueTime())
lastSuccess = e.getTrueTime();
}
}
if (lastSuccess != -1) {
// score = 1.0 + 1.0 / (1+lastSuccess);
score = lastSuccess;
scores.put(path, score);
}
} else {
scores.put(path, Double.POSITIVE_INFINITY);
}
if ((!success & showFail) || (success && showSuccess)) {
System.err.println('\n' + path + " @" + n.memory.time());
for (OutputCondition e : expects) {
System.err.println(" " + e);
}
}
// System.err.println("Status: " + success + " total=" + expects.size() + " " + expects);
if (requireSuccess)
assertTrue(path, success);
return score;
}
Aggregations