コード例 #1
0
ファイル: behavior_test.go プロジェクト: Rubentxu/lbricks
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
ファイル: behavior_test.go プロジェクト: Rubentxu/lbricks
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)
	}

}
コード例 #3
0
func TestMaxTime(t *testing.T) {
	blackboard := bgo.CreateBlackboard()
	tree := bgo.CreateBehaviorTree("Pruebas", "Test", blackboard)
	context := bgo.CreateContext("")
	tree.Root = bgo.NewMaxTime("MaxTimeTest", 200,
		NewTestDelayNode("Nodo1", 300),
	)

	status := tree.Tick(context)

	if status == bgo.SUCCESS {
		t.Error("Error status no es lo experado ")
	} else {
		t.Logf("Final status %s \r", status)
	}

}
コード例 #4
0
func TestInverter(t *testing.T) {
	blackboard := bgo.CreateBlackboard()
	tree := bgo.CreateBehaviorTree("Pruebas", "Test", blackboard)
	context := bgo.CreateContext("")
	tree.Root = bgo.NewInverter("InveterTest",
		NewTestNode("Nodo1", bgo.SUCCESS),
	)

	status := tree.Tick(context)

	if status == bgo.SUCCESS {
		t.Error("Error status no es lo experado ")
	} else {
		t.Logf("Final status %s \r", status)
	}

}
コード例 #5
0
func TestRepeater(t *testing.T) {
	blackboard := bgo.CreateBlackboard()
	tree := bgo.CreateBehaviorTree("Pruebas", "Test", blackboard)
	context := bgo.CreateContext("")
	tree.Root = bgo.NewRepeater("RepeaterTest", 3,
		NewTestNode("Nodo1", bgo.FAILURE),
	)

	tree.Tick(context)

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

	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)
	}
}