encompass-cs/test/GeneralRendererTest.cs

72 lines
2.0 KiB
C#
Raw Normal View History

2019-06-20 01:01:08 +00:00
using NUnit.Framework;
using Encompass;
namespace Tests
{
public static class GeneralRendererTest
2019-06-20 01:01:08 +00:00
{
2020-03-20 22:45:58 +00:00
struct AComponent { }
2019-06-20 01:01:08 +00:00
public class SingletonRead
{
2019-11-21 03:01:29 +00:00
static (AComponent, Entity) result;
2019-06-20 01:01:08 +00:00
class TestRenderer : GeneralRenderer
{
public override void Render()
{
2020-03-23 02:10:28 +00:00
ref readonly var entity = ref ReadEntity<AComponent>();
result = (GetComponent<AComponent>(entity), entity);
2019-06-20 01:01:08 +00:00
}
}
[Test]
public void SingletonComponent()
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddGeneralRenderer(new TestRenderer(), 1);
2019-06-20 01:01:08 +00:00
AComponent aComponent;
var entity = worldBuilder.CreateEntity();
2019-11-21 03:01:29 +00:00
worldBuilder.SetComponent(entity, aComponent);
2019-06-20 01:01:08 +00:00
var world = worldBuilder.Build();
world.Update(0.01f);
world.Draw();
world.Update(0.01);
world.Draw();
2019-11-21 03:01:29 +00:00
Assert.That(result, Is.EqualTo((aComponent, entity)));
2019-06-20 01:01:08 +00:00
}
[Test]
public void MultipleComponents()
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddGeneralRenderer(new TestRenderer(), 1);
2019-06-20 01:01:08 +00:00
AComponent aComponent;
AComponent aComponentTwo;
var entity = worldBuilder.CreateEntity();
2019-11-21 03:01:29 +00:00
worldBuilder.SetComponent(entity, aComponent);
var entityB = worldBuilder.CreateEntity();
2019-11-21 03:01:29 +00:00
worldBuilder.SetComponent(entityB, aComponentTwo);
2019-06-20 01:01:08 +00:00
var world = worldBuilder.Build();
world.Update(0.01f);
world.Draw();
2019-06-20 01:01:08 +00:00
world.Update(0.01f);
2019-08-01 23:48:02 +00:00
world.Draw();
2019-11-21 03:01:29 +00:00
Assert.That(result, Is.EqualTo((aComponent, entity)).Or.EqualTo((aComponentTwo, entityB)));
2019-06-20 01:01:08 +00:00
}
}
}
}