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 {
|
2019-06-14 05:15:15 +00:00
|
|
|
struct MockComponent : IComponent {
|
2019-06-13 02:51:36 +00:00
|
|
|
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-14 05:15:15 +00:00
|
|
|
MockComponent mockComponent;
|
2019-06-13 02:51:36 +00:00
|
|
|
mockComponent.myInt = 3;
|
2019-06-14 05:15:15 +00:00
|
|
|
mockComponent.myString = "hello";
|
|
|
|
|
|
|
|
entity.AddComponent<MockComponent>(mockComponent);
|
2019-06-13 02:51:36 +00:00
|
|
|
|
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();
|
|
|
|
|
2019-06-14 05:15:15 +00:00
|
|
|
MockComponent mockComponentA;
|
|
|
|
mockComponentA.myInt = 3;
|
|
|
|
mockComponentA.myString = "hello";
|
|
|
|
|
|
|
|
MockComponent mockComponentB;
|
|
|
|
mockComponentB.myInt = 5;
|
|
|
|
mockComponentB.myString = "wassup";
|
|
|
|
|
|
|
|
MockComponent mockComponentC;
|
|
|
|
mockComponentC.myInt = 1;
|
|
|
|
mockComponentC.myString = "howdy";
|
|
|
|
|
|
|
|
entity.AddComponent<MockComponent>(mockComponentA);
|
|
|
|
entity.AddComponent<MockComponent>(mockComponentB);
|
|
|
|
entity.AddComponent<MockComponent>(mockComponentC);
|
2019-06-14 03:41:21 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2019-06-14 05:15:15 +00:00
|
|
|
MockComponent mockComponent;
|
2019-06-14 03:41:21 +00:00
|
|
|
mockComponent.myInt = 3;
|
2019-06-14 05:15:15 +00:00
|
|
|
mockComponent.myString = "hello";
|
|
|
|
|
|
|
|
entity.AddComponent<MockComponent>(mockComponent);
|
2019-06-14 03:41:21 +00:00
|
|
|
|
|
|
|
world.Update();
|
|
|
|
|
|
|
|
Assert.AreEqual(mockComponent, entity.GetComponent<MockComponent>());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void HasComponent()
|
|
|
|
{
|
|
|
|
var world = new World();
|
|
|
|
var entity = world.CreateEntity();
|
|
|
|
|
2019-06-14 05:15:15 +00:00
|
|
|
MockComponent mockComponent;
|
|
|
|
mockComponent.myInt = 3;
|
|
|
|
mockComponent.myString = "hello";
|
|
|
|
|
|
|
|
entity.AddComponent<MockComponent>(mockComponent);
|
2019-06-14 03:41:21 +00:00
|
|
|
|
|
|
|
world.Update();
|
|
|
|
|
|
|
|
Assert.IsTrue(entity.HasComponent<MockComponent>());
|
2019-06-13 02:51:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|