Skip to content

Commit

Permalink
Root specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolas Howard committed Feb 27, 2024
1 parent 7c54e03 commit 6fd30cc
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/nodes/decorator/Root.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ describe("A Root node", () => {
"invalid definition: a root node must have a single child node defined"
);
});

it("(JSON)", () => {
const definition = {
type: "root"
} as any;
assert.throws(
() => new BehaviourTree(definition, {}),
Error,
"invalid definition: expected property 'child' to be defined for root node"
);
});
});
});

Expand All @@ -33,6 +44,24 @@ describe("A Root node", () => {

assert.strictEqual(findNode(tree, "root").state, State.FAILED);
});

it("(JSON)", () => {
const definition: RootNodeDefinition = {
type: "root",
child: {
type: "condition",
call: "someCondition"
}
};
const agent = { someCondition: () => false };
const tree = new BehaviourTree(definition, agent);

assert.strictEqual(findNode(tree, "root").state, State.READY);

tree.step();

assert.strictEqual(findNode(tree, "root").state, State.FAILED);
});
});

describe("move to the FAILED state if the child node moves to the FAILED state", () => {
Expand All @@ -47,6 +76,24 @@ describe("A Root node", () => {

assert.strictEqual(findNode(tree, "root").state, State.SUCCEEDED);
});

it("(JSON)", () => {
const definition: RootNodeDefinition = {
type: "root",
child: {
type: "condition",
call: "someCondition"
}
};
const agent = { someCondition: () => true };
const tree = new BehaviourTree(definition, agent);

assert.strictEqual(findNode(tree, "root").state, State.READY);

tree.step();

assert.strictEqual(findNode(tree, "root").state, State.SUCCEEDED);
});
});

describe("move to the RUNNING state if the child node does not move to the SUCCESS or FAILED state", () => {
Expand All @@ -61,6 +108,24 @@ describe("A Root node", () => {

assert.strictEqual(findNode(tree, "root").state, State.RUNNING);
});

it("(JSON)", () => {
const definition: RootNodeDefinition = {
type: "root",
child: {
type: "action",
call: "someAction"
}
};
const agent = { someAction: () => {} };
const tree = new BehaviourTree(definition, agent);

assert.strictEqual(findNode(tree, "root").state, State.READY);

tree.step();

assert.strictEqual(findNode(tree, "root").state, State.RUNNING);
});
});
});
});

0 comments on commit 6fd30cc

Please sign in to comment.