Added unit testing for kart characteristics (failing atm due to
bugs in characteristics).
This commit is contained in:
parent
3d2c2b63c0
commit
9efb4da2ec
@ -18,10 +18,13 @@
|
|||||||
|
|
||||||
#include "karts/combined_characteristic.hpp"
|
#include "karts/combined_characteristic.hpp"
|
||||||
|
|
||||||
|
#include "io/file_manager.hpp"
|
||||||
|
#include "karts/xml_characteristic.hpp"
|
||||||
|
|
||||||
void CombinedCharacteristic::addCharacteristic(
|
void CombinedCharacteristic::addCharacteristic(
|
||||||
const AbstractCharacteristic *characteristic)
|
const AbstractCharacteristic *characteristic)
|
||||||
{
|
{
|
||||||
m_childs.push_back(characteristic);
|
m_children.push_back(characteristic);
|
||||||
} // addCharacteristic
|
} // addCharacteristic
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -29,7 +32,59 @@ void CombinedCharacteristic::addCharacteristic(
|
|||||||
void CombinedCharacteristic::process(CharacteristicType type, Value value,
|
void CombinedCharacteristic::process(CharacteristicType type, Value value,
|
||||||
bool *is_set) const
|
bool *is_set) const
|
||||||
{
|
{
|
||||||
for (const AbstractCharacteristic *characteristic : m_childs)
|
for (const AbstractCharacteristic *characteristic : m_children)
|
||||||
characteristic->process(type, value, is_set);
|
characteristic->process(type, value, is_set);
|
||||||
} // process
|
} // process
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
void CombinedCharacteristic::unitTesting()
|
||||||
|
{
|
||||||
|
// We need to use really existing xml attributes, all characteristics
|
||||||
|
// were designed to work with those names.
|
||||||
|
std::string s1=
|
||||||
|
"<?xml version=\"1.0\"?>"
|
||||||
|
" <characteristic name=\"base\">"
|
||||||
|
" <suspension stiffness=\"4.5\" rest=\"-0.3\" travel=\"1+2\"/>"
|
||||||
|
" <stability roll-influence=\"1+2*3\" chassis-linear-damping=\"2*3+1\""
|
||||||
|
" chassis-angular-damping=\"0\" downward-impulse-factor=\"5\""
|
||||||
|
" track-connection-accel=\"2\" smooth-flying-impulse=\"250\" />"
|
||||||
|
" </characteristic>"
|
||||||
|
"</characteristics>";
|
||||||
|
|
||||||
|
XMLNode *xml1= file_manager->createXMLTreeFromString(s1);
|
||||||
|
XmlCharacteristic *c1 = new XmlCharacteristic(xml1);
|
||||||
|
delete xml1;
|
||||||
|
|
||||||
|
CombinedCharacteristic *cc = new CombinedCharacteristic();
|
||||||
|
cc->addCharacteristic(c1);
|
||||||
|
|
||||||
|
assert( cc->getSuspensionStiffness() == 4.5f );
|
||||||
|
assert( cc->getSuspensionRest() == -0.3f );
|
||||||
|
assert( cc->getSuspensionTravel() == 3.0f );
|
||||||
|
// Note: no operator precedence supported, so 1+2*3 = 9
|
||||||
|
assert( cc->getStabilityRollInfluence() == 9.0f );
|
||||||
|
assert( cc->getStabilityChassisLinearDamping() == 7.0f );
|
||||||
|
|
||||||
|
std::string s2=
|
||||||
|
"<?xml version=\"1.0\"?>"
|
||||||
|
" <characteristic name=\"base\">"
|
||||||
|
" <suspension stiffness=\"+1\" rest=\"-1\" travel=\"*2\"/>"
|
||||||
|
" <stability roll-influence=\"/3\" chassis-linear-damping=\"*1\"/>"
|
||||||
|
" </characteristic>"
|
||||||
|
"</characteristics>";
|
||||||
|
|
||||||
|
XMLNode *xml2= file_manager->createXMLTreeFromString(s2);
|
||||||
|
XmlCharacteristic *c2 = new XmlCharacteristic(xml2);
|
||||||
|
delete xml2;
|
||||||
|
|
||||||
|
cc->addCharacteristic(c2);
|
||||||
|
|
||||||
|
assert( cc->getSuspensionStiffness() == 5.5f );
|
||||||
|
assert( cc->getSuspensionRest() == -1.3f );
|
||||||
|
assert( cc->getSuspensionTravel() == 6.0f );
|
||||||
|
// Note: no operator precedence supported, so (1+2*3) / 3 = 3
|
||||||
|
assert( cc->getStabilityRollInfluence() == 3.0f );
|
||||||
|
assert( cc->getStabilityChassisLinearDamping() == 7.0f );
|
||||||
|
|
||||||
|
} // unitTesting
|
@ -24,9 +24,11 @@
|
|||||||
class CombinedCharacteristic : public AbstractCharacteristic
|
class CombinedCharacteristic : public AbstractCharacteristic
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::vector<const AbstractCharacteristic*> m_childs;
|
std::vector<const AbstractCharacteristic*> m_children;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static void unitTesting();
|
||||||
|
|
||||||
void addCharacteristic(const AbstractCharacteristic *characteristic);
|
void addCharacteristic(const AbstractCharacteristic *characteristic);
|
||||||
|
|
||||||
virtual void process(CharacteristicType type, Value value, bool *is_set) const;
|
virtual void process(CharacteristicType type, Value value, bool *is_set) const;
|
||||||
|
@ -168,6 +168,7 @@
|
|||||||
#include "items/attachment_manager.hpp"
|
#include "items/attachment_manager.hpp"
|
||||||
#include "items/item_manager.hpp"
|
#include "items/item_manager.hpp"
|
||||||
#include "items/projectile_manager.hpp"
|
#include "items/projectile_manager.hpp"
|
||||||
|
#include "karts/combined_characteristic.hpp"
|
||||||
#include "karts/controller/ai_base_lap_controller.hpp"
|
#include "karts/controller/ai_base_lap_controller.hpp"
|
||||||
#include "karts/kart_properties.hpp"
|
#include "karts/kart_properties.hpp"
|
||||||
#include "karts/kart_properties_manager.hpp"
|
#include "karts/kart_properties_manager.hpp"
|
||||||
@ -1857,6 +1858,11 @@ void runUnitTests()
|
|||||||
assert( isEasterMode(22, 3, 2016, 5));
|
assert( isEasterMode(22, 3, 2016, 5));
|
||||||
assert(!isEasterMode(21, 3, 2016, 5));
|
assert(!isEasterMode(21, 3, 2016, 5));
|
||||||
UserConfigParams::m_easter_ear_mode = saved_easter_mode;
|
UserConfigParams::m_easter_ear_mode = saved_easter_mode;
|
||||||
|
|
||||||
|
|
||||||
|
Log::info("UnitTest", " - Kart characteristics");
|
||||||
|
CombinedCharacteristic::unitTesting();
|
||||||
|
|
||||||
Log::info("UnitTest", "=====================");
|
Log::info("UnitTest", "=====================");
|
||||||
Log::info("UnitTest", "Testing successful ");
|
Log::info("UnitTest", "Testing successful ");
|
||||||
Log::info("UnitTest", "=====================");
|
Log::info("UnitTest", "=====================");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user