Contact.cpp
This is the googletest
based unit testing file for the playrho::d2::Contact
class.
/*
* Copyright (c) 2017 Louis Langholtz https://github.com/louis-langholtz/PlayRho
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#include "UnitTests.hpp"
#include <PlayRho/Dynamics/Contacts/Contact.hpp>
#include <PlayRho/Dynamics/Fixture.hpp>
#include <PlayRho/Dynamics/Body.hpp>
#include <PlayRho/Dynamics/World.hpp>
#include <PlayRho/Dynamics/BodyConf.hpp>
#include <PlayRho/Dynamics/FixtureConf.hpp>
#include <PlayRho/Collision/Shapes/DiskShapeConf.hpp>
using namespace playrho;
using namespace playrho::d2;
TEST(Contact, ByteSize)
{
{
default: FAIL(); break;
}
}
TEST(Contact, Traits)
{
EXPECT_FALSE(std::is_default_constructible<Contact>::value);
EXPECT_TRUE(std::is_copy_constructible<Contact>::value);
EXPECT_FALSE(std::is_copy_assignable<Contact>::value);
EXPECT_FALSE(IsAddable<Contact>::value);
EXPECT_FALSE((IsAddable<Contact, Contact>::value));
EXPECT_FALSE(IsIterable<Contact>::value);
}
TEST(Contact, Enabled)
{
auto c = Contact{fA, 0u, fB, 0u};
EXPECT_TRUE(c.IsEnabled());
c.UnsetEnabled();
EXPECT_FALSE(c.IsEnabled());
c.SetEnabled();
EXPECT_TRUE(c.IsEnabled());
}
{
auto world = World{};
bA->UnsetAwake();
ASSERT_FALSE(bA->IsAwake());
bB->UnsetAwake();
ASSERT_FALSE(bB->IsAwake());
SetAwake(c);
EXPECT_TRUE(bA->IsAwake());
EXPECT_TRUE(bB->IsAwake());
}
{
auto world = World{};
auto c = Contact{fA, 0u, fB, 0u};
ASSERT_NEAR(static_cast<double>(c.GetFriction()), static_cast<double>(Real{GetFriction(shape)}), 0.01);
c.SetFriction(GetFriction(shape) * Real(2));
ASSERT_NE(c.GetFriction(), GetFriction(shape));
ResetFriction(c);
EXPECT_NEAR(static_cast<double>(c.GetFriction()), static_cast<double>(Real{GetFriction(shape)}), 0.01);
}
{
auto world = World{};
auto c = Contact{fA, 0u, fB, 0u};
ASSERT_EQ(c.GetRestitution(), GetRestitution(shape));
c.SetRestitution(Real(2));
ASSERT_NE(c.GetRestitution(), GetRestitution(shape));
ResetRestitution(c);
EXPECT_EQ(c.GetRestitution(), GetRestitution(shape));
}