blob: b06780ba1aec5d16f78f3aba7a3978262074acb9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
using System.Collections.Specialized;
using MonoGame.Extended.Sprites;
using Xunit;
namespace MonoGame.Extended.Entities.Tests
{
public class DummyComponent
{
}
public class AspectTests
{
private readonly ComponentManager _componentManager;
private readonly BitVector32 _entityA;
private readonly BitVector32 _entityB;
public AspectTests()
{
_componentManager = new ComponentManager();
_entityA = new BitVector32
{
[1 << _componentManager.GetComponentTypeId(typeof(Transform2))] = true,
[1 << _componentManager.GetComponentTypeId(typeof(Sprite))] = true,
[1 << _componentManager.GetComponentTypeId(typeof(DummyComponent))] = true
};
_entityB = new BitVector32
{
[1 << _componentManager.GetComponentTypeId(typeof(Transform2))] = true,
[1 << _componentManager.GetComponentTypeId(typeof(Sprite))] = true,
};
}
[Fact]
public void EmptyAspectMatchesAllComponents()
{
var componentManager = new ComponentManager();
var emptyAspect = Aspect.All()
.Build(componentManager);
Assert.True(emptyAspect.IsInterested(_entityA));
Assert.True(emptyAspect.IsInterested(_entityB));
}
[Fact]
public void IsInterestedInAllComponents()
{
var allAspect = Aspect
.All(typeof(Sprite), typeof(Transform2), typeof(DummyComponent))
.Build(_componentManager);
Assert.True(allAspect.IsInterested(_entityA));
Assert.False(allAspect.IsInterested(_entityB));
}
[Fact]
public void IsInterestedInEitherOneOfTheComponents()
{
var eitherOneAspect = Aspect
.One(typeof(Transform2), typeof(DummyComponent))
.Build(_componentManager);
Assert.True(eitherOneAspect.IsInterested(_entityA));
Assert.True(eitherOneAspect.IsInterested(_entityB));
}
[Fact]
public void IsInterestedInJustOneComponent()
{
var oneAspect = Aspect
.One(typeof(DummyComponent))
.Build(_componentManager);
Assert.True(oneAspect.IsInterested(_entityA));
Assert.False(oneAspect.IsInterested(_entityB));
}
[Fact]
public void IsInterestedInExcludingOneComponent()
{
var oneAspect = Aspect
.Exclude(typeof(DummyComponent))
.Build(_componentManager);
Assert.False(oneAspect.IsInterested(_entityA));
Assert.True(oneAspect.IsInterested(_entityB));
}
}
}
|