浏览代码

Add tests for engine::scene for all collision_t enum rules.
TODO: Test non-overlapping objects
FAILING: SceneTest.ObjectCannotCollideSelf
FAILING: SceneTest.DoubleCollisionDoesNotOccur

Sam Jaffe 6 年之前
父节点
当前提交
668e85d3f1
共有 2 个文件被更改,包括 78 次插入0 次删除
  1. 2 0
      engine/engine.xcodeproj/project.pbxproj
  2. 76 0
      engine/test/scene_test.cxx

+ 2 - 0
engine/engine.xcodeproj/project.pbxproj

@@ -24,6 +24,7 @@
 		CD8064F922D2984400B9B4E4 /* fps_counter_test.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD8064F822D2984400B9B4E4 /* fps_counter_test.cxx */; };
 		CD8064FB22D69CAE00B9B4E4 /* game_dispatch_test.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD8064FA22D69CAE00B9B4E4 /* game_dispatch_test.cxx */; };
 		CD8064FD22D9456100B9B4E4 /* scene_test.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD8064FC22D9456100B9B4E4 /* scene_test.cxx */; };
+		CD8064FE22DA621200B9B4E4 /* libmath.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = CD62D8472251A9500023219A /* libmath.dylib */; };
 		CDB1F8C81D7A312B00700C6B /* game_dispatch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDB1F8C61D7A312B00700C6B /* game_dispatch.cpp */; settings = {COMPILER_FLAGS = "-fvisibility=default"; }; };
 		CDB1F8CC1D7A319A00700C6B /* scene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDB1F8CA1D7A319A00700C6B /* scene.cpp */; settings = {COMPILER_FLAGS = "-fvisibility=default"; }; };
 		CDB1F8D21D7A32A300700C6B /* events.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDB1F8D01D7A32A300700C6B /* events.cpp */; settings = {COMPILER_FLAGS = "-fvisibility=default"; }; };
@@ -107,6 +108,7 @@
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				CD8064FE22DA621200B9B4E4 /* libmath.dylib in Frameworks */,
 				CD8064F722D22BF500B9B4E4 /* libgameutils.dylib in Frameworks */,
 				CD8064EF22D21EB500B9B4E4 /* libgraphics.dylib in Frameworks */,
 				CDED9C5222A4130700AE5CE5 /* libjsoncpp.1.8.4.dylib in Frameworks */,

+ 76 - 0
engine/test/scene_test.cxx

@@ -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);
+}