add more query tests

pull/5/head
Evan Hemsley 2019-12-22 11:44:35 -08:00
parent 50974c181a
commit 120fb738d7
1 changed files with 211 additions and 0 deletions

View File

@ -1238,6 +1238,217 @@ namespace Tests
queriedEntities.ToArray().Should().BeEquivalentTo(new Entity[] { entityD });
}
[Reads(typeof(MockComponent))]
[WritesPending(typeof(MockComponentB))]
[Writes(typeof(MockComponentB), 0)]
class AddPendingComponentEngine : Engine
{
public override void Update(double dt)
{
foreach (var entity in QueryEntities().With<MockComponent>())
{
SetComponent(entity, new MockComponentB());
}
}
}
[ReadsPending(typeof(MockComponentB))]
class EntityQueryWithPendingComponentsEngine : Engine
{
private List<Entity> entities;
public EntityQueryWithPendingComponentsEngine(List<Entity> entities)
{
this.entities = entities;
}
public override void Update(double dt)
{
entities.Clear();
entities.AddRange(QueryEntities().With<MockComponentB>());
}
}
[Test]
public void EntitiesWithPendingComponents()
{
var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity();
var entityB = worldBuilder.CreateEntity();
worldBuilder.SetComponent(entity, new MockComponent());
var queriedEntities = new List<Entity>();
worldBuilder.AddEngine(new AddPendingComponentEngine());
worldBuilder.AddEngine(new EntityQueryWithPendingComponentsEngine(queriedEntities));
var world = worldBuilder.Build();
world.Update(0.01);
queriedEntities.ToArray().Should().BeEquivalentTo(new Entity[] { entity });
}
[ReadsPending(typeof(MockComponentB))]
class EntityQueryWithoutPendingComponentsEngine : Engine
{
private List<Entity> entities;
public EntityQueryWithoutPendingComponentsEngine(List<Entity> entities)
{
this.entities = entities;
}
public override void Update(double dt)
{
entities.Clear();
entities.AddRange(QueryEntities().Without<MockComponentB>());
}
}
[Test]
public void EntitiesWithoutPendingComponents()
{
var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity();
var entityB = worldBuilder.CreateEntity();
worldBuilder.SetComponent(entity, new MockComponent());
var queriedEntities = new List<Entity>();
worldBuilder.AddEngine(new AddPendingComponentEngine());
worldBuilder.AddEngine(new EntityQueryWithoutPendingComponentsEngine(queriedEntities));
var world = worldBuilder.Build();
world.Update(0.01);
queriedEntities.ToArray().Should().BeEquivalentTo(new Entity[] { entityB });
}
[Reads(typeof(MockComponentC), typeof(MockComponentD))]
[WritesPending(typeof(MockComponent), typeof(MockComponentB))]
[Writes(typeof(MockComponent), 0)]
[Writes(typeof(MockComponentB), 0)]
class ConditionallyAddPendingComponentsEngine : Engine
{
public override void Update(double dt)
{
foreach (var entity in QueryEntities().With<MockComponentC>())
{
SetComponent(entity, new MockComponent());
}
foreach (var entity in QueryEntities().With<MockComponentD>())
{
SetComponent(entity, new MockComponent());
SetComponent(entity, new MockComponentB());
}
}
}
[ReadsPending(typeof(MockComponent), typeof(MockComponentB))]
class EntityQueryWithAndWithoutPendingComponentsEngine : Engine
{
private List<Entity> entities;
public EntityQueryWithAndWithoutPendingComponentsEngine(List<Entity> entities)
{
this.entities = entities;
}
public override void Update(double dt)
{
entities.Clear();
entities.AddRange(QueryEntities().With<MockComponent>().Without<MockComponentB>());
}
}
[Test]
public void EntitiesWithAndWithoutPendingComponents()
{
var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity();
var entityB = worldBuilder.CreateEntity();
var entityC = worldBuilder.CreateEntity();
worldBuilder.SetComponent(entityB, new MockComponentC());
worldBuilder.SetComponent(entityC, new MockComponentD());
var queriedEntities = new List<Entity>();
worldBuilder.AddEngine(new ConditionallyAddPendingComponentsEngine());
worldBuilder.AddEngine(new EntityQueryWithAndWithoutPendingComponentsEngine(queriedEntities));
var world = worldBuilder.Build();
world.Update(0.01);
queriedEntities.ToArray().Should().BeEquivalentTo(new Entity[] { entityB });
}
[Reads(typeof(MockComponentC))]
[WritesPending(typeof(MockComponentB))]
[Writes(typeof(MockComponentB), 0)]
class ConditionallyAddPendingComponentEngine : Engine
{
public override void Update(double dt)
{
foreach (var entity in QueryEntities().With<MockComponentC>())
{
SetComponent(entity, new MockComponentB());
}
}
}
[ReadsPending(typeof(MockComponentB))]
[Reads(typeof(MockComponent))]
class EntityQueryWithPendingAndNonPendingComponents : Engine
{
private List<Entity> entities;
public EntityQueryWithPendingAndNonPendingComponents(List<Entity> entities)
{
this.entities = entities;
}
public override void Update(double dt)
{
entities.Clear();
entities.AddRange(QueryEntities().With<MockComponent>().With<MockComponentB>());
}
}
[Test]
public void EntitiesWithPendingAndNonPendingComponents()
{
var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity();
var entityB = worldBuilder.CreateEntity();
var entityC = worldBuilder.CreateEntity();
worldBuilder.SetComponent(entityB, new MockComponent());
worldBuilder.SetComponent(entityB, new MockComponentC());
worldBuilder.SetComponent(entityC, new MockComponentD());
var queriedEntities = new List<Entity>();
worldBuilder.AddEngine(new ConditionallyAddPendingComponentEngine());
worldBuilder.AddEngine(new EntityQueryWithPendingAndNonPendingComponents(queriedEntities));
var world = worldBuilder.Build();
world.Update(0.01);
queriedEntities.ToArray().Should().BeEquivalentTo(new Entity[] { entityB });
}
}
}
}