// throws VisitFailure
 public virtual void testSucceedAtSomeNode()
 {
     IVisitor v = new FailAtNodes(n1,n2);
     (logVisitor(v)).visit(n0);
     Logger expected = new Logger();
     expected.log(new Event(v,n0));
     Assertion.AssertEquals(expected,logger);
 }
 // throws VisitFailure
 public virtual void testNestingStopAt()
 {
     IVisitor recognize = new FailAtNodes(n1, n12);
     IVisitor goOnWhile = new SucceedAtNodes(n0, n1);
     NestingDepth nd = new NestingDepth(recognize, goOnWhile);
     nd.visit(n0);
     Assertion.AssertEquals(1, nd.getDepth());
 }
        // throws VisitFailure
        public virtual void testSuccessCounter()
        {
            IVisitor action = new FailAtNodes(n1, n2);
            SuccessCounter sc = new SuccessCounter(action);

            IVisitable nodeReturned = (new TopDown(sc)).visit(n0);

            Assertion.AssertEquals(n0, nodeReturned);
            Assertion.AssertEquals(3, sc.getSuccesses());
            Assertion.AssertEquals(2, sc.getFailures());
        }
Esempio n. 4
0
        // throws VisitFailure
        public virtual void testSomeOneFailure()
        {
            IVisitor v = new FailAtNodes(n1);
            Some     some = new Some(logVisitor(v));
            Logger expected = new Logger(v, new IVisitable[]{n1,n2});

            IVisitable nodeReturned = null;

            nodeReturned = some.visit(n0);
            Assertion.AssertEquals(expected, logger);
            Assertion.AssertEquals(n0, nodeReturned);
        }
        // throws VisitFailure
        public virtual void testSpineTopDownAtLeaf()
        {
            IVisitor stop = new FailAtNodes(n11);
            SpineTopDown spineTopDown = new SpineTopDown(logVisitor(stop));

            // n11 fails, so path to n12 is first to succeed.
            Logger expected = new Logger(stop, new IVisitable[]{n0,n1,n11,n12});

            IVisitable nodeReturned = spineTopDown.visit(n0);

            Assertion.AssertEquals("visit trace",expected, logger);
            Assertion.AssertEquals("return value",n0, nodeReturned);
        }
        // throws VisitFailure
        public virtual void testSpineTopDownAtInnerNode()
        {
            IVisitor stop = new FailAtNodes(n1);
            SpineTopDown spineTopDown = new SpineTopDown(logVisitor(stop));

            // n1 fails, so searching continues in n2.
            Logger expected = new Logger(stop, new IVisitable[]{n0,n1,n2});

            IVisitable nodeReturned = spineTopDown.visit(n0);

            Assertion.AssertEquals("visit trace",expected, logger);
            Assertion.AssertEquals("return value",n0, nodeReturned);
        }
        // throws VisitFailure
        public virtual void testSpineBottomUpAtLeaf()
        {
            IVisitor stop = new FailAtNodes(n11);
            SpineBottomUp spineBottomUp = new SpineBottomUp(logVisitor(stop));

            // n11 fails, so path to n12 is first to succeed,
            // and visited bottom up.
            Logger expected = new Logger(stop, new IVisitable[]{n11,n12,n1,n0});

            IVisitable nodeReturned = spineBottomUp.visit(n0);

            Assertion.AssertEquals("visit trace",expected, logger);
            Assertion.AssertEquals("return value",n0, nodeReturned);
        }
        // throws VisitFailure \
        public virtual void testSpineBottomUpAtInnerNode()
        {
            IVisitor stop = new FailAtNodes(n1);
            SpineBottomUp spineBottomUp = new SpineBottomUp(logVisitor(stop));

            // after having tried n11, n1 fails.
            // searching then continues in n2 and goes up to n0.
            Logger expected = new Logger(stop, new IVisitable[]{n11,n1,n2,n0});

            IVisitable nodeReturned = spineBottomUp.visit(n0);

            Assertion.AssertEquals("visit trace",expected, logger);
            Assertion.AssertEquals("return value",n0, nodeReturned);
        }
 // throws VisitFailure
 public virtual void testFailAtSomeNode()
 {
     IVisitor v = new FailAtNodes(n0,n1);
     try
     {
         (logVisitor(v)).visit(n0);
         Assertion.Fail("VisitFailure should have occured");
     }
     catch (VisitFailure)
     {
         Logger expected = new Logger();
         expected.log(new Event(v,n0));
         Assertion.AssertEquals(expected,logger);
     }
 }
        // throws VisitFailure
        public virtual void testFailAtn1()
        {
            IVisitor action = new Identity();
            IVisitor goDown = new FailAtNodes(n1);
            IVisitor successNode = new SucceedAtNodes(n12,n2);
            AllSpinesBottomUp asbu =
                new AllSpinesBottomUp(goDown, successNode, logVisitor(action));

            Logger expected = new Logger(action, new IVisitable[]{n2,n0});

            IVisitable nodeReturned = asbu.visit(n0);

            Assertion.AssertEquals("visit trace",expected, logger);
            Assertion.AssertEquals("return value",n0, nodeReturned);
        }
 public virtual void testSpineTopDownFailAtTop()
 {
     IVisitor stop = new FailAtNodes(n0);
     SpineTopDown spineTopDown = new SpineTopDown(logVisitor(stop));
     Logger expected = new Logger(stop, new IVisitable[]{n0});
     IVisitable nodeReturned = null;
     try
     {
         nodeReturned = spineTopDown.visit(n0);
         Assertion.Fail("VisitFailure should have occured!");
     }
     catch (VisitFailure)
     {
         Assertion.AssertEquals("visit trace",expected, logger);
         Assertion.AssertNull("return value",nodeReturned);
     }
 }
 public virtual void testSpineBottomUpFailAtInners()
 {
     IVisitor stop = new FailAtNodes(n1,n2);
     SpineBottomUp spineBottomUp = new SpineBottomUp(logVisitor(stop));
     Logger expected = new Logger(stop, new IVisitable[]{n11,n1,n2});
     IVisitable nodeReturned = null;
     try
     {
         nodeReturned = spineBottomUp.visit(n0);
         Assertion.Fail("VisitFailure should have occured!");
     }
     catch (VisitFailure)
     {
         Assertion.AssertEquals("visit trace",expected, logger);
         Assertion.AssertNull("return value",nodeReturned);
     }
 }
 // throws VisitFailure
 public virtual void testFailAtSomeNodes()
 {
     ArrayList nodes = new ArrayList();
     nodes.Add(n0);
     nodes.Add(n1);
     nodes.Add(n11);
     IVisitor v = new FailAtNodes(nodes);
     new Not((logVisitor(v))).visit(n0);
     new Not((logVisitor(v))).visit(n1);
     (logVisitor(v)).visit(n2);
     new Not((logVisitor(v))).visit(n11);
     (logVisitor(v)).visit(n12);
     Logger expected = new Logger();
     expected.log(new Event(v,n0));
     expected.log(new Event(v,n1));
     expected.log(new Event(v,n2));
     expected.log(new Event(v,n11));
     expected.log(new Event(v,n12));
     Assertion.AssertEquals(expected,logger);
 }
        // throws VisitFailure
        public virtual void testDoWhileSuccess()
        {
            IVisitor condition = new FailAtNodes(n1, n2);
            IVisitor action = new Identity();

            Logger expected = new Logger();
            expected.log(new Event(condition, n0));
            expected.log(new Event(action, n0));
            expected.log(new Event(condition, n1));
            expected.log(new Event(condition, n2));

            IVisitable nodeReturned =
                new DoWhileSuccess(
                logVisitor(condition),
                logVisitor(action)).visit(
                n0);

            Assertion.AssertEquals(expected, logger);
            Assertion.AssertEquals(n0, nodeReturned);
        }