Search in sources :

Example 76 with NAR

use of nars.NAR in project narchy by automenta.

the class QueryVariableTest method testQueryAnswered.

void testQueryAnswered(int cyclesBeforeQuestion, int cyclesAfterQuestion) throws Narsese.NarseseException {
    AtomicBoolean b = new AtomicBoolean(false);
    String question = cyclesBeforeQuestion == 0 ? "<a --> b>" : /* unknown solution to be derived */
    "<b --> a>";
    // this.activeTasks = activeTasks;
    NAR n = NARS.tmpEternal();
    n.input("<a <-> b>. %1.0;0.5%", "<b --> a>. %1.0;0.5%");
    n.run(cyclesBeforeQuestion);
    n.question(question, ETERNAL, (q, a) -> {
        if (!a.isDeleted())
            b.set(true);
    });
    n.stopIf(b::get);
    n.run(cyclesAfterQuestion);
    assertTrue(b.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NAR(nars.NAR)

Example 77 with NAR

use of nars.NAR in project narchy by automenta.

the class TruthletTaskTest method test_LinearTruthlet_And_SustainTruthlet.

@Test
public void test_LinearTruthlet_And_SustainTruthlet() {
    float conf = 0.9f;
    RangeTruthlet s = Truthlet.slope(0, 1f, 3, 0f, c2w(conf));
    for (Truthlet t : new Truthlet[] { s, new SustainTruthlet(s, 1) }) {
        NAR n = NARS.shell();
        Term x = $.the("x");
        System.out.println(t);
        n.input(new TruthletTask(x, BELIEF, t, n));
        BeliefTable xb = n.truths(x, BELIEF);
        for (int i = -3; i < 7; i++) {
            Truth ti = xb.truth(i, n);
            if (i < 0 || i > 3) {
                if (t instanceof SustainTruthlet) {
                    // fade out
                    assertTrue(ti.conf() < 0.9f);
                } else {
                    assertNull(ti);
                }
            } else {
                assertEquals(0.9f, ti.conf());
                float f = ti.freq();
                switch(i) {
                    case 0:
                        assertEquals(1f, f, 0.01f);
                        break;
                    case 1:
                        assertEquals(0.666f, f, 0.01f);
                        break;
                    case 2:
                        assertEquals(0.333f, f, 0.01f);
                        break;
                    case 3:
                        assertEquals(0f, f, 0.01f);
                        break;
                }
            }
            System.out.println(i + ": " + ti);
        }
    }
}
Also used : BeliefTable(nars.table.BeliefTable) Term(nars.term.Term) NAR(nars.NAR) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Example 78 with NAR

use of nars.NAR in project narchy by automenta.

the class TemporalInductionTest method testTemporalRevisionOfTemporalRelation.

@Test
public void testTemporalRevisionOfTemporalRelation() throws Narsese.NarseseException {
    NAR n = NARS.tmp();
    // TextOutput.out(n);
    n.input("(a ==>+0 b). %1.0;0.7%");
    n.input("(a ==>+5 b). %1.0;0.6%");
    n.run(1);
// n.forEachActiveConcept(Concept::print);
// Concept c = n.concept("a:b");
// assertEquals("(b-->a). 5+0 %.50;.95%", c.getBeliefs().top().toStringWithoutBudget());
}
Also used : TestNAR(nars.test.TestNAR) NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 79 with NAR

use of nars.NAR in project narchy by automenta.

the class TemporalInductionTest method testInductionStability.

@Test
public void testInductionStability() throws Narsese.NarseseException {
    // two entirely disjoint events, and all inductable beliefs from them, should produce a finite system that doesn't explode
    NAR d = NARS.tmp();
    d.input("a:b. :|:");
    d.run(5);
    d.input("c:d. :|:");
    d.run(200);
    // everything should be inducted by now:
    int before = d.concepts.size();
    int numBeliefs = getBeliefCount(d);
    // System.out.println(numConcepts + " " + numBeliefs);
    d.run(60);
    // # unique concepts unchanged:
    int after = d.concepts.size();
    assertEquals(before, after);
// assertEquals(numBeliefs, getBeliefCount(d));
}
Also used : TestNAR(nars.test.TestNAR) NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 80 with NAR

use of nars.NAR in project narchy by automenta.

the class TemporalStabilityTests method testTemporalStabilityLinkedImplExt2.

@Test
public void testTemporalStabilityLinkedImplExt2() {
    // Param.DEBUG = true;
    @NotNull NAR n = NARS.tmp();
    int time = CYCLES;
    T1 a = new T1(linkedimpl, 1, 2, 5, 10);
    T1 b = new T1(linkedinh, 1, 2, 5, 10);
    a.test(-1, n);
    b.test(-1, n);
    n.run(time);
// a.evaluate(n);
// b.evaluate(n);
}
Also used : NotNull(org.jetbrains.annotations.NotNull) 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