Skip to content

Commit

Permalink
For issue #6: Surpassing 90% unit test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-langholtz committed Jul 26, 2017
1 parent c35f1d3 commit 3b97c50
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
1 change: 1 addition & 0 deletions Build/xcode5/PlayRho.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,7 @@
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 3;
GCC_PREPROCESSOR_DEFINITIONS = "NDEBUG=1";
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
Expand Down
5 changes: 1 addition & 4 deletions PlayRho/Collision/Manifold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,10 +857,7 @@ bool playrho::operator==(const Manifold& lhs, const Manifold& rhs) noexcept
return false;
}

if (IsValid(lhs.GetLocalNormal()) != IsValid(rhs.GetLocalNormal()))
{
return false;
}
assert(IsValid(lhs.GetLocalNormal()) == IsValid(rhs.GetLocalNormal()));

if (IsValid(lhs.GetLocalNormal()) && (lhs.GetLocalNormal() != rhs.GetLocalNormal()))
{
Expand Down
18 changes: 18 additions & 0 deletions UnitTests/Manifold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ TEST(Manifold, EqualsFreeFunction)
const auto poo = Manifold::GetForFaceA(ln0, lp0);
const auto goo = Manifold::GetForFaceA(ln0, lp1);
const auto too = Manifold::GetForFaceA(ln1, lp0);
//const auto nottoo = Manifold::GetForFaceA(UnitVec2{}, lp0);
const auto localPoint1 = Length2D{Real(1) * Meter, Real(2) * Meter};
const auto cf1 = ContactFeature{ContactFeature::e_vertex, 1, ContactFeature::e_vertex, 2};
const auto cf2 = ContactFeature{ContactFeature::e_vertex, 0, ContactFeature::e_vertex, 1};
const auto normalImpulse1 = Momentum{Real(1) * Kilogram * MeterPerSecond};
const auto tangentImpulse1 = Momentum{Real(2) * Kilogram * MeterPerSecond};
const auto mp0 = Manifold::Point{localPoint1, cf1, normalImpulse1, tangentImpulse1};
const auto mp1 = Manifold::Point{localPoint1, cf2, normalImpulse1, tangentImpulse1};
const auto faceA000 = Manifold::GetForFaceA(ln0, lp0, mp0);
const auto faceA0001 = Manifold::GetForFaceA(ln0, lp0, mp0, mp1);
const auto faceA001 = Manifold::GetForFaceA(ln0, lp0, mp1);
const auto faceA0010 = Manifold::GetForFaceA(ln0, lp0, mp1, mp0);
const auto faceA0011 = Manifold::GetForFaceA(ln0, lp0, mp1, mp1);
EXPECT_TRUE(Manifold{} == Manifold{});
EXPECT_TRUE(foo == foo);
EXPECT_TRUE(boo == boo);
Expand All @@ -216,6 +229,11 @@ TEST(Manifold, EqualsFreeFunction)
EXPECT_FALSE(foo == boo);
EXPECT_FALSE(poo == goo);
EXPECT_FALSE(poo == too);
//EXPECT_FALSE(too == nottoo);
EXPECT_FALSE(faceA000 == foo);
EXPECT_FALSE(faceA000 == faceA001);
EXPECT_TRUE(faceA0001 == faceA0010);
EXPECT_FALSE(faceA0010 == faceA0011);
}

TEST(Manifold, NotEqualsFreeFunction)
Expand Down
41 changes: 41 additions & 0 deletions UnitTests/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,47 @@ TEST(World, AwakenFreeFunction)
EXPECT_TRUE(body->IsAwake());
}

TEST(World, GetTouchingCountFreeFunction)
{
World world;
EXPECT_EQ(GetTouchingCount(world), ContactCounter(0));
auto stepConf = StepConf{};
world.Step(stepConf);
EXPECT_EQ(GetTouchingCount(world), ContactCounter(0));
stepConf.SetInvTime(Real(100) * Hertz);
world.Step(stepConf);
EXPECT_EQ(GetTouchingCount(world), ContactCounter(0));
}

TEST(World, IsValidShapeMethod)
{
World world;
EXPECT_FALSE(world.IsValid(std::shared_ptr<const Shape>(nullptr)));

const auto radius = Real(1) * Meter;
const auto shape = std::make_shared<DiskShape>(radius);
EXPECT_TRUE(world.IsValid(shape));
}

TEST(World, ShiftOrigin)
{
const auto origin = Length2D{Real(0) * Meter, Real(0) * Meter};
const auto location = Length2D{Real(1) * Meter, Real(1) * Meter};

ASSERT_NE(origin, location);

World world;
EXPECT_NO_THROW(world.ShiftOrigin(origin));

auto bodyDef = BodyDef{};
bodyDef.UseLocation(location);
const auto body = world.CreateBody(bodyDef);
EXPECT_EQ(body->GetLocation(), location);

EXPECT_NO_THROW(world.ShiftOrigin(location));
EXPECT_EQ(body->GetLocation(), origin);
}

TEST(World, DynamicEdgeBodyHasCorrectMass)
{
World world;
Expand Down

0 comments on commit 3b97c50

Please sign in to comment.