2019-06-13 02:51:36 +00:00
|
|
|
using NUnit.Framework;
|
2019-06-14 03:41:21 +00:00
|
|
|
using System.Linq;
|
2019-06-13 02:51:36 +00:00
|
|
|
|
|
|
|
namespace Encompass
|
|
|
|
{
|
|
|
|
namespace Tests {
|
|
|
|
class MockComponent : Component {
|
|
|
|
public string myString;
|
|
|
|
public int myInt;
|
|
|
|
}
|
|
|
|
|
|
|
|
public class EntityTest
|
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void AddComponent()
|
|
|
|
{
|
2019-06-14 03:28:26 +00:00
|
|
|
var world = new World();
|
|
|
|
var entity = world.CreateEntity();
|
|
|
|
|
2019-06-13 02:51:36 +00:00
|
|
|
var mockComponent = entity.AddComponent<MockComponent>();
|
|
|
|
mockComponent.myString = "hello";
|
|
|
|
mockComponent.myInt = 3;
|
|
|
|
|
2019-06-14 03:28:26 +00:00
|
|
|
world.Update();
|
|
|
|
|
2019-06-13 02:51:36 +00:00
|
|
|
Assert.IsTrue(entity.HasComponent<MockComponent>());
|
2019-06-14 03:41:21 +00:00
|
|
|
Assert.AreEqual(mockComponent, entity.GetComponent<MockComponent>());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetComponents()
|
|
|
|
{
|
|
|
|
var world = new World();
|
|
|
|
var entity = world.CreateEntity();
|
|
|
|
|
|
|
|
var mockComponentA = entity.AddComponent<MockComponent>();
|
|
|
|
var mockComponentB = entity.AddComponent<MockComponent>();
|
|
|
|
var mockComponentC = entity.AddComponent<MockComponent>();
|
|
|
|
|
|
|
|
world.Update();
|
|
|
|
|
|
|
|
Assert.Contains(mockComponentA, entity.GetComponents<MockComponent>().ToList());
|
|
|
|
Assert.Contains(mockComponentB, entity.GetComponents<MockComponent>().ToList());
|
|
|
|
Assert.Contains(mockComponentC, entity.GetComponents<MockComponent>().ToList());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetComponent()
|
|
|
|
{
|
|
|
|
var world = new World();
|
|
|
|
var entity = world.CreateEntity();
|
|
|
|
|
|
|
|
var mockComponent = entity.AddComponent<MockComponent>();
|
|
|
|
mockComponent.myString = "hello";
|
|
|
|
mockComponent.myInt = 3;
|
|
|
|
|
|
|
|
world.Update();
|
|
|
|
|
|
|
|
Assert.AreEqual(mockComponent, entity.GetComponent<MockComponent>());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void HasComponent()
|
|
|
|
{
|
|
|
|
var world = new World();
|
|
|
|
var entity = world.CreateEntity();
|
|
|
|
|
|
|
|
var mockComponent = entity.AddComponent<MockComponent>();
|
|
|
|
|
|
|
|
world.Update();
|
|
|
|
|
|
|
|
Assert.IsTrue(entity.HasComponent<MockComponent>());
|
2019-06-13 02:51:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|