Package org.terasology.logic.behavior.tree

Examples of org.terasology.logic.behavior.tree.Interpreter$Debugger


* @author synopia
*/
public class ParallelTest {
    @Test
    public void testSuccessRequireAll() {
        Interpreter interpreter = new Interpreter(null);
        ParallelNode parallel = new ParallelNode(ParallelNode.Policy.RequireAll, ParallelNode.Policy.RequireOne);

        Node one = create(new Mocker() {
            @Override
            public void mock(Task spy) {
                when(spy.update(anyInt())).thenReturn(Status.RUNNING, Status.SUCCESS);
            }
        });
        Node two = create(new Mocker() {
            @Override
            public void mock(Task spy) {
                when(spy.update(anyInt())).thenReturn(Status.RUNNING, Status.RUNNING, Status.SUCCESS);
            }
        });
        parallel.children().add(one);
        parallel.children().add(two);

        Task task = interpreter.start(parallel);
        interpreter.tick(0);
        Assert.assertEquals(Status.RUNNING, task.getStatus());
        interpreter.tick(0);
        Assert.assertEquals(Status.RUNNING, task.getStatus());
        interpreter.tick(0);
        Assert.assertEquals(Status.SUCCESS, task.getStatus());
    }
View Full Code Here


        Assert.assertEquals(Status.SUCCESS, task.getStatus());
    }

    @Test
    public void testSuccessRequireOne() {
        Interpreter interpreter = new Interpreter(null);
        ParallelNode parallel = new ParallelNode(ParallelNode.Policy.RequireOne, ParallelNode.Policy.RequireAll);
        Node one = create(new Mocker() {
            @Override
            public void mock(Task spy) {
                when(spy.update(anyInt())).thenReturn(Status.RUNNING, Status.SUCCESS);
            }
        });
        Node two = create(new Mocker() {
            @Override
            public void mock(Task spy) {
                when(spy.update(anyInt())).thenReturn(Status.RUNNING, Status.RUNNING);
            }
        });
        parallel.children().add(one);
        parallel.children().add(two);

        Task task = interpreter.start(parallel);
        interpreter.tick(0);
        Assert.assertEquals(Status.RUNNING, task.getStatus());
        interpreter.tick(0);
        Assert.assertEquals(Status.SUCCESS, task.getStatus());
    }
View Full Code Here

        Assert.assertEquals(Status.SUCCESS, task.getStatus());
    }

    @Test
    public void testFailureRequireAll() {
        Interpreter interpreter = new Interpreter(null);
        ParallelNode parallel = new ParallelNode(ParallelNode.Policy.RequireOne, ParallelNode.Policy.RequireAll);
        Node one = create(new Mocker() {
            @Override
            public void mock(Task spy) {
                when(spy.update(anyInt())).thenReturn(Status.RUNNING, Status.FAILURE);
            }
        });
        Node two = create(new Mocker() {
            @Override
            public void mock(Task spy) {
                when(spy.update(anyInt())).thenReturn(Status.RUNNING, Status.RUNNING, Status.FAILURE);
            }
        });
        parallel.children().add(one);
        parallel.children().add(two);

        Task task = interpreter.start(parallel);
        interpreter.tick(0);
        Assert.assertEquals(Status.RUNNING, task.getStatus());
        interpreter.tick(0);
        Assert.assertEquals(Status.RUNNING, task.getStatus());
        interpreter.tick(0);
        Assert.assertEquals(Status.FAILURE, task.getStatus());
    }
View Full Code Here

        Assert.assertEquals(Status.FAILURE, task.getStatus());
    }

    @Test
    public void testFailureRequireOne() {
        Interpreter interpreter = new Interpreter(null);
        ParallelNode parallel = new ParallelNode(ParallelNode.Policy.RequireAll, ParallelNode.Policy.RequireOne);
        Node one = create(new Mocker() {
            @Override
            public void mock(Task spy) {
                when(spy.update(anyInt())).thenReturn(Status.RUNNING, Status.FAILURE);
            }
        });
        Node two = create(new Mocker() {
            @Override
            public void mock(Task spy) {
                when(spy.update(anyInt())).thenReturn(Status.RUNNING, Status.RUNNING);
            }
        });
        parallel.children().add(one);
        parallel.children().add(two);

        Task task = interpreter.start(parallel);
        interpreter.tick(0);
        Assert.assertEquals(Status.RUNNING, task.getStatus());
        interpreter.tick(0);
        Assert.assertEquals(Status.FAILURE, task.getStatus());
    }
View Full Code Here

    private Node node;
    private Task task;

    @Test
    public void test0() {
        Interpreter interpreter = new Interpreter(null);
        DebugNode debugNode = new DebugNode(0);

        interpreter.start(debugNode);

        Assert.assertTrue(interpreter.tick(0) > 0);
        DebugNode.DebugTask first = debugNode.lastTask;
        Assert.assertTrue(first.updateCalled);
        Assert.assertTrue(first.initializeCalled);
        Assert.assertTrue(first.terminateCalled);

        Assert.assertTrue(interpreter.tick(0) == 0);
    }
View Full Code Here

        Assert.assertTrue(interpreter.tick(0) == 0);
    }

    @Test
    public void test1() {
        Interpreter interpreter = new Interpreter(null);
        DebugNode debugNode = new DebugNode(1);

        interpreter.start(debugNode);

        Assert.assertTrue(interpreter.tick(0) > 0);
        DebugNode.DebugTask first = debugNode.lastTask;
        Assert.assertTrue(first.updateCalled);
        Assert.assertTrue(first.initializeCalled);
        Assert.assertTrue(!first.terminateCalled);
        first.reset();

        Assert.assertTrue(interpreter.tick(0) > 0);
        DebugNode.DebugTask last = debugNode.lastTask;
        Assert.assertTrue(last.updateCalled);
        Assert.assertTrue(!last.initializeCalled);
        Assert.assertTrue(last.terminateCalled);
        Assert.assertSame(first, last);

        Assert.assertTrue(interpreter.tick(0) == 0);
    }
View Full Code Here

        Assert.assertTrue(interpreter.tick(0) == 0);
    }

    @Test
    public void testX() {
        Interpreter interpreter = new Interpreter(null);
        DebugNode debugNode = new DebugNode(10);

        interpreter.start(debugNode);

        Assert.assertTrue(interpreter.tick(0) > 0);
        DebugNode.DebugTask first = debugNode.lastTask;
        Assert.assertTrue(first.updateCalled);
        Assert.assertTrue(first.initializeCalled);
        Assert.assertTrue(!first.terminateCalled);
        first.reset();

        for (int i = 0; i < 9; i++) {
            Assert.assertTrue(interpreter.tick(0) > 0);
            DebugNode.DebugTask current = debugNode.lastTask;
            Assert.assertSame(first, current);
            Assert.assertTrue(current.updateCalled);
            Assert.assertTrue(!current.initializeCalled);
            Assert.assertTrue(!current.terminateCalled);
            current.reset();
        }

        Assert.assertTrue(interpreter.tick(0) > 0);
        DebugNode.DebugTask last = debugNode.lastTask;
        Assert.assertTrue(last.updateCalled);
        Assert.assertTrue(!last.initializeCalled);
        Assert.assertTrue(last.terminateCalled);
        Assert.assertSame(first, last);

        Assert.assertTrue(interpreter.tick(0) == 0);
    }
View Full Code Here

    }

    @Test
    public void testInit() {
        create();
        Interpreter interpreter = new Interpreter(null);
        interpreter.start(node, null);
        interpreter.tick(0);
        verify(task).onInitialize();
    }
View Full Code Here

    }

    @Test
    public void testUpdate() {
        create();
        Interpreter interpreter = new Interpreter(null);
        interpreter.start(node, null);
        interpreter.tick(0);
        verify(task).update(anyInt());
    }
View Full Code Here

    }

    @Test
    public void testNoTerminate() {
        create();
        Interpreter interpreter = new Interpreter(null);
        interpreter.start(node, null);
        interpreter.tick(0);
        verify(task, never()).onTerminate(any(Status.class));
    }
View Full Code Here

TOP

Related Classes of org.terasology.logic.behavior.tree.Interpreter$Debugger

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.