Search in sources :

Example 26 with NAR

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NAR(nars.NAR)

Example 27 with NAR

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);
}
Also used : Termed(nars.term.Termed) Concept(nars.concept.Concept) NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 28 with NAR

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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 29 with NAR

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);
}
Also used : NARS(nars.NARS) Loop(jcog.exe.Loop) AtomicLong(java.util.concurrent.atomic.AtomicLong) NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 30 with NAR

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();
    }
}
Also used : Bitmap2D(jcog.signal.Bitmap2D) Bitmap2DSensor(nars.util.signal.Bitmap2DSensor) NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Aggregations

NAR (nars.NAR)124 Test (org.junit.jupiter.api.Test)92 NARS (nars.NARS)23 Term (nars.term.Term)20 Truth (nars.truth.Truth)18 TestNAR (nars.test.TestNAR)16 BeliefTable (nars.table.BeliefTable)10 Disabled (org.junit.jupiter.api.Disabled)9 PrologCore (nars.op.prolog.PrologCore)8 Nullable (org.jetbrains.annotations.Nullable)8 Task (nars.Task)7 Concept (nars.concept.Concept)6 Param (nars.Param)5 Termed (nars.term.Termed)5 List (java.util.List)4 FasterList (jcog.list.FasterList)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 nars.$ (nars.$)3 ITask (nars.task.ITask)3 NALTest (nars.util.NALTest)3