LOAD_TEST(btunittest, selector_probability_ut_2)
{
	const char* tree = "node_test/selector_probability_ut_2";

	behaviac::Profiler::CreateInstance();
	behaviac::Config::SetSocketing(false);
	behaviac::Config::SetLogging(false);

	//behaviac::Agent::Register<AgentNodeTest>();
	registerAllTypes();
	AgentNodeTest* myTestAgent = AgentNodeTest::DynamicCast(behaviac::Agent::Create<AgentNodeTest>());
	behaviac::Agent::SetIdMask(1);
	myTestAgent->SetIdFlag(1);
	myTestAgent->btload(tree);
	myTestAgent->btsetcurrent(tree);
	myTestAgent->resetProperties();

	int loopCount = 10000;

	while (loopCount > 0)
	{
		myTestAgent->btexec();
		CHECK_EQUAL(-1, myTestAgent->testVar_0);
		--loopCount;
	}

	unregisterAllTypes();
	BEHAVIAC_DELETE(myTestAgent);
	//behaviac::Agent::UnRegister<AgentNodeTest>();

	behaviac::Profiler::DestroyInstance();
}
LOAD_TEST(btunittest, selector_probability_ut_4)
{
	const char* tree = "node_test/selector_probability_ut_4";

	behaviac::Profiler::CreateInstance();
	behaviac::Config::SetSocketing(false);
	behaviac::Config::SetLogging(false);

	//behaviac::Agent::Register<AgentNodeTest>();
	registerAllTypes();
	AgentNodeTest* myTestAgent = AgentNodeTest::DynamicCast(behaviac::Agent::Create<AgentNodeTest>());
	behaviac::Agent::SetIdMask(1);
	myTestAgent->SetIdFlag(1);
	myTestAgent->btload(tree);
	myTestAgent->btsetcurrent(tree);
	myTestAgent->resetProperties();

	behaviac::Workspace::GetInstance()->SetTimeSinceStartup(0.0);

	for (int i = 0; i < 10; ++i) {
		myTestAgent->btexec();
		if (myTestAgent->testVar_0 != -1) {
			CHECK_EQUAL(0, myTestAgent->testVar_0);
			CHECK_EQUAL(-1, myTestAgent->testVar_1);
			CHECK_FLOAT_EQUAL(0.0f, myTestAgent->testVar_2);
		}
		else {
			CHECK_EQUAL(-1, myTestAgent->testVar_0);
			CHECK_EQUAL(0, myTestAgent->testVar_1);
			CHECK_FLOAT_EQUAL(-1, myTestAgent->testVar_2);
		}

		behaviac::Workspace::GetInstance()->SetTimeSinceStartup(behaviac::Workspace::GetInstance()->GetTimeSinceStartup() + 0.1);
	}

	behaviac::Workspace::GetInstance()->SetTimeSinceStartup(behaviac::Workspace::GetInstance()->GetTimeSinceStartup() + 0.1);
	myTestAgent->btexec();

	CHECK_EQUAL(-1, myTestAgent->testVar_0);
	CHECK_EQUAL(-1, myTestAgent->testVar_1);


	unregisterAllTypes();
	BEHAVIAC_DELETE(myTestAgent);
	//behaviac::Agent::UnRegister<AgentNodeTest>();

	behaviac::Profiler::DestroyInstance();
}
//< Wait For Frames Tests
LOAD_TEST(btunittest, action_waitframes_ut_0)
{
    behaviac::Profiler::CreateInstance();
    behaviac::Config::SetSocketing(false);
    behaviac::Config::SetLogging(false);

    //behaviac::Agent::Register<AgentNodeTest>();
    registerAllTypes();
    AgentNodeTest* myTestAgent = AgentNodeTest::DynamicCast(behaviac::Agent::Create<AgentNodeTest>());
    behaviac::Agent::SetIdMask(1);
    myTestAgent->SetIdFlag(1);
    myTestAgent->btload("node_test/action_waitframes_ut_0");
    myTestAgent->btsetcurrent("node_test/action_waitframes_ut_0");
    myTestAgent->resetProperties();

    int loopCount = 0;

	behaviac::Workspace::GetInstance()->SetFrameSinceStartup(0);

    while (loopCount < 5)
    {
        myTestAgent->btexec();

        if (loopCount < 4)
        {
            CHECK_EQUAL(1, myTestAgent->testVar_0);
        }
        else
        {
            CHECK_EQUAL(2, myTestAgent->testVar_0);
        }

        ++loopCount;
		behaviac::Workspace::GetInstance()->SetFrameSinceStartup(behaviac::Workspace::GetInstance()->GetFrameSinceStartup() + 1);
    }

    myTestAgent->resetProperties();
    myTestAgent->btexec();
    CHECK_EQUAL(1, myTestAgent->testVar_0);

    BEHAVIAC_DELETE(myTestAgent);
    behaviac::Agent::UnRegister<AgentNodeTest>();

    behaviac::Profiler::DestroyInstance();

    unregisterAllTypes();
}
void test_stochastic_distribution_0(behaviac::string tree, behaviac::Workspace::EFileFormat format)
{
    behaviac::Profiler::CreateInstance();
    behaviac::Config::SetSocketing(false);
    behaviac::Config::SetLogging(false);

    //behaviac::Agent::Register<AgentNodeTest>();
    registerAllTypes();

    AgentNodeTest* myTestAgent = AgentNodeTest::DynamicCast(behaviac::Agent::Create<AgentNodeTest>());
    behaviac::Agent::SetIdMask(1);
    myTestAgent->SetIdFlag(1);
    //ms_workspace = new BehaviacWorkspace();
    myTestAgent->btload(tree.c_str());
    myTestAgent->btsetcurrent(tree.c_str());
    myTestAgent->resetProperties();

    int counts[3] = { 0, 0, 0 };
    int loopCount = STOCHASTIC_SAMPLE_COUNT;

    while (loopCount > 0)
    {
        myTestAgent->btexec();
        ++(counts[myTestAgent->testVar_0]);
        --loopCount;
    }

#if BEHAVIAC_COMPILER_MSVC

    for (int i = 0; i < 3; ++i)
    {
        int k = counts[i];
        int bias = abs(k - STOCHASTIC_SAMPLE_COUNT / 3);
        CHECK_LESS(bias, (STOCHASTIC_SAMPLE_COUNT / 20));
    }

#endif
    unregisterAllTypes();
    BEHAVIAC_DELETE(myTestAgent);
    //behaviac::Agent::UnRegister<AgentNodeTest>();

    behaviac::Profiler::DestroyInstance();
}
void test_stochastic_distribution_1(behaviac::string tree, behaviac::Workspace::EFileFormat format,
                                    int loopCount = STOCHASTIC_SAMPLE_COUNT, int referenceValue = STOCHASTIC_SAMPLE_COUNT / 3, int checkValue = STOCHASTIC_SAMPLE_COUNT / 30)
{
    behaviac::Profiler::CreateInstance();
    behaviac::Config::SetSocketing(false);
    behaviac::Config::SetLogging(false);

    //behaviac::Agent::Register<AgentNodeTest>();
    registerAllTypes();
    AgentNodeTest* myTestAgent = AgentNodeTest::DynamicCast(behaviac::Agent::Create<AgentNodeTest>());
    behaviac::Agent::SetIdMask(1);
    myTestAgent->SetIdFlag(1);


    int predicateValueCount = 0;
    myTestAgent->btload(tree.c_str());
    myTestAgent->btsetcurrent(tree.c_str());
    myTestAgent->resetProperties();

    while (loopCount > 0)
    {
        myTestAgent->resetProperties();
        myTestAgent->btexec();

        if (myTestAgent->testVar_0 == 0)
        {
            predicateValueCount++;
        }

        --loopCount;
    }

#if BEHAVIAC_COMPILER_MSVC
    int bias = abs(predicateValueCount - referenceValue);
    CHECK_LESS(bias, checkValue);
#endif
    unregisterAllTypes();
    BEHAVIAC_DELETE(myTestAgent);
    //behaviac::Agent::UnRegister<AgentNodeTest>();

    behaviac::Profiler::DestroyInstance();
}
//< Selector Probability Tests
void test_stochastic_distribution_2(behaviac::string tree, behaviac::Workspace::EFileFormat format, int refs[3])
{
    behaviac::Profiler::CreateInstance();
    behaviac::Config::SetSocketing(false);
    behaviac::Config::SetLogging(false);

    //behaviac::Agent::Register<AgentNodeTest>();
    registerAllTypes();
    AgentNodeTest* myTestAgent = AgentNodeTest::DynamicCast(behaviac::Agent::Create<AgentNodeTest>());
    behaviac::Agent::SetIdMask(1);
    myTestAgent->SetIdFlag(1);
    myTestAgent->btload(tree.c_str());
    myTestAgent->btsetcurrent(tree.c_str());
    myTestAgent->resetProperties();

    int counts[3] = { 0, 0, 0 };
    int loopCount = 10000;

    while (loopCount > 0)
    {
        myTestAgent->btexec();
        ++(counts[myTestAgent->testVar_0]);
        --loopCount;
    }

    for (int i = 0; i < 3; ++i)
    {
        int k = counts[i];
        int bias = abs(k - refs[i]);
        CHECK_LESS(bias, 1000);
    }

    unregisterAllTypes();
    BEHAVIAC_DELETE(myTestAgent);
    //behaviac::Agent::UnRegister<AgentNodeTest>();

    behaviac::Profiler::DestroyInstance();
}