Search in sources :

Example 91 with TestNAR

use of nars.test.TestNAR in project narchy by automenta.

the class NAL8EternalMixTest method goal_deduction_impl_after.

@Test
public void goal_deduction_impl_after() {
    TestNAR tester = test;
    tester.input("x:y! :|:");
    tester.input("(goto(z) ==>-5 x:y).");
    tester.mustGoal(cycles, "goto(z)", 1.0f, 0.45f, 5);
}
Also used : TestNAR(nars.test.TestNAR) Test(org.junit.jupiter.api.Test) NAL7Test(nars.nal.nal7.NAL7Test) NALTest(nars.util.NALTest)

Example 92 with TestNAR

use of nars.test.TestNAR in project narchy by automenta.

the class NAL8EternalMixTest method subgoal_1_abd.

@Test
public void subgoal_1_abd() {
    TestNAR tester = test;
    tester.input("opened:{t001}. :|:");
    tester.input("((hold(SELF,{t002}) &&+5 ( at(SELF,{t001}) &&+5 open({t001}))) ==>+5 opened:{t001}).");
    tester.mustBelieve(cycles, "( hold(SELF,{t002}) &&+5 ( at(SELF,{t001}) &&+5 open({t001})))", 1.0f, 0.45f, -15);
}
Also used : TestNAR(nars.test.TestNAR) Test(org.junit.jupiter.api.Test) NAL7Test(nars.nal.nal7.NAL7Test) NALTest(nars.util.NALTest)

Example 93 with TestNAR

use of nars.test.TestNAR in project narchy by automenta.

the class NAL8EternalMixTest method ded_with_indep_var_temporal.

@Test
public void ded_with_indep_var_temporal() {
    TestNAR tester = test;
    tester.input("goto({t003}). :|:");
    tester.inputAt(10, "(goto($1) ==>+5 at(SELF,$1)).");
    tester.mustBelieve(cycles, "at(SELF,{t003})", 1.0f, 0.81f, 5);
}
Also used : TestNAR(nars.test.TestNAR) Test(org.junit.jupiter.api.Test) NAL7Test(nars.nal.nal7.NAL7Test) NALTest(nars.util.NALTest)

Example 94 with TestNAR

use of nars.test.TestNAR in project narchy by automenta.

the class NAL8TestExt method subsent_simultaneous.

@Test
public void subsent_simultaneous() {
    TestNAR tester = test;
    // TODO decide correct parentheses ordering
    // tester.nar.log();
    tester.input("[opened]:t1. :|:");
    tester.inputAt(10, "(hold:t2 &&+0 (at:t1 &&+0 (open(t1) &&+0 [opened]:t1))).");
    // TODO Narsese parser for this:
    // tester.mustBelieve(cycles, "( &&+0 ,(t1-->at),(t2-->hold),(t1-->[opened]),open(t1))",
    tester.mustBelieve(cycles, "( && ,(t1-->at),(t2-->hold),(t1-->[opened]),open(t1))", 1.0f, 0.43f, 0);
    tester.mustBelieve(cycles, "(&&, hold:t2, at:t1, open(t1)).", 1.0f, 0.81f, ETERNAL);
}
Also used : TestNAR(nars.test.TestNAR) Test(org.junit.jupiter.api.Test) NALTest(nars.util.NALTest)

Example 95 with TestNAR

use of nars.test.TestNAR in project narchy by automenta.

the class QuestionTest method questionDrivesInference.

// @Test public void testQuestionHandler() throws Narsese.NarseseException {
// NAR nar = NARS.shell();
// 
// final int[] s = {0};
// new TaskMatch("add(%1, %2, #x)", nar) {
// 
// @Override public boolean test(@NotNull Task task) { return task.isQuestOrQuestion(); }
// 
// @Override
// protected void accept(Task task, Map<Term, Term> xy) {
// System.out.println(task + " " + xy);
// s[0] = xy.size();
// }
// };
// 
// nar.ask($.$("add(1, 2, #x)"));
// 
// assertEquals(3, s[0]);
// 
// }
// @Test public void testOperationHandler() throws Narsese.NarseseException {
// NAR nar = NARS.shell();
// 
// final int[] s = {0};
// StringBuilder match = new StringBuilder();
// new OperationTaskMatch( $.$("add(%1, %2, #x)"), nar) {
// 
// @Override public boolean test(@NotNull Task task) { return task.isQuestOrQuestion(); }
// 
// @Override
// protected void onMatch(Term[] args) {
// match.append(Arrays.toString(args)).append(' ');
// }
// };
// 
// nar.ask($.$("add(1, 2, #x)"));
// 
// assertTrue(match.toString().contains("[1, 2, #1026]"));
// 
// nar.ask($.$("add(1, #x)"));
// nar.ask($.$("(#x --> add)"));
// 
// assertFalse(match.toString().contains("[1, #1026]"));
// }
/**
 * tests whether the use of a question guides inference as measured by the speed to reach a specific conclusion
 */
@Test
public void questionDrivesInference() {
    final int[] dims = { 3, 2 };
    final int timelimit = 2400;
    TaskStatistics withTasks = new TaskStatistics();
    TaskStatistics withoutTasks = new TaskStatistics();
    DoubleSummaryStatistics withTime = new DoubleSummaryStatistics();
    DoubleSummaryStatistics withOutTime = new DoubleSummaryStatistics();
    IntFunction<NAR> narProvider = (seed) -> {
        NAR d = NARS.tmp(1);
        d.random().setSeed(seed);
        d.termVolumeMax.set(16);
        d.freqResolution.set(0.1f);
        return d;
    };
    BiFunction<Integer, Integer, TestNAR> testProvider = (seed, variation) -> {
        NAR n = narProvider.apply(seed);
        TestNAR t = new TestNAR(n);
        switch(variation) {
            case 0:
                new DeductiveMeshTest(t, dims, timelimit);
                break;
            case 1:
                new DeductiveMeshTest(t, dims, timelimit) {

                    @Override
                    public void ask(@NotNull TestNAR n, Term term) {
                    // disabled
                    }
                };
                break;
        }
        return t;
    };
    for (int i = 0; i < 10; i++) {
        int seed = i + 1;
        TestNAR withQuestion = testProvider.apply(seed, 0);
        withQuestion.test(true);
        withTime.accept(withQuestion.time());
        withTasks.add(withQuestion.nar);
        TestNAR withoutQuestion = testProvider.apply(seed, 1);
        withoutQuestion.test(true);
        withOutTime.accept(withoutQuestion.time());
        withoutTasks.add(withoutQuestion.nar);
    }
    withTasks.print();
    withoutTasks.print();
    assertNotEquals(withTime, withOutTime);
    System.out.println("with: " + withTime);
    System.out.println("withOut: " + withOutTime);
// assertTrue(withTime.getSum() < withOutTime.getSum());
// assertTrue(withTime.getSum() < 2 * withOutTime.getSum()); //less than half, considering that a search "diameter" becomes a "radius" by providing the answer end-point
}
Also used : nars(nars) BiFunction(java.util.function.BiFunction) DeductiveMeshTest(nars.test.DeductiveMeshTest) TestNAR(nars.test.TestNAR) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Disabled(org.junit.jupiter.api.Disabled) DoubleSummaryStatistics(java.util.DoubleSummaryStatistics) ETERNAL(nars.time.Tense.ETERNAL) Test(org.junit.jupiter.api.Test) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TaskStatistics(nars.task.util.TaskStatistics) NotNull(org.jetbrains.annotations.NotNull) Term(nars.term.Term) IntFunction(java.util.function.IntFunction) TestNAR(nars.test.TestNAR) DeductiveMeshTest(nars.test.DeductiveMeshTest) Term(nars.term.Term) DoubleSummaryStatistics(java.util.DoubleSummaryStatistics) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TaskStatistics(nars.task.util.TaskStatistics) TestNAR(nars.test.TestNAR) DeductiveMeshTest(nars.test.DeductiveMeshTest) Test(org.junit.jupiter.api.Test)

Aggregations

TestNAR (nars.test.TestNAR)178 Test (org.junit.jupiter.api.Test)169 NALTest (nars.util.NALTest)162 NAL7Test (nars.nal.nal7.NAL7Test)18 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 Disabled (org.junit.jupiter.api.Disabled)5 NAR (nars.NAR)2 Concept (nars.concept.Concept)2 DoubleSummaryStatistics (java.util.DoubleSummaryStatistics)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BiFunction (java.util.function.BiFunction)1 IntFunction (java.util.function.IntFunction)1 nars (nars)1 NARS (nars.NARS)1 TaskStatistics (nars.task.util.TaskStatistics)1 Term (nars.term.Term)1 DeductiveMeshTest (nars.test.DeductiveMeshTest)1 ETERNAL (nars.time.Tense.ETERNAL)1 NotNull (org.jetbrains.annotations.NotNull)1 Assertions.assertNotEquals (org.junit.jupiter.api.Assertions.assertNotEquals)1