|
|
@@ -60,3 +60,79 @@ void SceneTest::TearDown() {
|
|
|
dispatch_.reset();
|
|
|
renderer_.reset();
|
|
|
}
|
|
|
+
|
|
|
+using testing::Ref;
|
|
|
+
|
|
|
+TEST_F(SceneTest, WillCollideOverlappingObjects) {
|
|
|
+ math::dim2::rectangle bnds{{{0.f, 0.f}}, {{1.f, 1.f}}};
|
|
|
+ mock_collidable one{bnds}, two{bnds};
|
|
|
+ scene().add_with(1, one);
|
|
|
+ scene().add_as(1, two);
|
|
|
+ EXPECT_CALL(one, collide(Ref(two))).Times(1);
|
|
|
+ scene().update(0.f);
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(SceneTest, CollisionIsOneWay) {
|
|
|
+ math::dim2::rectangle bnds{{{0.f, 0.f}}, {{1.f, 1.f}}};
|
|
|
+ mock_collidable one{bnds}, two{bnds};
|
|
|
+ scene().add_with(1, one);
|
|
|
+ scene().add_as(1, two);
|
|
|
+ EXPECT_CALL(one, collide(Ref(two))).Times(1);
|
|
|
+ EXPECT_CALL(two, collide(Ref(one))).Times(0);
|
|
|
+ scene().update(0.f);
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(SceneTest, ObjectCannotCollideSelf) {
|
|
|
+ math::dim2::rectangle bnds{{{0.f, 0.f}}, {{1.f, 1.f}}};
|
|
|
+ mock_collidable one{bnds};
|
|
|
+ scene().add_with(1, one);
|
|
|
+ scene().add_as(1, one);
|
|
|
+ EXPECT_CALL(one, collide(Ref(one))).Times(0);
|
|
|
+ scene().update(0.f);
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(SceneTest, CollisionMatchesAsWithKeys) {
|
|
|
+ math::dim2::rectangle bnds{{{0.f, 0.f}}, {{1.f, 1.f}}};
|
|
|
+ mock_collidable one{bnds}, two{bnds}, three{bnds};
|
|
|
+ scene().add_with(2, one);
|
|
|
+ scene().add_as(1, two);
|
|
|
+ scene().add_as(2, three);
|
|
|
+ EXPECT_CALL(one, collide(Ref(two))).Times(0);
|
|
|
+ EXPECT_CALL(one, collide(Ref(three))).Times(1);
|
|
|
+ scene().update(0.f);
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(SceneTest, ObjectCanBeInMultipleCollidesWithGroups) {
|
|
|
+ math::dim2::rectangle bnds{{{0.f, 0.f}}, {{1.f, 1.f}}};
|
|
|
+ mock_collidable one{bnds}, two{bnds}, three{bnds};
|
|
|
+ scene().add_with(1, one);
|
|
|
+ scene().add_with(2, one);
|
|
|
+ scene().add_as(1, two);
|
|
|
+ scene().add_as(2, three);
|
|
|
+ EXPECT_CALL(one, collide(Ref(two))).Times(1);
|
|
|
+ EXPECT_CALL(one, collide(Ref(three))).Times(1);
|
|
|
+ scene().update(0.f);
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(SceneTest, ObjectCanBeInMultipleCollidableAsGroups) {
|
|
|
+ math::dim2::rectangle bnds{{{0.f, 0.f}}, {{1.f, 1.f}}};
|
|
|
+ mock_collidable one{bnds}, two{bnds}, three{bnds};
|
|
|
+ scene().add_with(1, one);
|
|
|
+ scene().add_with(2, three);
|
|
|
+ scene().add_as(1, two);
|
|
|
+ scene().add_as(2, two);
|
|
|
+ EXPECT_CALL(one, collide(Ref(two))).Times(1);
|
|
|
+ EXPECT_CALL(three, collide(Ref(two))).Times(1);
|
|
|
+ scene().update(0.f);
|
|
|
+}
|
|
|
+
|
|
|
+TEST_F(SceneTest, DoubleCollisionDoesNotOccur) {
|
|
|
+ math::dim2::rectangle bnds{{{0.f, 0.f}}, {{1.f, 1.f}}};
|
|
|
+ mock_collidable one{bnds}, two{bnds};
|
|
|
+ scene().add_with(1, one);
|
|
|
+ scene().add_with(2, one);
|
|
|
+ scene().add_as(1, two);
|
|
|
+ scene().add_as(2, two);
|
|
|
+ EXPECT_CALL(one, collide(Ref(two))).Times(1);
|
|
|
+ scene().update(0.f);
|
|
|
+}
|