use of nars.NAR in project narchy by automenta.
the class QuestTest method testQuest.
public void testQuest(boolean goalFirst, int timeBetween, int timeAfter) throws Narsese.NarseseException {
// Param.DEBUG = true;
final NAR nar = NARS.tmpEternal();
// nar.log();
AtomicBoolean valid = new AtomicBoolean(false);
if (goalFirst) {
goal(nar);
nar.run(timeBetween);
quest(nar, valid);
} else {
quest(nar, valid);
nar.run(timeBetween);
goal(nar);
}
nar.run(timeAfter);
assertTrue(valid.get());
}
use of nars.NAR in project narchy by automenta.
the class NARTest method testConceptInstancing.
//
// @Test public void testFork() throws Exception {
// NAR a = new Default();
// a.input("b:a.");
// a.input("c:b.");
// a.frame(8);
//
// NAR b = a.fork();
//
// assertEquals(a, b);
//
//
// }
@Test
public void testConceptInstancing() throws Narsese.NarseseException {
NAR n = NARS.tmp();
String statement1 = "<a --> b>.";
Termed a = $.$("a");
assertNotNull(a);
Termed a1 = $.$("a");
assertEquals(a, a1);
n.input(statement1);
n.run(4);
n.input(" <a --> b>. ");
n.run(1);
n.input(" <a--> b>. ");
n.run(1);
String statement2 = "<a --> c>.";
n.input(statement2);
n.run(4);
Termed a2 = $.$("a");
assertNotNull(a2);
Concept ca = n.conceptualize(a2);
assertNotNull(ca);
}
use of nars.NAR in project narchy by automenta.
the class NARTest method testBeforeNextFrameOnlyOnce.
@Test
public void testBeforeNextFrameOnlyOnce() {
AtomicInteger b = new AtomicInteger(0);
NAR n = NARS.shell();
n.runLater(b::incrementAndGet);
n.run(4);
assertEquals(1, b.get());
}
use of nars.NAR in project narchy by automenta.
the class WorkerMultiExecTest method test1.
@Test
public void test1() {
int threads = 3;
Focus.DefaultRevaluator reval = new Focus.DefaultRevaluator();
WorkerMultiExec exe = new WorkerMultiExec(reval, threads, 16, 3);
NAR n = new NARS().exe(exe).get();
AtomicLong dutyTimeNS = new AtomicLong();
DummyCan a = new DummyCan("a", dutyTimeNS, n, (int j) -> Util.sleep(1 * j)).value(4f);
DummyCan b = new DummyCan("b", dutyTimeNS, n, (int j) -> Util.sleep(1 * j)).value(1f);
DummyCan c = new DummyCan("c", dutyTimeNS, n, (int j) -> Util.sleep(2 * j)).value(1f);
// n.onCycle(nn -> {
// Focus.Schedule s = exe.focus.schedule.read();
// System.out.println(nn.time() + " " +
// Arrays.toString(s.active) + "->" + n4(s.weight));
// });
long start = System.nanoTime();
Loop l = n.startFPS(5f);
Util.sleep(4000);
l.stop();
long totalTimeNS = (System.nanoTime() - start) * threads;
System.out.println("dutyTime=" + timeStr(dutyTimeNS.get()) + " , totalTime=" + timeStr(totalTimeNS) + ", efficiency=" + ((double) dutyTimeNS.get()) / totalTimeNS);
System.out.println(a.executed.get());
System.out.println(b.executed.get());
System.out.println(c.executed.get());
System.out.println(exe.focus);
assertEquals(3 + 1, exe.focus.choice.size());
assertEquals(expectedDuty(a) / expectedDuty(b), ((float) a.executed.get()) / b.executed.get(), 0.5f);
assertEquals(expectedDuty(a) / expectedDuty(c) / 2, ((float) a.executed.get()) / c.executed.get(), 0.5f);
}
use of nars.NAR in project narchy by automenta.
the class AutoConceptualizerTest method test1.
@Test
public void test1() {
int W = 4, H = 4;
NAR n = NARS.tmp();
Bitmap2DSensor c = new Bitmap2DSensor((x, y) -> $.p(x, y), new Bitmap2D() {
@Override
public int width() {
return W;
}
@Override
public int height() {
return H;
}
@Override
public float brightness(int xx, int yy) {
return (((xx + yy + n.time())) % 2) > 0 ? 1f : 0f;
}
}, n);
AutoConceptualizer ac = new AutoConceptualizer(c.iter.order, /* HACK */
true, 2, n);
for (int i = 0; i < 155; i++) {
c.input();
c.print(System.out);
n.run(1);
System.out.println();
}
}
Aggregations