diff options
author | chai <215380520@qq.com> | 2024-06-03 10:15:45 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-06-03 10:15:45 +0800 |
commit | acea7b2e728787a0d83bbf83c8c1f042d2c32e7e (patch) | |
tree | 0bfec05c1ca2d71be2c337bcd110a0421f19318b /Plugins/MonoGame.Extended/tests/MonoGame.Extended.Entities.Tests/AspectTests.cs | |
parent | 88febcb02bf127d961c6471d9e846c0e1315f5c3 (diff) |
+ plugins project
Diffstat (limited to 'Plugins/MonoGame.Extended/tests/MonoGame.Extended.Entities.Tests/AspectTests.cs')
-rw-r--r-- | Plugins/MonoGame.Extended/tests/MonoGame.Extended.Entities.Tests/AspectTests.cs | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Entities.Tests/AspectTests.cs b/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Entities.Tests/AspectTests.cs new file mode 100644 index 0000000..b06780b --- /dev/null +++ b/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Entities.Tests/AspectTests.cs @@ -0,0 +1,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)); + } + } +}
\ No newline at end of file |