diff --git a/bt.h b/bt.h index fedf19c..fbba01a 100644 --- a/bt.h +++ b/bt.h @@ -273,6 +273,7 @@ class Node { std::string name; // cache priority for current tick. unsigned int priorityCurrentTick = 0; + unsigned int priorityCurrentTickSeq = 0; protected: NodeId id = 0; @@ -345,8 +346,12 @@ class Node { // Internal method to query priority of this node in current tick. unsigned int GetPriorityCurrentTick(const Context& ctx) { + if (ctx.seq != priorityCurrentTickSeq) priorityCurrentTick = 0; // try cache in this tick firstly. - if (!priorityCurrentTick) priorityCurrentTick = Priority(ctx); + if (!priorityCurrentTick) { + priorityCurrentTick = Priority(ctx); + priorityCurrentTickSeq = ctx.seq; + } return priorityCurrentTick; } @@ -378,9 +383,6 @@ class Node { OnTerminate(ctx, status); b->running = false; // reset } - - // Clears priority for this tick. - priorityCurrentTick = 0; return status; } diff --git a/tests/blob_test.cc b/tests/blob_test.cc index 578cc55..beb8963 100644 --- a/tests/blob_test.cc +++ b/tests/blob_test.cc @@ -61,6 +61,7 @@ TEMPLATE_TEST_CASE("Blob/2", "[multiple entites]", Entity, // e1: Tick#1 root.BindTreeBlob(e1.blob); bb->shouldA = bt::Status::FAILURE; + ++ctx.seq; root.Tick(ctx); REQUIRE(root.LastStatus() == bt::Status::RUNNING); REQUIRE(bb->counterA == 1); @@ -71,6 +72,7 @@ TEMPLATE_TEST_CASE("Blob/2", "[multiple entites]", Entity, // e2: Tick#1 root.BindTreeBlob(e2.blob); bb->shouldA = bt::Status::SUCCESS; + ++ctx.seq; root.Tick(ctx); REQUIRE(root.LastStatus() == bt::Status::SUCCESS); REQUIRE(bb->counterA == 2); // +1 @@ -81,6 +83,7 @@ TEMPLATE_TEST_CASE("Blob/2", "[multiple entites]", Entity, root.BindTreeBlob(e3.blob); bb->shouldA = bt::Status::FAILURE; bb->shouldB = bt::Status::FAILURE; + ++ctx.seq; root.Tick(ctx); REQUIRE(root.LastStatus() == bt::Status::RUNNING); REQUIRE(bb->counterA == 3); // +1 @@ -92,6 +95,7 @@ TEMPLATE_TEST_CASE("Blob/2", "[multiple entites]", Entity, // e1: Tick#2 root.BindTreeBlob(e1.blob); bb->shouldB = bt::Status::FAILURE; + ++ctx.seq; root.Tick(ctx); REQUIRE(root.LastStatus() == bt::Status::RUNNING); REQUIRE(bb->counterA == 3); // +0 @@ -102,6 +106,7 @@ TEMPLATE_TEST_CASE("Blob/2", "[multiple entites]", Entity, // e2: Tick#2 root.BindTreeBlob(e2.blob); bb->shouldA = bt::Status::SUCCESS; + ++ctx.seq; root.Tick(ctx); REQUIRE(root.LastStatus() == bt::Status::SUCCESS); REQUIRE(bb->counterA == 4); // +1 @@ -112,6 +117,7 @@ TEMPLATE_TEST_CASE("Blob/2", "[multiple entites]", Entity, // e3: Tick#2 root.BindTreeBlob(e3.blob); bb->shouldE = bt::Status::FAILURE; + ++ctx.seq; root.Tick(ctx); REQUIRE(root.LastStatus() == bt::Status::FAILURE); REQUIRE(bb->counterA == 4); // +0 diff --git a/tests/builder_test.cc b/tests/builder_test.cc index 8b16542..44eede4 100644 --- a/tests/builder_test.cc +++ b/tests/builder_test.cc @@ -47,6 +47,7 @@ TEMPLATE_TEST_CASE("Builder/1", "[extend a custom decorator to builder]", Entity // Tick#1 root.BindTreeBlob(e.blob); + ++ctx.seq; root.Tick(ctx); REQUIRE(bb->counterA == 1); REQUIRE(bb->customDecoratorCounter == 1); @@ -55,6 +56,7 @@ TEMPLATE_TEST_CASE("Builder/1", "[extend a custom decorator to builder]", Entity // Tick#2 root.BindTreeBlob(e.blob); bb->shouldA = bt::Status::SUCCESS; + ++ctx.seq; root.Tick(ctx); REQUIRE(bb->counterA == 2); REQUIRE(bb->counterB == 1); diff --git a/tests/condition_test.cc b/tests/condition_test.cc index 5e2bbec..cee8def 100644 --- a/tests/condition_test.cc +++ b/tests/condition_test.cc @@ -25,6 +25,7 @@ TEST_CASE("Condition/1", "[simplest condition - constructed from template]") { // Tick#1 root.BindTreeBlob(e.blob); std::cout << "tick1" << std::endl; + ++ctx.seq; root.Tick(ctx); // A should not started. REQUIRE(bb->counterA == 0); @@ -35,6 +36,7 @@ TEST_CASE("Condition/1", "[simplest condition - constructed from template]") { // Tick#2: Make C true. root.BindTreeBlob(e.blob); bb->shouldC = true; + ++ctx.seq; root.Tick(ctx); // A should started running. REQUIRE(bb->counterA == 1); @@ -47,6 +49,7 @@ TEST_CASE("Condition/1", "[simplest condition - constructed from template]") { // Tick#3: Make A Success. root.BindTreeBlob(e.blob); bb->shouldA = bt::Status::SUCCESS; + ++ctx.seq; root.Tick(ctx); // The whole tree should Success. REQUIRE(root.LastStatus() == bt::Status::SUCCESS); @@ -76,6 +79,7 @@ TEST_CASE("Condition/2", "[simplest condition - constructed from lambda]") { // Tick#1 root.BindTreeBlob(e.blob); + ++ctx.seq; root.Tick(ctx); // A should not started. REQUIRE(bb->counterA == 0); @@ -83,6 +87,7 @@ TEST_CASE("Condition/2", "[simplest condition - constructed from lambda]") { // Tick#2: Make C true. bb->shouldC = true; + ++ctx.seq; root.Tick(ctx); // A should started running. REQUIRE(bb->counterA == 1); @@ -114,6 +119,7 @@ TEST_CASE("Condition/3", "[simplest condition - if]") { REQUIRE(bb->shouldC == false); // Tick#1 + ++ctx.seq; root.Tick(ctx); // A should not started. REQUIRE(bb->counterA == 0); @@ -121,6 +127,7 @@ TEST_CASE("Condition/3", "[simplest condition - if]") { // Tick#2: Make C true. bb->shouldC = true; + ++ctx.seq; root.Tick(ctx); // A should started running. REQUIRE(bb->counterA == 1); @@ -131,6 +138,7 @@ TEST_CASE("Condition/3", "[simplest condition - if]") { // Tick#2: Make C false. bb->shouldC = false; + ++ctx.seq; root.Tick(ctx); // A should not change. REQUIRE(bb->counterA == 1); @@ -160,11 +168,13 @@ TEST_CASE("Condition/4", "[simplest condition - and]") { root.BindTreeBlob(e.blob); // Tick#1 + ++ctx.seq; root.Tick(ctx); REQUIRE(root.LastStatus() == bt::Status::FAILURE); // Tick#2: Make C true. bb->shouldC = true; + ++ctx.seq; root.Tick(ctx); REQUIRE(root.LastStatus() == bt::Status::FAILURE); @@ -172,6 +182,7 @@ TEST_CASE("Condition/4", "[simplest condition - and]") { bb->shouldC = true; bb->shouldD = true; bb->shouldF = true; + ++ctx.seq; root.Tick(ctx); // The whole tree should Success REQUIRE(root.LastStatus() == bt::Status::SUCCESS); @@ -198,17 +209,20 @@ TEST_CASE("Condition/5", "[simplest condition - or]") { root.BindTreeBlob(e.blob); // Tick#1 + ++ctx.seq; root.Tick(ctx); REQUIRE(root.LastStatus() == bt::Status::FAILURE); // Tick#2: Make C true. bb->shouldC = true; + ++ctx.seq; root.Tick(ctx); REQUIRE(root.LastStatus() == bt::Status::SUCCESS); // Tick#3: Make only D true. bb->shouldC = false; bb->shouldD = true; + ++ctx.seq; root.Tick(ctx); REQUIRE(root.LastStatus() == bt::Status::SUCCESS); @@ -216,6 +230,7 @@ TEST_CASE("Condition/5", "[simplest condition - or]") { bb->shouldC = true; bb->shouldD = true; bb->shouldF = true; + ++ctx.seq; root.Tick(ctx); // The whole tree should Success REQUIRE(root.LastStatus() == bt::Status::SUCCESS); @@ -240,11 +255,13 @@ TEST_CASE("Condition/6", "[simplest condition - not]") { root.BindTreeBlob(e.blob); // Tick#1 + ++ctx.seq; root.Tick(ctx); REQUIRE(root.LastStatus() == bt::Status::SUCCESS); // Tick#2: Make C true. bb->shouldC = true; + ++ctx.seq; root.Tick(ctx); REQUIRE(root.LastStatus() == bt::Status::FAILURE); @@ -271,18 +288,21 @@ TEST_CASE("Condition/7", "[simplest condition - not2]") { REQUIRE(!bb->shouldC); // Tick#1 + ++ctx.seq; root.Tick(ctx); REQUIRE(root.LastStatus() == bt::Status::RUNNING); REQUIRE(bb->counterA == 1); // Tick#2: Make A Success. bb->shouldA = bt::Status::SUCCESS; + ++ctx.seq; root.Tick(ctx); REQUIRE(root.LastStatus() == bt::Status::SUCCESS); REQUIRE(bb->counterA == 2); // Tick#3: Make C true. bb->shouldC = true; + ++ctx.seq; root.Tick(ctx); REQUIRE(root.LastStatus() == bt::Status::FAILURE); REQUIRE(bb->counterA == 2); // not ticked diff --git a/tests/delay_test.cc b/tests/delay_test.cc index a72febe..ded9f85 100644 --- a/tests/delay_test.cc +++ b/tests/delay_test.cc @@ -26,7 +26,7 @@ TEMPLATE_TEST_CASE("Delay/1", "[simple delay]", Entity, REQUIRE(bb->counterA == 0); // Tick#1: A is not started. root.BindTreeBlob(e.blob); - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx);; REQUIRE(bb->counterA == 0); REQUIRE(root.LastStatus() == bt::Status::RUNNING); root.UnbindTreeBlob(); @@ -36,7 +36,7 @@ TEMPLATE_TEST_CASE("Delay/1", "[simple delay]", Entity, // Tick#2: A is started. root.BindTreeBlob(e.blob); - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx);; REQUIRE(bb->counterA == 1); root.UnbindTreeBlob(); } diff --git a/tests/hook_test.cc b/tests/hook_test.cc index 0e2afef..631ffc0 100644 --- a/tests/hook_test.cc +++ b/tests/hook_test.cc @@ -42,7 +42,7 @@ TEMPLATE_TEST_CASE("Hook/2", "[hook OnEnter]", Entity, (EntityFixedBlob<16>)) { TestType e; root.BindTreeBlob(e.blob); - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->onEnterCalledA); root.UnbindTreeBlob(); } @@ -62,13 +62,13 @@ TEMPLATE_TEST_CASE("Hook/3", "[hook OnTerminate]", Entity, (EntityFixedBlob<16>) TestType e; root.BindTreeBlob(e.blob); - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(!bb->onTerminatedCalledA); root.UnbindTreeBlob(); root.BindTreeBlob(e.blob); bb->shouldA = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->onTerminatedCalledA); root.UnbindTreeBlob(); } diff --git a/tests/invert_test.cc b/tests/invert_test.cc index 78f1603..81a42f6 100644 --- a/tests/invert_test.cc +++ b/tests/invert_test.cc @@ -22,7 +22,7 @@ TEST_CASE("Invert/1", "[invert once]") { // Tick#1: A is running root.BindTreeBlob(e.blob); - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 1); REQUIRE(bb->statusA == bt::Status::RUNNING); REQUIRE(root.LastStatus() == bt::Status::RUNNING); @@ -31,7 +31,7 @@ TEST_CASE("Invert/1", "[invert once]") { // Tick#2: A is success. root.BindTreeBlob(e.blob); bb->shouldA = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); REQUIRE(bb->statusA == bt::Status::SUCCESS); REQUIRE(root.LastStatus() == bt::Status::FAILURE); @@ -58,7 +58,7 @@ TEST_CASE("Invert/2", "[invert twice]") { // Tick#1: A is running root.BindTreeBlob(e.blob); - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 1); REQUIRE(bb->statusA == bt::Status::RUNNING); REQUIRE(root.LastStatus() == bt::Status::RUNNING); @@ -67,7 +67,7 @@ TEST_CASE("Invert/2", "[invert twice]") { // Tick#2: A is success. root.BindTreeBlob(e.blob); bb->shouldA = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); REQUIRE(bb->statusA == bt::Status::SUCCESS); REQUIRE(root.LastStatus() == bt::Status::SUCCESS); diff --git a/tests/parallel_test.cc b/tests/parallel_test.cc index f9ef20f..dd6833c 100644 --- a/tests/parallel_test.cc +++ b/tests/parallel_test.cc @@ -23,7 +23,7 @@ TEST_CASE("Parallel/1", "[all success]") { // Tick#1 root.BindTreeBlob(e.blob); - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // both A and B should RUNNING REQUIRE(bb->counterA == 1); REQUIRE(bb->counterB == 1); @@ -36,7 +36,7 @@ TEST_CASE("Parallel/1", "[all success]") { // Tick#2: Makes A SUCCESS. root.BindTreeBlob(e.blob); bb->shouldA = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A should SUCCESS, and b should still running REQUIRE(bb->counterA == 2); REQUIRE(bb->counterB == 2); @@ -49,7 +49,7 @@ TEST_CASE("Parallel/1", "[all success]") { // Tick#3: Makes B success. root.BindTreeBlob(e.blob); bb->shouldB = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 3); REQUIRE(bb->counterB == 3); @@ -81,7 +81,7 @@ TEST_CASE("Parallel/2", "[partial success (2nd failure)]") { root.BindTreeBlob(e.blob); // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // both A and B should RUNNING REQUIRE(bb->counterA == 1); REQUIRE(bb->counterB == 1); @@ -92,7 +92,7 @@ TEST_CASE("Parallel/2", "[partial success (2nd failure)]") { // Tick#2: Makes A SUCCESS. bb->shouldA = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A should SUCCESS, and b should still running REQUIRE(bb->counterA == 2); REQUIRE(bb->counterB == 2); @@ -103,7 +103,7 @@ TEST_CASE("Parallel/2", "[partial success (2nd failure)]") { // Tick#3: Makes B failure. bb->shouldB = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 3); REQUIRE(bb->counterB == 3); @@ -135,7 +135,7 @@ TEST_CASE("Parallel/3", "[partial success (1st failure)]") { root.BindTreeBlob(e.blob); // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // both A and B should RUNNING REQUIRE(bb->counterA == 1); REQUIRE(bb->counterB == 1); @@ -146,7 +146,7 @@ TEST_CASE("Parallel/3", "[partial success (1st failure)]") { // Tick#2: Makes A FAILURE. bb->shouldA = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A should FAILURE b should still running REQUIRE(bb->counterA == 2); REQUIRE(bb->counterB == 2); @@ -178,7 +178,7 @@ TEST_CASE("Parallel/4", "[all failure]") { root.BindTreeBlob(e.blob); // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // both A and B should RUNNING REQUIRE(bb->counterA == 1); REQUIRE(bb->counterB == 1); @@ -190,7 +190,7 @@ TEST_CASE("Parallel/4", "[all failure]") { // Tick#2: Makes A and B FAILURE. bb->shouldA = bt::Status::FAILURE; bb->shouldB = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A and B shuold both FAILURE REQUIRE(bb->counterA == 2); REQUIRE(bb->counterB == 2); @@ -225,7 +225,7 @@ TEST_CASE("Parallel/5", "[priority partial]") { bb->shouldPriorityH = 2; // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterG == 1); REQUIRE(bb->counterH == 1); REQUIRE(bb->statusG == bt::Status::RUNNING); @@ -235,7 +235,7 @@ TEST_CASE("Parallel/5", "[priority partial]") { // Tick#2 bb->shouldG = bt::Status::FAILURE; bb->shouldH = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterG == 2); REQUIRE(bb->counterH == 2); REQUIRE(bb->statusG == bt::Status::FAILURE); diff --git a/tests/random_selector_test.cc b/tests/random_selector_test.cc index 6995403..75c0381 100644 --- a/tests/random_selector_test.cc +++ b/tests/random_selector_test.cc @@ -26,7 +26,7 @@ TEST_CASE("RandomSelector/1", "[simple random selector]") { bb->shouldPriorityI = 0; bb->shouldPriorityH = 1; - for (int i = 0; i < 100; i++) root.Tick(ctx); + for (int i = 0; i < 100; i++) ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterI == 0); // I should have no chance to get tick REQUIRE(bb->counterH == 100); // The whole tree should RUNNING @@ -56,7 +56,7 @@ TEST_CASE("RandomSelector/2", "[simple random selector - equal weights]") { bb->shouldPriorityI = 1; bb->shouldPriorityH = 1; - for (int i = 0; i < 100000; i++) root.Tick(ctx); + for (int i = 0; i < 100000; i++) ++ctx.seq;root.Tick(ctx); REQUIRE(abs(bb->counterI - bb->counterH) < 3000); // error < 30%? // The whole tree should RUNNING REQUIRE(root.LastStatus() == bt::Status::RUNNING); diff --git a/tests/repeat_test.cc b/tests/repeat_test.cc index 057a3fa..d9eef74 100644 --- a/tests/repeat_test.cc +++ b/tests/repeat_test.cc @@ -29,7 +29,7 @@ TEMPLATE_TEST_CASE("Repeat/1", "[simple repeat]", Entity, REQUIRE(bb->counterE == 0); // Tick1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterE == 1); REQUIRE(bb->counterA == 1); REQUIRE(bb->counterB == 0); // blocked by A @@ -39,7 +39,7 @@ TEMPLATE_TEST_CASE("Repeat/1", "[simple repeat]", Entity, bb->shouldA = bt::Status::SUCCESS; bb->shouldB = bt::Status::SUCCESS; bb->shouldE = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterE == 2); REQUIRE(bb->counterA == 2); REQUIRE(bb->counterB == 1); @@ -48,7 +48,7 @@ TEMPLATE_TEST_CASE("Repeat/1", "[simple repeat]", Entity, // Tick3: A, B goes into RUNNING again. bb->shouldA = bt::Status::RUNNING; bb->shouldB = bt::Status::RUNNING; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterE == 3); REQUIRE(bb->counterA == 3); REQUIRE(bb->counterB == 1); // blocked by A @@ -57,7 +57,7 @@ TEMPLATE_TEST_CASE("Repeat/1", "[simple repeat]", Entity, // Tick4: A, B both gose into SUCCESS again. bb->shouldA = bt::Status::SUCCESS; bb->shouldB = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterE == 4); REQUIRE(bb->counterA == 4); REQUIRE(bb->counterB == 2); // blocked by A diff --git a/tests/retry_test.cc b/tests/retry_test.cc index f757ca0..4ce1cf8 100644 --- a/tests/retry_test.cc +++ b/tests/retry_test.cc @@ -24,13 +24,13 @@ TEMPLATE_TEST_CASE("Retry/1", "[simple retry success]", Entity, root.BindTreeBlob(e.blob); // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 1); REQUIRE(root.LastStatus() == bt::Status::RUNNING); // Tick#2: Makes A success. bb->shouldA = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); REQUIRE(root.LastStatus() == bt::Status::SUCCESS); @@ -55,13 +55,13 @@ TEMPLATE_TEST_CASE("Retry/2", "[simple retry final failure]", Entity, root.BindTreeBlob(e.blob); // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 1); REQUIRE(root.LastStatus() == bt::Status::RUNNING); // Tick#2: Makes A failure bb->shouldA = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); REQUIRE(root.LastStatus() == bt::Status::RUNNING); @@ -69,15 +69,15 @@ TEMPLATE_TEST_CASE("Retry/2", "[simple retry final failure]", Entity, for (int i = 1; i <= 2; i++) { std::this_thread::sleep_for(30ms); bb->shouldA = bt::Status::RUNNING; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(root.LastStatus() == bt::Status::RUNNING); bb->shouldA = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(root.LastStatus() == bt::Status::RUNNING); } // Next the whole tree should failure. - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(root.LastStatus() == bt::Status::FAILURE); root.UnbindTreeBlob(); @@ -100,20 +100,20 @@ TEMPLATE_TEST_CASE("Retry/3", "[simple retry final success ]", Entity, root.BindTreeBlob(e.blob); // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 1); REQUIRE(root.LastStatus() == bt::Status::RUNNING); // Tick#2: Makes A failure bb->shouldA = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); REQUIRE(root.LastStatus() == bt::Status::RUNNING); // Tick#3: Makes A ok. std::this_thread::sleep_for(30ms); bb->shouldA = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(root.LastStatus() == bt::Status::SUCCESS); root.UnbindTreeBlob(); } @@ -136,13 +136,13 @@ TEMPLATE_TEST_CASE("Retry/4", "[simple retry forever ]", Entity, root.BindTreeBlob(e.blob); // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 1); REQUIRE(root.LastStatus() == bt::Status::RUNNING); // Tick#2: Makes A failure bb->shouldA = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); REQUIRE(root.LastStatus() == bt::Status::RUNNING); @@ -150,7 +150,7 @@ TEMPLATE_TEST_CASE("Retry/4", "[simple retry forever ]", Entity, for (int i = 0; i < 30; i++) { std::this_thread::sleep_for(1ms); bb->shouldA = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(root.LastStatus() == bt::Status::RUNNING); } root.UnbindTreeBlob(); diff --git a/tests/selector_test.cc b/tests/selector_test.cc index af27635..afdcb00 100644 --- a/tests/selector_test.cc +++ b/tests/selector_test.cc @@ -22,6 +22,7 @@ TEST_CASE("Selector/1", "[first success]") { REQUIRE(bb->counterB == 0); // Tick#1 + ++ctx.seq; root.Tick(ctx); // A is still running, B has not started running. REQUIRE(bb->counterA == 1); @@ -33,6 +34,7 @@ TEST_CASE("Selector/1", "[first success]") { // Tick#2: Makes A SUCCESS. bb->shouldA = bt::Status::SUCCESS; + ++ctx.seq; root.Tick(ctx); // A should SUCCESS, and b should not start running REQUIRE(bb->counterA == 2); @@ -43,6 +45,7 @@ TEST_CASE("Selector/1", "[first success]") { REQUIRE(root.LastStatus() == bt::Status::SUCCESS); // Tick#3: Nothing changes. + ++ctx.seq; root.Tick(ctx); // A should still success, and b should still not started. @@ -74,6 +77,7 @@ TEST_CASE("Selector/2", "[first failure and second success]") { REQUIRE(bb->counterB == 0); // Tick#1 + ++ctx.seq; root.Tick(ctx); // A is still running, B has not started running. REQUIRE(bb->counterA == 1); @@ -85,6 +89,7 @@ TEST_CASE("Selector/2", "[first failure and second success]") { // Tick#2: Makes A FAILURE. bb->shouldA = bt::Status::FAILURE; + ++ctx.seq; root.Tick(ctx); // A should FAILURE, and b should started REQUIRE(bb->counterA == 2); @@ -96,6 +101,7 @@ TEST_CASE("Selector/2", "[first failure and second success]") { // Tick#3: Makes B SUCCESS bb->shouldB = bt::Status::SUCCESS; + ++ctx.seq; root.Tick(ctx); // A should still FAILURE, and b should SUCCESS. @@ -127,6 +133,7 @@ TEST_CASE("Selector/3", "[all failure]") { REQUIRE(bb->counterB == 0); // Tick#1 + ++ctx.seq; root.Tick(ctx); // A is still running, B has not started running. REQUIRE(bb->counterA == 1); @@ -138,6 +145,7 @@ TEST_CASE("Selector/3", "[all failure]") { // Tick#2: Makes A FAILURE. bb->shouldA = bt::Status::FAILURE; + ++ctx.seq; root.Tick(ctx); // A should FAILURE, and b should started REQUIRE(bb->counterA == 2); @@ -149,6 +157,7 @@ TEST_CASE("Selector/3", "[all failure]") { // Tick#3: Makes B FAILURE bb->shouldB = bt::Status::FAILURE; + ++ctx.seq; root.Tick(ctx); // A should still FAILURE, and b should SUCCESS. @@ -183,6 +192,7 @@ TEST_CASE("Selector/4", "[priority selector final success]") { bb->shouldPriorityG = 1; bb->shouldPriorityH = 2; + ++ctx.seq; root.Tick(ctx); REQUIRE(bb->counterG == 0); REQUIRE(bb->counterH == 1); @@ -193,6 +203,7 @@ TEST_CASE("Selector/4", "[priority selector final success]") { // Tick#2: makes H failure. bb->shouldH = bt::Status::FAILURE; + ++ctx.seq; root.Tick(ctx); REQUIRE(bb->counterG == 1); // G now started. REQUIRE(bb->counterH == 2); @@ -202,12 +213,14 @@ TEST_CASE("Selector/4", "[priority selector final success]") { REQUIRE(root.LastStatus() == bt::Status::RUNNING); // Tick#3: one more tick + ++ctx.seq; root.Tick(ctx); REQUIRE(bb->counterG == 2); REQUIRE(bb->counterH == 3); // Tick#4: make G success. bb->shouldG = bt::Status::SUCCESS; + ++ctx.seq; root.Tick(ctx); REQUIRE(bb->counterG == 3); REQUIRE(bb->counterH == 4); @@ -240,6 +253,7 @@ TEST_CASE("Selector/4", "[priority selector final failure]") { bb->shouldPriorityG = 1; bb->shouldPriorityH = 2; + ++ctx.seq; root.Tick(ctx); REQUIRE(bb->counterG == 0); REQUIRE(bb->counterH == 1); @@ -250,6 +264,7 @@ TEST_CASE("Selector/4", "[priority selector final failure]") { // Tick#2: makes H failure. bb->shouldH = bt::Status::FAILURE; + ++ctx.seq; root.Tick(ctx); REQUIRE(bb->counterG == 1); // G now started. REQUIRE(bb->counterH == 2); @@ -260,6 +275,7 @@ TEST_CASE("Selector/4", "[priority selector final failure]") { // Tick#3: make G failure. bb->shouldG = bt::Status::FAILURE; + ++ctx.seq; root.Tick(ctx); REQUIRE(bb->counterG == 2); REQUIRE(bb->counterH == 3); @@ -292,6 +308,7 @@ TEST_CASE("Selector/5", "[priority selector - dynamic]") { bb->shouldPriorityG = 1; bb->shouldPriorityH = 2; + ++ctx.seq; root.Tick(ctx); REQUIRE(bb->counterG == 0); REQUIRE(bb->counterH == 1); @@ -302,6 +319,7 @@ TEST_CASE("Selector/5", "[priority selector - dynamic]") { // Tick#2: increase G's priority bb->shouldPriorityG = 2; + ++ctx.seq; root.Tick(ctx); REQUIRE(bb->counterG == 1); // G now started REQUIRE(bb->counterH == 1); // H should not ticked @@ -312,6 +330,7 @@ TEST_CASE("Selector/5", "[priority selector - dynamic]") { // Tick#3: increase G's priority bb->shouldPriorityG = 3; + ++ctx.seq; root.Tick(ctx); REQUIRE(bb->counterG == 2); // G now started REQUIRE(bb->counterH == 1); // H should not ticked @@ -322,6 +341,7 @@ TEST_CASE("Selector/5", "[priority selector - dynamic]") { // Tick#4: makes H success. bb->shouldH = bt::Status::SUCCESS; + ++ctx.seq; root.Tick(ctx); REQUIRE(bb->counterG == 3); // G now started REQUIRE(bb->counterH == 1); // H still blocked @@ -332,6 +352,7 @@ TEST_CASE("Selector/5", "[priority selector - dynamic]") { // Tick$5 makes H's priority highest bb->shouldPriorityH = 99; + ++ctx.seq; root.Tick(ctx); REQUIRE(bb->counterG == 3); // G should be skipped. REQUIRE(bb->counterH == 2); diff --git a/tests/sequence_test.cc b/tests/sequence_test.cc index b0fa04c..bc6b89e 100644 --- a/tests/sequence_test.cc +++ b/tests/sequence_test.cc @@ -23,7 +23,7 @@ TEST_CASE("Sequence/1", "[all success]") { REQUIRE(bb->counterB == 0); // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A is still running, B has not started running. REQUIRE(bb->counterA == 1); REQUIRE(bb->counterB == 0); @@ -34,7 +34,7 @@ TEST_CASE("Sequence/1", "[all success]") { // Tick#2: Makes A success. bb->shouldA = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A should success, and b should started running REQUIRE(bb->counterA == 2); REQUIRE(bb->counterB == 1); @@ -42,7 +42,7 @@ TEST_CASE("Sequence/1", "[all success]") { REQUIRE(bb->statusB == bt::Status::RUNNING); // Tick#3 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A should stay success, and b should still running REQUIRE(bb->counterA == 3); REQUIRE(bb->counterB == 2); @@ -51,7 +51,7 @@ TEST_CASE("Sequence/1", "[all success]") { // Tick#3: Make B success. bb->shouldB = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A should stay success, and b should success. REQUIRE(bb->counterA == 4); REQUIRE(bb->counterB == 3); @@ -82,7 +82,7 @@ TEST_CASE("Sequence/2", "[partial failure - first failure]") { REQUIRE(bb->counterB == 0); // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A is still running, B has not started running. REQUIRE(bb->counterA == 1); REQUIRE(bb->counterB == 0); @@ -91,7 +91,7 @@ TEST_CASE("Sequence/2", "[partial failure - first failure]") { // Tick#2: Makes A failure bb->shouldA = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A should failure, and b should not started REQUIRE(bb->counterA == 2); REQUIRE(bb->counterB == 0); @@ -121,7 +121,7 @@ TEST_CASE("Sequence/3", "[partial failure - last failure]") { REQUIRE(bb->counterB == 0); // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A is still running, B has not started running. REQUIRE(bb->counterA == 1); REQUIRE(bb->counterB == 0); @@ -130,7 +130,7 @@ TEST_CASE("Sequence/3", "[partial failure - last failure]") { // Tick#2: Makes A SUCCESS. bb->shouldA = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A should failure, and b should start running REQUIRE(bb->counterA == 2); REQUIRE(bb->counterB == 1); @@ -141,7 +141,7 @@ TEST_CASE("Sequence/3", "[partial failure - last failure]") { // Tick#3: Makes B FAILURE bb->shouldB = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A should still success, and b should FAILURE REQUIRE(bb->counterA == 3); @@ -178,7 +178,7 @@ TEST_CASE("Sequence/4", "[priority sequence - final success]") { bb->shouldPriorityI = 3; // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterI == 1); REQUIRE(bb->counterH == 0); REQUIRE(bb->counterG == 0); @@ -189,7 +189,7 @@ TEST_CASE("Sequence/4", "[priority sequence - final success]") { // Tick#2: makes I success bb->shouldI = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterI == 2); REQUIRE(bb->counterH == 1); REQUIRE(bb->counterG == 0); @@ -200,7 +200,7 @@ TEST_CASE("Sequence/4", "[priority sequence - final success]") { // Tick#3: makes H success bb->shouldH = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterI == 3); REQUIRE(bb->counterH == 2); REQUIRE(bb->counterG == 1); @@ -211,7 +211,7 @@ TEST_CASE("Sequence/4", "[priority sequence - final success]") { // Tick#4: makes G success bb->shouldG = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterI == 4); REQUIRE(bb->counterH == 3); REQUIRE(bb->counterG == 2); @@ -247,7 +247,7 @@ TEST_CASE("Sequence/5", "[priority sequence - partial success/failure]") { bb->shouldPriorityI = 3; // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterI == 1); REQUIRE(bb->counterH == 0); REQUIRE(bb->counterG == 0); @@ -258,7 +258,7 @@ TEST_CASE("Sequence/5", "[priority sequence - partial success/failure]") { // Tick#2: makes I success bb->shouldI = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterI == 2); REQUIRE(bb->counterH == 1); REQUIRE(bb->counterG == 0); @@ -269,7 +269,7 @@ TEST_CASE("Sequence/5", "[priority sequence - partial success/failure]") { // Tick#3: makes H FAILURE bb->shouldH = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterI == 3); REQUIRE(bb->counterH == 2); REQUIRE(bb->counterG == 0); @@ -305,7 +305,7 @@ TEST_CASE("Sequence/5", "[priority sequence - dynamic]") { bb->shouldPriorityI = 3; // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterI == 1); REQUIRE(bb->counterH == 0); REQUIRE(bb->counterG == 0); @@ -317,7 +317,7 @@ TEST_CASE("Sequence/5", "[priority sequence - dynamic]") { // Tick#2: makes G' and H' s priority higher bb->shouldPriorityG = 3; bb->shouldPriorityH = 3; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterI == 1); REQUIRE(bb->counterH == 0); REQUIRE(bb->counterG == 1); @@ -329,7 +329,7 @@ TEST_CASE("Sequence/5", "[priority sequence - dynamic]") { // Tick#2: makes I' s priority higher bb->shouldPriorityI = 999; bb->shouldI = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterI == 2); REQUIRE(bb->counterH == 0); REQUIRE(bb->counterG == 2); diff --git a/tests/stateful_parallel_test.cc b/tests/stateful_parallel_test.cc index 2ba516e..1bb735e 100644 --- a/tests/stateful_parallel_test.cc +++ b/tests/stateful_parallel_test.cc @@ -27,7 +27,7 @@ TEMPLATE_TEST_CASE("StatefulParallel/1", "[all success]", Entity, root.BindTreeBlob(e.blob); // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A/B/E all started running REQUIRE(bb->counterA == 1); REQUIRE(bb->counterB == 1); @@ -40,7 +40,7 @@ TEMPLATE_TEST_CASE("StatefulParallel/1", "[all success]", Entity, // Tick#2: Make A SUCCESS bb->shouldA = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); REQUIRE(bb->counterB == 2); REQUIRE(bb->counterE == 2); @@ -51,7 +51,7 @@ TEMPLATE_TEST_CASE("StatefulParallel/1", "[all success]", Entity, REQUIRE(root.LastStatus() == bt::Status::RUNNING); // Tick#3 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); // A should skip this tick REQUIRE(bb->counterB == 3); REQUIRE(bb->counterE == 3); @@ -63,7 +63,7 @@ TEMPLATE_TEST_CASE("StatefulParallel/1", "[all success]", Entity, // Tick#4: Makes B SUCCESS bb->shouldB = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); // not ticked REQUIRE(bb->counterB == 4); // got one more tick. REQUIRE(bb->counterE == 4); @@ -75,7 +75,7 @@ TEMPLATE_TEST_CASE("StatefulParallel/1", "[all success]", Entity, // Tick#5: Makes E success bb->shouldE = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); // not ticked. REQUIRE(bb->counterB == 4); // not ticked. REQUIRE(bb->counterE == 5); // got one more tick. @@ -86,7 +86,7 @@ TEMPLATE_TEST_CASE("StatefulParallel/1", "[all success]", Entity, REQUIRE(root.LastStatus() == bt::Status::SUCCESS); // Tick#6: One more tick should restart from all children - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 3); // got ticked. REQUIRE(bb->counterB == 5); // got ticked. REQUIRE(bb->counterE == 6); // got ticked. @@ -116,7 +116,7 @@ TEMPLATE_TEST_CASE("StatefulParallel/2", "[final failure]", Entity, REQUIRE(bb->counterB == 0); // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A/B/E all started running REQUIRE(bb->counterA == 1); REQUIRE(bb->counterB == 1); @@ -129,7 +129,7 @@ TEMPLATE_TEST_CASE("StatefulParallel/2", "[final failure]", Entity, // Tick#2: Make A SUCCESS bb->shouldA = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); REQUIRE(bb->counterB == 2); REQUIRE(bb->counterE == 2); @@ -140,7 +140,7 @@ TEMPLATE_TEST_CASE("StatefulParallel/2", "[final failure]", Entity, REQUIRE(root.LastStatus() == bt::Status::RUNNING); // Tick#3 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); // A should skip this tick REQUIRE(bb->counterB == 3); REQUIRE(bb->counterE == 3); @@ -152,7 +152,7 @@ TEMPLATE_TEST_CASE("StatefulParallel/2", "[final failure]", Entity, // Tick#4: Makes B failure bb->shouldB = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); // not ticked REQUIRE(bb->counterB == 4); // got one more tick. REQUIRE(bb->counterE == 4); // go ticked @@ -163,7 +163,7 @@ TEMPLATE_TEST_CASE("StatefulParallel/2", "[final failure]", Entity, REQUIRE(root.LastStatus() == bt::Status::FAILURE); // Tick#5: One more tick should restart from all children - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 3); // got ticked. REQUIRE(bb->counterB == 5); // got ticked. REQUIRE(bb->counterE == 5); // got ticked. diff --git a/tests/stateful_random_selector_test.cc b/tests/stateful_random_selector_test.cc index 644d378..99c2d2e 100644 --- a/tests/stateful_random_selector_test.cc +++ b/tests/stateful_random_selector_test.cc @@ -27,12 +27,12 @@ TEMPLATE_TEST_CASE("StatefulRandomSelector/1", "[simple stateful random selector bb->shouldPriorityI = 1; bb->shouldPriorityH = 1; - for (int i = 0; i < 10; i++) root.Tick(ctx); + for (int i = 0; i < 10; i++) ++ctx.seq;root.Tick(ctx); // Makes I failure. bb->shouldI = bt::Status::FAILURE; - for (int i = 0; i < 100; i++) root.Tick(ctx); + for (int i = 0; i < 100; i++) ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterI <= 11); // at most get 11 tick REQUIRE(bb->counterH >= 99); // at least 99 tick diff --git a/tests/stateful_selector_test.cc b/tests/stateful_selector_test.cc index d290091..67a8ae3 100644 --- a/tests/stateful_selector_test.cc +++ b/tests/stateful_selector_test.cc @@ -26,7 +26,7 @@ TEMPLATE_TEST_CASE("StatefulSelector/1", "[final success]", Entity, REQUIRE(bb->counterB == 0); // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A is still running, B & E has not started running. REQUIRE(bb->counterA == 1); REQUIRE(bb->counterB == 0); @@ -39,7 +39,7 @@ TEMPLATE_TEST_CASE("StatefulSelector/1", "[final success]", Entity, // Tick#2: Make A failure. bb->shouldA = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A should failure, and B should started running, E should still not started. REQUIRE(bb->counterA == 2); REQUIRE(bb->counterB == 1); @@ -51,7 +51,7 @@ TEMPLATE_TEST_CASE("StatefulSelector/1", "[final success]", Entity, REQUIRE(root.LastStatus() == bt::Status::RUNNING); // Tick#3 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A should stay failure, but without ticked. // B should still running, got one more tick. REQUIRE(bb->counterA == 2); @@ -66,7 +66,7 @@ TEMPLATE_TEST_CASE("StatefulSelector/1", "[final success]", Entity, // Tick#4: Makes B failure bb->shouldB = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); // not ticked REQUIRE(bb->counterB == 3); // got one more tick. // E started running @@ -79,7 +79,7 @@ TEMPLATE_TEST_CASE("StatefulSelector/1", "[final success]", Entity, // Tick#5: Makes E success bb->shouldE = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); // not ticked. REQUIRE(bb->counterB == 3); // not ticked. REQUIRE(bb->counterE == 2); // got one more tick. @@ -90,7 +90,7 @@ TEMPLATE_TEST_CASE("StatefulSelector/1", "[final success]", Entity, REQUIRE(root.LastStatus() == bt::Status::SUCCESS); // Tick#6: One more tick should restart from the first - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 3); // got ticked. root.UnbindTreeBlob(); } @@ -117,7 +117,7 @@ TEMPLATE_TEST_CASE("StatefulSelector/2", "[final failure]", Entity, REQUIRE(bb->counterB == 0); // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A is still running, B & E has not started running. REQUIRE(bb->counterA == 1); REQUIRE(bb->counterB == 0); @@ -130,7 +130,7 @@ TEMPLATE_TEST_CASE("StatefulSelector/2", "[final failure]", Entity, // Tick#2: Make A failure. bb->shouldA = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A should failure, and B should started running, E should still not started. REQUIRE(bb->counterA == 2); REQUIRE(bb->counterB == 1); @@ -142,7 +142,7 @@ TEMPLATE_TEST_CASE("StatefulSelector/2", "[final failure]", Entity, REQUIRE(root.LastStatus() == bt::Status::RUNNING); // Tick#3 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A should stay failure, but without ticked. // B should still running, got one more tick. REQUIRE(bb->counterA == 2); @@ -157,7 +157,7 @@ TEMPLATE_TEST_CASE("StatefulSelector/2", "[final failure]", Entity, // Tick#4: Makes B failure bb->shouldB = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); // not ticked REQUIRE(bb->counterB == 3); // got one more tick. // E started running @@ -170,7 +170,7 @@ TEMPLATE_TEST_CASE("StatefulSelector/2", "[final failure]", Entity, // Tick#5: Makes E failure bb->shouldE = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); // not ticked. REQUIRE(bb->counterB == 3); // not ticked. REQUIRE(bb->counterE == 2); // got one more tick. @@ -181,7 +181,7 @@ TEMPLATE_TEST_CASE("StatefulSelector/2", "[final failure]", Entity, REQUIRE(root.LastStatus() == bt::Status::FAILURE); // Tick#6: One more tick should restart from the first - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 3); // got ticked. root.UnbindTreeBlob(); } @@ -212,7 +212,7 @@ TEMPLATE_TEST_CASE("StatefulSelector/3", "[priority statefule selector final suc bb->shouldPriorityI = 3; // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterG == 0); REQUIRE(bb->counterH == 0); REQUIRE(bb->counterI == 1); @@ -223,7 +223,7 @@ TEMPLATE_TEST_CASE("StatefulSelector/3", "[priority statefule selector final suc // Tick#2: Make I failure. bb->shouldI = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterG == 0); REQUIRE(bb->counterH == 1); REQUIRE(bb->counterI == 2); @@ -234,7 +234,7 @@ TEMPLATE_TEST_CASE("StatefulSelector/3", "[priority statefule selector final suc // Tick#3: Make H failure. bb->shouldH = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterG == 1); REQUIRE(bb->counterH == 2); REQUIRE(bb->counterI == 2); // skip ticked @@ -245,7 +245,7 @@ TEMPLATE_TEST_CASE("StatefulSelector/3", "[priority statefule selector final suc // Tick#4: Make G SUCCESS. bb->shouldG = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterG == 2); REQUIRE(bb->counterH == 2); // skip ticked. REQUIRE(bb->counterI == 2); // skip ticked diff --git a/tests/stateful_sequence_test.cc b/tests/stateful_sequence_test.cc index 8414aaa..0fee126 100644 --- a/tests/stateful_sequence_test.cc +++ b/tests/stateful_sequence_test.cc @@ -26,7 +26,7 @@ TEMPLATE_TEST_CASE("StatefulSequence/1", "[all success]", Entity, REQUIRE(bb->counterB == 0); // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A is still running, B & E has not started running. REQUIRE(bb->counterA == 1); REQUIRE(bb->counterB == 0); @@ -39,7 +39,7 @@ TEMPLATE_TEST_CASE("StatefulSequence/1", "[all success]", Entity, // Tick#2: Make A success. bb->shouldA = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A should success, and B should started running, E should still not started. REQUIRE(bb->counterA == 2); REQUIRE(bb->counterB == 1); @@ -51,7 +51,7 @@ TEMPLATE_TEST_CASE("StatefulSequence/1", "[all success]", Entity, REQUIRE(root.LastStatus() == bt::Status::RUNNING); // Tick#3 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A should stay success, but without ticked. // B should still running, got one more tick. REQUIRE(bb->counterA == 2); @@ -66,7 +66,7 @@ TEMPLATE_TEST_CASE("StatefulSequence/1", "[all success]", Entity, // Tick#4: Makes B success. bb->shouldB = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); REQUIRE(bb->counterB == 3); // got one more tick. // E started running @@ -79,7 +79,7 @@ TEMPLATE_TEST_CASE("StatefulSequence/1", "[all success]", Entity, // Tick#5: Makes E success bb->shouldE = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); // not ticked. REQUIRE(bb->counterB == 3); // not ticked. REQUIRE(bb->counterE == 2); // got one more tick. @@ -113,7 +113,7 @@ TEMPLATE_TEST_CASE("StatefulSequence/2", "[paritial failure]", Entity, REQUIRE(bb->counterB == 0); // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A is still running, B & E has not started running. REQUIRE(bb->counterA == 1); REQUIRE(bb->counterB == 0); @@ -126,7 +126,7 @@ TEMPLATE_TEST_CASE("StatefulSequence/2", "[paritial failure]", Entity, // Tick#2: Make A success. bb->shouldA = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A should success, and B should started running, E should still not started. REQUIRE(bb->counterA == 2); REQUIRE(bb->counterB == 1); @@ -139,7 +139,7 @@ TEMPLATE_TEST_CASE("StatefulSequence/2", "[paritial failure]", Entity, // Tick#3: Make B failure bb->shouldB = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); // not ticked REQUIRE(bb->counterB == 2); // got one more tick REQUIRE(bb->counterE == 0); // still not started. @@ -150,7 +150,7 @@ TEMPLATE_TEST_CASE("StatefulSequence/2", "[paritial failure]", Entity, REQUIRE(root.LastStatus() == bt::Status::FAILURE); // Tick#4: The next tick will starts from first child. - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 3); // restarts from here, got ticked root.UnbindTreeBlob(); } @@ -177,7 +177,7 @@ TEMPLATE_TEST_CASE("StatefulSequence/3", "[priority StatefulSequence]", Entity, bb->shouldPriorityI = 3; // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterG == 0); REQUIRE(bb->counterH == 0); REQUIRE(bb->counterI == 1); @@ -189,7 +189,7 @@ TEMPLATE_TEST_CASE("StatefulSequence/3", "[priority StatefulSequence]", Entity, // Tick#2: makes I success. bb->shouldI = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterG == 0); REQUIRE(bb->counterH == 1); REQUIRE(bb->counterI == 2); @@ -199,7 +199,7 @@ TEMPLATE_TEST_CASE("StatefulSequence/3", "[priority StatefulSequence]", Entity, // The whole tree should running. REQUIRE(root.LastStatus() == bt::Status::RUNNING); // Tick#3 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterG == 0); REQUIRE(bb->counterH == 2); REQUIRE(bb->counterI == 2); @@ -210,7 +210,7 @@ TEMPLATE_TEST_CASE("StatefulSequence/3", "[priority StatefulSequence]", Entity, REQUIRE(root.LastStatus() == bt::Status::RUNNING); // Tick#4: Makes G priority highest. bb->shouldPriorityG = 9999; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterG == 1); REQUIRE(bb->counterH == 2); REQUIRE(bb->counterI == 2); @@ -221,7 +221,7 @@ TEMPLATE_TEST_CASE("StatefulSequence/3", "[priority StatefulSequence]", Entity, REQUIRE(root.LastStatus() == bt::Status::RUNNING); // Tick#5: Makes G success. bb->shouldG = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterG == 2); REQUIRE(bb->counterH == 3); REQUIRE(bb->counterI == 2); @@ -232,7 +232,7 @@ TEMPLATE_TEST_CASE("StatefulSequence/3", "[priority StatefulSequence]", Entity, REQUIRE(root.LastStatus() == bt::Status::RUNNING); // Tick#6: Makes H success. bb->shouldH = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterG == 2); REQUIRE(bb->counterH == 4); REQUIRE(bb->counterI == 2); diff --git a/tests/subtree_test.cc b/tests/subtree_test.cc index 1e1e961..b26c8b2 100644 --- a/tests/subtree_test.cc +++ b/tests/subtree_test.cc @@ -35,7 +35,7 @@ TEMPLATE_TEST_CASE("SubTree/1", "[subtree test]", Entity, (EntityFixedBlob<32>)) // Tick#1: Make Action E Failure. bb->shouldE = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A should running. REQUIRE(bb->counterA == 1); REQUIRE(bb->counterE == 1); @@ -44,7 +44,7 @@ TEMPLATE_TEST_CASE("SubTree/1", "[subtree test]", Entity, (EntityFixedBlob<32>)) // Tick#2: Make C true. bb->shouldC = true; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); REQUIRE(bb->counterE == 2); REQUIRE(bb->counterB == 0); // B is blocked @@ -52,7 +52,7 @@ TEMPLATE_TEST_CASE("SubTree/1", "[subtree test]", Entity, (EntityFixedBlob<32>)) // Tick#3: Make A success. bb->shouldA = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 3); REQUIRE(bb->counterE == 3); REQUIRE(bb->counterB == 1); // B is started @@ -60,7 +60,7 @@ TEMPLATE_TEST_CASE("SubTree/1", "[subtree test]", Entity, (EntityFixedBlob<32>)) // Tick#4: Make B success. bb->shouldB = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 4); REQUIRE(bb->counterE == 4); REQUIRE(bb->counterB == 2); // B ok diff --git a/tests/switch_case_test.cc b/tests/switch_case_test.cc index e629735..8f70240 100644 --- a/tests/switch_case_test.cc +++ b/tests/switch_case_test.cc @@ -24,7 +24,7 @@ TEST_CASE("SwitchCase/1", "[simplest switch/case]") { Entity e; root.BindTreeBlob(e.blob); // Tick#1 - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // All should unstarted. REQUIRE(bb->counterA == 0); REQUIRE(bb->counterE == 0); @@ -34,7 +34,7 @@ TEST_CASE("SwitchCase/1", "[simplest switch/case]") { // Tick#2: Make D success. bb->shouldD = true; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // only B should started REQUIRE(bb->counterA == 0); REQUIRE(bb->counterE == 0); @@ -46,7 +46,7 @@ TEST_CASE("SwitchCase/1", "[simplest switch/case]") { // Tick#3: Make D FAILURE and C ok bb->shouldD = false; bb->shouldC = true; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); // A should started REQUIRE(bb->counterA == 1); REQUIRE(bb->counterE == 0); @@ -60,7 +60,7 @@ TEST_CASE("SwitchCase/1", "[simplest switch/case]") { // Tick#4: Make A success and E success bb->shouldA = bt::Status::SUCCESS; bb->shouldE = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); REQUIRE(bb->counterE == 1); REQUIRE(bb->counterB == 1); diff --git a/tests/tick_benchmark.cc b/tests/tick_benchmark.cc index a5477b9..ac1fc27 100644 --- a/tests/tick_benchmark.cc +++ b/tests/tick_benchmark.cc @@ -51,7 +51,7 @@ TEMPLATE_TEST_CASE("Tick/1", "[simple traversal benchmark ]", Entity, (EntityFix bb->shouldI = bt::Status::SUCCESS; BENCHMARK("bench tick without priorities - 6000 nodes ") { root.BindTreeBlob(e.blob); - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); root.UnbindTreeBlob(); }; } @@ -72,7 +72,7 @@ TEST_CASE("Tick/2", "[simple traversal benchmark - priority ]") { bb->shouldPriorityG = 2; BENCHMARK("bench tick with priorities - 6000 nodes") { root.BindTreeBlob(e.blob); - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); root.UnbindTreeBlob(); }; } @@ -90,7 +90,7 @@ TEST_CASE("Tick/3", "[simple traversal benchmark - stateful ]") { bb->shouldI = bt::Status::SUCCESS; BENCHMARK("bench tick without priorities - stateful - 6000 nodes ") { root.BindTreeBlob(e.blob); - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); root.UnbindTreeBlob(); }; } @@ -110,7 +110,7 @@ TEMPLATE_TEST_CASE("Tick/4", "[lots of entities]", Entity, (EntityFixedBlob<602> BENCHMARK("bench lots of entities - 1000 entities x 600 nodes") { for (auto& e : entities) { root.BindTreeBlob(e.blob); - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); root.UnbindTreeBlob(); } }; diff --git a/tests/timeout_test.cc b/tests/timeout_test.cc index f812134..88747f1 100644 --- a/tests/timeout_test.cc +++ b/tests/timeout_test.cc @@ -24,13 +24,13 @@ TEMPLATE_TEST_CASE("Timeout/1", "[simple timeout success]", Entity, TestType e; root.BindTreeBlob(e.blob); // Tick#1: A is not started. - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 1); REQUIRE(root.LastStatus() == bt::Status::RUNNING); // Tick#2: Makes A success. bb->shouldA = bt::Status::SUCCESS; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); REQUIRE(root.LastStatus() == bt::Status::SUCCESS); root.UnbindTreeBlob(); @@ -53,13 +53,13 @@ TEMPLATE_TEST_CASE("Timeout/2", "[simple timeout failure]", Entity, TestType e; root.BindTreeBlob(e.blob); // Tick#1: A is not started. - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 1); REQUIRE(root.LastStatus() == bt::Status::RUNNING); // Tick#2: Makes A failure. bb->shouldA = bt::Status::FAILURE; - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 2); REQUIRE(root.LastStatus() == bt::Status::FAILURE); root.UnbindTreeBlob(); @@ -82,13 +82,13 @@ TEMPLATE_TEST_CASE("Timeout/3", "[simple timeout timedout]", Entity, TestType e; root.BindTreeBlob(e.blob); // Tick#1: A is not started. - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 1); REQUIRE(root.LastStatus() == bt::Status::RUNNING); // Tick#2: should timeout std::this_thread::sleep_for(110ms); - root.Tick(ctx); + ++ctx.seq;root.Tick(ctx); REQUIRE(bb->counterA == 1); REQUIRE(root.LastStatus() == bt::Status::FAILURE); root.UnbindTreeBlob();