Created
January 22, 2016 18:47
-
-
Save BGR360/5237be5cd9b5229ca693 to your computer and use it in GitHub Desktop.
Excerpt from GameEngineTests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Testing.h> | |
#include <cstdlib> | |
#include <ctime> | |
#include <string> | |
#include <sstream> | |
#include <vector> | |
#include <core/GameObject.h> | |
#include <math/RandomGenerator.h> | |
using std::string; | |
using std::stringstream; | |
using std::vector; | |
using Math::RandomGenerator; | |
using Core::GameObject; | |
using Core::GameComponent; | |
using Core::Transform; | |
//For use in the GameObject.UpdateHierarchy test | |
vector<int> updateOrder; | |
TEST(GameObject, DefaultConstruction) | |
{ | |
GameObject gameObject; | |
int numComponents = gameObject.getNumComponents(); | |
int numChildren = gameObject.getNumChildren(); | |
EXPECT_EQ(0, numComponents); | |
EXPECT_EQ(0, numChildren); | |
} | |
TEST(GameObject, AddComponent) | |
{ | |
RandomGenerator* rng = RandomGenerator::getInstance(); | |
int numComponentsToAdd = rng->irand(1, 10); | |
int numTimes = rng->irand(1, 10); | |
for (int i = 0; i < numTimes; i++) | |
{ | |
GameObject gameObject; | |
for (int j = 0; j < numComponentsToAdd; j++) | |
{ | |
gameObject.addComponent(new GameComponent); | |
} | |
int numComponents = gameObject.getNumComponents(); | |
int numChildren = gameObject.getNumChildren(); | |
EXPECT_EQ(numComponentsToAdd, numComponents); | |
EXPECT_EQ(0, numChildren); | |
} | |
} | |
TEST(GameObject, AddChildren) | |
{ | |
GameObject parent; | |
GameObject* child1, *child2, *child3, *child4, *child5; | |
child1 = new GameObject; | |
child2 = new GameObject; | |
child3 = new GameObject; | |
child4 = new GameObject; | |
child5 = new GameObject; | |
parent.addChild(child1); | |
parent.addChild(child2); | |
parent.addChild(child3); | |
parent.addChild(child4); | |
parent.addChild(child5); | |
EXPECT_EQ(5, parent.getNumChildren()); | |
} | |
TEST(GameObject, ChildHierarchy) | |
{ | |
GameObject root; | |
GameObject* child1, *child2, *child3; | |
GameObject* child1_child1, *child1_child2, *child3_child1; | |
GameObject* child1_child2_child1; | |
child1 = new GameObject; | |
child2 = new GameObject; | |
child3 = new GameObject; | |
child1_child1 = new GameObject; | |
child1_child2 = new GameObject; | |
child3_child1 = new GameObject; | |
child1_child2_child1 = new GameObject; | |
root.addChild(child1); | |
root.addChild(child2); | |
root.addChild(child3); | |
child1->addChild(child1_child1); | |
child1->addChild(child1_child2); | |
child3->addChild(child3_child1); | |
child1_child2->addChild(child1_child2_child1); | |
EXPECT_EQ(3, root.getNumChildren()); | |
EXPECT_EQ(2, child1->getNumChildren()); | |
EXPECT_EQ(1, child3->getNumChildren()); | |
EXPECT_EQ(1, child1_child2->getNumChildren()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment