Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/tests/test_RangeManager.h
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
* GNU General Public License for more details. | * GNU General Public License for more details. | ||||
* | * | ||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#include "simulation2/system/ComponentTest.h" | #include "simulation2/system/ComponentTest.h" | ||||
#include "simulation2/components/ICmpRangeManager.h" | |||||
#include "simulation2/components/ICmpPosition.h" | #include "simulation2/components/ICmpPosition.h" | ||||
#include "simulation2/components/ICmpRangeManager.h" | |||||
#include "simulation2/components/ICmpVision.h" | #include "simulation2/components/ICmpVision.h" | ||||
#include "maths/Random.h" | #include <boost/random/mersenne_twister.hpp> | ||||
#include <boost/random/uniform_real.hpp> | #include <boost/random/uniform_real.hpp> | ||||
class MockVision : public ICmpVision | class MockVision : public ICmpVision | ||||
{ | { | ||||
public: | public: | ||||
DEFAULT_MOCK_COMPONENT() | DEFAULT_MOCK_COMPONENT() | ||||
virtual entity_pos_t GetRange() const { return entity_pos_t::FromInt(66); } | virtual entity_pos_t GetRange() const { return entity_pos_t::FromInt(66); } | ||||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | void test_basic() | ||||
{ CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(256), entity_pos_t::FromInt(256)-entity_pos_t::Epsilon(), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); } | { CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(256), entity_pos_t::FromInt(256)-entity_pos_t::Epsilon(), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); } | ||||
cmp->Verify(); | cmp->Verify(); | ||||
{ CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(383), entity_pos_t::FromInt(84), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); } | { CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(383), entity_pos_t::FromInt(84), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); } | ||||
cmp->Verify(); | cmp->Verify(); | ||||
{ CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(348), entity_pos_t::FromInt(83), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); } | { CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(348), entity_pos_t::FromInt(83), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); } | ||||
cmp->Verify(); | cmp->Verify(); | ||||
WELL512 rng; | boost::mt19937 rng; | ||||
for (size_t i = 0; i < 1024; ++i) | for (size_t i = 0; i < 1024; ++i) | ||||
{ | { | ||||
double x = boost::uniform_real<>(0.0, 512.0)(rng); | double x = boost::uniform_real<>(0.0, 512.0)(rng); | ||||
double z = boost::uniform_real<>(0.0, 512.0)(rng); | double z = boost::uniform_real<>(0.0, 512.0)(rng); | ||||
{ CMessagePositionChanged msg(100, true, entity_pos_t::FromDouble(x), entity_pos_t::FromDouble(z), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); } | { CMessagePositionChanged msg(100, true, entity_pos_t::FromDouble(x), entity_pos_t::FromDouble(z), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); } | ||||
cmp->Verify(); | cmp->Verify(); | ||||
} | } | ||||
Show All 17 Lines |
Wildfire Games · Phabricator