示例#1
0
func TestNSequenceRoot(t *testing.T) {
	blackboard := bgo.CreateBlackboard()
	tree := bgo.CreateBehaviorTree("Pruebas", "Test", blackboard)
	context := bgo.CreateContext("context1")
	context2 := bgo.CreateContext("context1")
	context3 := bgo.CreateContext("context1")

	tree.Root = bgo.NewSequence("SequenceTest",
		bgo.NewPriority("PriorityTest",
			NewTestNode("Nodo1", bgo.FAILURE),
			NewTestNode("Nodo2", bgo.SUCCESS),
			NewTestNode("Nodo3", bgo.SUCCESS)),

		NewTestNode("Nodo4", bgo.SUCCESS),
		NewTestNode("Nodo5", bgo.SUCCESS))

	tree.Tick(context)
	tree.Tick(context2)
	tree.Tick(context3)

	elem, _ := context.GetContextMemory().ArrayString["StatusResponses"]
	elem2, _ := context2.GetContextMemory().ArrayString["StatusResponses"]
	elem3, _ := context3.GetContextMemory().ArrayString["StatusResponses"]
	expected := []string{"Failure", "Success", "Success", "Success"}

	if !ArrayEquals(expected, elem) && !ArrayEquals(expected, elem2) && !ArrayEquals(expected, elem3) {
		t.Errorf("Error StatusResponses no son iguales a lo experado %s <--->%s -- %s -- %s \r",
			expected, elem, elem2, elem3)
	} else {
		t.Logf("Final status %s -- %s -- %s \r", elem, elem2, elem3)
	}

}
示例#2
0
func TestPriorityRoot(t *testing.T) {
	blackboard := bgo.CreateBlackboard()
	tree := bgo.CreateBehaviorTree("Pruebas2", "Test2", blackboard)
	context := bgo.CreateContext("")

	tree.Root = bgo.NewPriority("PriorityTest",
		bgo.NewSequence("SequenceTestA",
			NewTestNode("NodoA", bgo.SUCCESS),
			NewTestNode("NodoB", bgo.FAILURE),
			NewTestNode("NodoC", bgo.SUCCESS)),
		bgo.NewSequence("SequenceTestB",
			NewTestNode("NodoD", bgo.SUCCESS),
			NewTestNode("NodoE", bgo.SUCCESS)),
	)

	tree.Tick(context)

	elem, _ := context.GetContextMemory().ArrayString["StatusResponses"]
	expected := []string{"Success", "Failure", "Success", "Success"}

	if !ArrayEquals(expected, elem) {
		t.Errorf("Error StatusResponses no son iguales a lo experado %s <---> %s", expected, elem)
	} else {
		t.Logf("Final status %s \r", elem)
	}

}