use of nars.util.NALTest in project narchy by automenta.
the class NARTestOptimize method test.
private static float test(Supplier<NAR> s, Method m) {
try {
NALTest t = (NALTest) m.getDeclaringClass().getConstructor().newInstance();
// overwrite NAR with the supplier
t.nar = s.get();
t.nar.random().setSeed(System.nanoTime());
m.invoke(t);
try {
Param.DEBUG = false;
t.test.test(false);
return t.test.score;
// return 1 + t.test.score; //+1 for successful completion
} catch (Throwable ee) {
// return -2f;
return 0f;
}
} catch (Exception e) {
e.printStackTrace();
return 0f;
}
}
use of nars.util.NALTest in project narchy by automenta.
the class NARTestOptimize method tests.
/**
* HACK runs all Junit test methods, summing the scores.
* TODO use proper JUnit5 test runner api but it is a mess to figure out right now
*/
static float tests(Supplier<NAR> s, Class<? extends NALTest>... c) {
List<Method> methods = Stream.of(c).flatMap(cc -> Stream.of(cc.getMethods()).filter(x -> x.getAnnotation(Test.class) != null)).collect(toList());
final CountDownLatch remain = new CountDownLatch(methods.size());
final AtomicDouble sum = new AtomicDouble(0);
methods.forEach(m -> {
exe.submit(() -> {
try {
sum.addAndGet(test(s, m));
} finally {
remain.countDown();
}
});
});
try {
remain.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
return sum.floatValue();
}
Aggregations