diff options
Diffstat (limited to 'Plugins/MonoGame.Extended/tests/MonoGame.Extended.Tests/Particles')
6 files changed, 537 insertions, 0 deletions
diff --git a/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Tests/Particles/AssertionModifier.cs b/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Tests/Particles/AssertionModifier.cs new file mode 100644 index 0000000..ff23d8b --- /dev/null +++ b/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Tests/Particles/AssertionModifier.cs @@ -0,0 +1,25 @@ +//using System; +//using MonoGame.Extended.Particles; +//using MonoGame.Extended.Particles.Modifiers; +//using Xunit; + +//namespace MonoGame.Extended.Tests.Particles +//{ +// internal class AssertionModifier : Modifier +// { +// private readonly Predicate<Particle> _predicate; + +// public AssertionModifier(Predicate<Particle> predicate) +// { +// _predicate = predicate; +// } + +// public override unsafe void Update(float elapsedSeconds, ParticleBuffer.ParticleIterator iterator) +// { +// while (iterator.HasNext) { +// var particle = iterator.Next(); +// Assert.IsTrue(_predicate(*particle)); +// } +// } +// } +//}
\ No newline at end of file diff --git a/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Tests/Particles/ColourTests.cs b/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Tests/Particles/ColourTests.cs new file mode 100644 index 0000000..49b5e03 --- /dev/null +++ b/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Tests/Particles/ColourTests.cs @@ -0,0 +1,126 @@ +using System; +using Microsoft.Xna.Framework; +using Xunit; + +namespace MonoGame.Extended.Tests.Particles +{ + public class ColourTests + { + public class Constructor + { + [Fact] + public void WhenGivenValues_ReturnsInitializedColour() + { + var colour = new HslColor(1f, 1f, 1f); + Assert.Equal(1f, colour.H); + Assert.Equal(1f, colour.S); + Assert.Equal(1f, colour.L); + } + } + + public class AreEqualColourMethod + { + [Fact] + public void WhenGivenEqualValues_ReturnsTrue() + { + var x = new HslColor(360f, 1f, 1f); + var y = new HslColor(360f, 1f, 1f); + Assert.Equal(x, y); + } + + [Fact] + public void WhenGivenDifferentValues_ReturnsFalse() + { + var x = new HslColor(0f, 1f, 0f); + var y = new HslColor(360f, 1f, 1f); + Assert.False(x.Equals(y)); + } + } + + public class AreEqualObjectMethod + { + [Fact] + public void WhenGivenEqualColour_ReturnsTrue() + { + var x = new HslColor(360f, 1f, 1f); + + Object y = new HslColor(360f, 1f, 1f); + Assert.Equal(x, y); + } + + [Fact] + public void WhenGivenDifferentColour_ReturnsFalse() + { + var x = new HslColor(360f, 1f, 1f); + + Object y = new HslColor(0f, 1f, 0f); + Assert.False(x.Equals(y)); + } + + [Fact] + public void WhenGivenObjectOfAntotherType_ReturnsFalse() + { + var colour = new HslColor(360f, 1f, 1f); + + // ReSharper disable once SuspiciousTypeConversion.Global + Assert.False(colour.Equals(DateTime.Now)); + } + } + + public class GetHashCodeMethod + { + [Fact] + public void WhenObjectsAreDifferent_YieldsDifferentHashCodes() + { + var x = new HslColor(0f, 1f, 0f); + var y = new HslColor(360f, 1f, 1f); + Assert.NotEqual(x.GetHashCode(), y.GetHashCode()); + } + + [Fact] + public void WhenObjectsAreSame_YieldsIdenticalHashCodes() + { + var x = new HslColor(180f, 0.5f, 0.5f); + var y = new HslColor(180f, 0.5f, 0.5f); + Assert.Equal(x.GetHashCode(), y.GetHashCode()); + } + } + + public class ToStringMethod + { + [Theory] + [InlineData(360f, 1f, 1f, "H:0.0° S:100.0 L:100.0")] + [InlineData(180f, 0.5f, 0.5f, "H:180.0° S:50.0 L:50.0")] + [InlineData(0f, 0f, 0f, "H:0.0° S:0.0 L:0.0")] + public void ReturnsCorrectValue(float h, float s, float l, string expected) + { + var colour = new HslColor(h, s, l); + Assert.Equal(expected, colour.ToString()); + } + } + + public class ToRgbMethod + { + [Theory] + [InlineData(0f, 1f, 0.5f, "{R:255 G:0 B:0 A:255}")] // Color.Red + [InlineData(360f, 1f, 0.5f, "{R:255 G:0 B:0 A:255}")] // Color.Red + [InlineData(120f, 1f, 0.5f, "{R:0 G:255 B:0 A:255}")] // Color.Lime + public void ReturnsCorrectValue(float h, float s, float l, string expected) + { + var hslColour = new HslColor(h, s, l); + Color rgbColor = hslColour.ToRgb(); + + Assert.Equal(expected, rgbColor.ToString()); + } + + [Fact] + public void FromRgbAndToRgbWorksCorrectly() + { + HslColor blueHsl = HslColor.FromRgb(Color.Blue); + Color blueRgb = blueHsl.ToRgb(); + + Assert.Equal(Color.Blue, blueRgb); + } + } + } +} diff --git a/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Tests/Particles/EmitterTests.cs b/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Tests/Particles/EmitterTests.cs new file mode 100644 index 0000000..4ec9b65 --- /dev/null +++ b/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Tests/Particles/EmitterTests.cs @@ -0,0 +1,131 @@ +//using System; +//using Microsoft.Xna.Framework; +//using MonoGame.Extended.Particles; +//using MonoGame.Extended.Particles.Modifiers; +//using MonoGame.Extended.Particles.Profiles; +//using Xunit; + +//namespace MonoGame.Extended.Tests.Particles +//{ +// +// public class EmitterTests +// { +// public class UpdateMethod +// { +// [Fact] +// public void WhenThereAreParticlesToExpire_DecreasesActiveParticleCount() +// { +// var subject = new ParticleEmitter(null, 100, TimeSpan.FromSeconds(1), Profile.Point()) +// { +// AutoTrigger = false, +// Parameters = new ParticleReleaseParameters +// { +// Quantity = 1 +// } +// }; + +// subject.Trigger(new Vector2(0f, 0f)); +// Assert.Equal(subject.ActiveParticles, 1); + +// subject.Update(2f); +// Assert.Equal(subject.ActiveParticles, 0); +// } + +// [Fact] +// public void WhenThereAreParticlesToExpire_DoesNotPassExpiredParticlesToModifiers() +// { +// var subject = new ParticleEmitter(null, 100, TimeSpan.FromSeconds(1), Profile.Point()) +// { +// Parameters = new ParticleReleaseParameters() +// { +// Quantity = 1 +// }, +// Modifiers = +// { +// new AssertionModifier(particle => particle.Age <= 1f) +// } +// }; + +// subject.Trigger(new Vector2(0f, 0f)); +// subject.Update(0.5f); +// subject.Trigger(new Vector2(0f, 0f)); +// subject.Update(0.5f); +// subject.Trigger(new Vector2(0f, 0f)); +// subject.Update(0.5f); +// } + +// [Fact] +// public void WhenThereAreNoActiveParticles_GracefullyDoesNothing() +// { +// var subject = new ParticleEmitter(null, 100, TimeSpan.FromSeconds(1), Profile.Point()) { AutoTrigger = false }; + +// subject.Update(0.5f); +// Assert.Equal(subject.ActiveParticles, 0); +// } +// } + +// public class TriggerMethod +// { +// [Fact] +// public void WhenEnoughHeadroom_IncreasesActiveParticlesCountByReleaseQuantity() +// { +// var subject = new ParticleEmitter(null, 100, TimeSpan.FromSeconds(1), Profile.Point()) +// { +// Parameters = new ParticleReleaseParameters +// { +// Quantity = 10 +// } +// }; +// Assert.Equal(subject.ActiveParticles, 0); +// subject.Trigger(new Vector2(0f, 0f)); +// Assert.Equal(subject.ActiveParticles, 10); +// } + +// [Fact] +// public void WhenNotEnoughHeadroom_IncreasesActiveParticlesCountByRemainingParticles() +// { +// var subject = new ParticleEmitter(null, 15, TimeSpan.FromSeconds(1), Profile.Point()) +// { +// Parameters = new ParticleReleaseParameters +// { +// Quantity = 10 +// } +// }; + +// subject.Trigger(new Vector2(0f, 0f)); +// Assert.Equal(subject.ActiveParticles, 10); +// subject.Trigger(new Vector2(0f, 0f)); +// Assert.Equal(subject.ActiveParticles, 15); +// } + +// [Fact] +// public void WhenNoRemainingParticles_DoesNotIncreaseActiveParticlesCount() +// { +// var subject = new ParticleEmitter(null, 10, TimeSpan.FromSeconds(1), Profile.Point()) +// { +// Parameters = new ParticleReleaseParameters +// { +// Quantity = 10 +// } +// }; + +// subject.Trigger(new Vector2(0f, 0f)); +// Assert.Equal(subject.ActiveParticles, 10); +// subject.Trigger(new Vector2(0f, 0f)); +// Assert.Equal(subject.ActiveParticles, 10); +// } +// } + +// public class DisposeMethod +// { +// [Fact] +// public void IsIdempotent() +// { +// var subject = new ParticleEmitter(null, 10, TimeSpan.FromSeconds(1), Profile.Point()); + +// subject.Dispose(); +// subject.Dispose(); +// } +// } +// } +//}
\ No newline at end of file diff --git a/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Tests/Particles/ParticleBufferTests.cs b/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Tests/Particles/ParticleBufferTests.cs new file mode 100644 index 0000000..ef2e159 --- /dev/null +++ b/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Tests/Particles/ParticleBufferTests.cs @@ -0,0 +1,184 @@ +//using System; +//using MonoGame.Extended.Particles; +//using Xunit; + +//namespace MonoGame.Extended.Tests.Particles +//{ +// +// public class ParticleBufferTests +// { +// public class AvailableProperty +// { +// [Fact] +// public void WhenNoParticlesReleased_ReturnsBufferSize() +// { +// var subject = new ParticleBuffer(100); + +// Assert.Equal(subject.Available, 100); +// } + +// [Fact] +// public void WhenSomeParticlesReleased_ReturnsAvailableCount() +// { +// var subject = new ParticleBuffer(100); + +// subject.Release(10); +// Assert.Equal(subject.Available, 90); +// } + +// [Fact] +// public void WhenAllParticlesReleased_ReturnsZero() +// { +// var subject = new ParticleBuffer(100); + +// subject.Release(100); +// Assert.Equal(subject.Available, 0); + +// } +// } + +// public class CountProperty +// { +// [Fact] +// public void WhenNoParticlesReleased_ReturnsZero() +// { +// var subject = new ParticleBuffer(100); +// Assert.Equal(subject.Count, 0); +// } + +// [Fact] +// public void WhenSomeParticlesReleased_ReturnsCount() +// { +// var subject = new ParticleBuffer(100); + +// subject.Release(10); +// Assert.Equal(subject.Count, 10); + +// } + +// [Fact] +// public void WhenAllParticlesReleased_ReturnsZero() +// { +// var subject = new ParticleBuffer(100); + +// subject.Release(100); +// Assert.Equal(subject.Count, 100); + +// } +// } + +// public class ReleaseMethod +// { +// [Fact] +// public void WhenPassedReasonableQuantity_ReturnsNumberReleased() +// { +// var subject = new ParticleBuffer(100); + +// var count = subject.Release(50); + +// Assert.Equal(count.Total, 50); +// } + +// [Fact] +// public void WhenPassedImpossibleQuantity_ReturnsNumberActuallyReleased() +// { +// var subject = new ParticleBuffer(100); + +// var count = subject.Release(200); +// Assert.Equal(count.Total, 100); +// } +// } + +// public class ReclaimMethod +// { +// [Fact] +// public void WhenPassedReasonableNumber_ReclaimsParticles() +// { +// var subject = new ParticleBuffer(100); + +// subject.Release(100); +// Assert.Equal(subject.Count, 100); + +// subject.Reclaim(50); +// Assert.Equal(subject.Count, 50); +// } +// } + +// //public class CopyToMethod +// //{ +// // [Fact] +// // public void WhenBufferIsSequential_CopiesParticlesInOrder() +// // { +// // unsafe +// // { +// // var subject = new ParticleBuffer(10); +// // var iterator = subject.Release(5); + +// // do +// // { +// // var particle = iterator.Next(); +// // particle->Age = 1f; +// // } +// // while (iterator.HasNext); + +// // var destination = new Particle[10]; + +// // fixed (Particle* buffer = destination) +// // { +// // subject.CopyTo((IntPtr)buffer); +// // } + +// // Assert.Equal(destination[0].Age, 1f, 0.0001); +// // Assert.Equal(destination[1].Age, 1f, 0.0001); +// // Assert.Equal(destination[2].Age, 1f, 0.0001); +// // Assert.Equal(destination[3].Age, 1f, 0.0001); +// // Assert.Equal(destination[4].Age, 1f, 0.0001); +// // } +// // } +// //} + +// //public class CopyToReverseMethod +// //{ +// // [Fact] +// // public void WhenBufferIsSequential_CopiesParticlesInReverseOrder() +// // { +// // unsafe +// // { +// // var subject = new ParticleBuffer(10); +// // var iterator = subject.Release(5); + +// // do +// // { +// // var particle = iterator.Next(); +// // particle->Age = 1f; +// // } +// // while (iterator.HasNext); + +// // var destination = new Particle[10]; + +// // fixed (Particle* buffer = destination) +// // { +// // subject.CopyToReverse((IntPtr)buffer); +// // } + +// // Assert.Equal(destination[0].Age, 1f, 0.0001); +// // Assert.Equal(destination[1].Age, 1f, 0.0001); +// // Assert.Equal(destination[2].Age, 1f, 0.0001); +// // Assert.Equal(destination[3].Age, 1f, 0.0001); +// // Assert.Equal(destination[4].Age, 1f, 0.0001); +// // } +// // } +// //} + +// public class DisposeMethod +// { +// [Fact] +// public void IsIdempotent() +// { +// var subject = new ParticleBuffer(100); +// subject.Dispose(); +// subject.Dispose(); +// } +// } +// } +//}
\ No newline at end of file diff --git a/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Tests/Particles/Profiles/PointProfileTests.cs b/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Tests/Particles/Profiles/PointProfileTests.cs new file mode 100644 index 0000000..cb22b3b --- /dev/null +++ b/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Tests/Particles/Profiles/PointProfileTests.cs @@ -0,0 +1,33 @@ +using System; +using MonoGame.Extended.Particles.Profiles; +using Xunit; + +namespace MonoGame.Extended.Tests.Particles.Profiles +{ + + public class PointProfileTests + { + [Fact] + public void ReturnsZeroOffset() + { + var subject = new PointProfile(); + + subject.GetOffsetAndHeading(out var offset, out _); + + Assert.Equal(0f, offset.X); + Assert.Equal(0f, offset.Y); + } + + [Fact] + public void ReturnsHeadingAsUnitVector() + { + var subject = new PointProfile(); + + subject.GetOffsetAndHeading(out _, out var heading); + + var length = Math.Sqrt(heading.X * heading.X + heading.Y * heading.Y); + Assert.Equal(1f, length, 6); + } + + } +} diff --git a/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Tests/Particles/Profiles/RingProfileTests.cs b/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Tests/Particles/Profiles/RingProfileTests.cs new file mode 100644 index 0000000..a18f5b7 --- /dev/null +++ b/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Tests/Particles/Profiles/RingProfileTests.cs @@ -0,0 +1,38 @@ +using System; +using MonoGame.Extended.Particles.Profiles; +using Xunit; + +namespace MonoGame.Extended.Tests.Particles.Profiles +{ + public class RingProfileTests + { + [Fact] + public void ReturnsOffsetEqualToRadius() + { + var subject = new RingProfile + { + Radius = 10f + }; + subject.GetOffsetAndHeading(out var offset, out _); + + var length = Math.Sqrt(offset.X * offset.X + offset.Y * offset.Y); + Assert.Equal(10f, length, 6); + } + + [Fact] + public void WhenRadiateIsTrue_HeadingIsEqualToNormalizedOffset() + { + var subject = new RingProfile + { + Radius = 10f, + Radiate = Profile.CircleRadiation.Out + }; + subject.GetOffsetAndHeading(out var offset, out var heading); + + Assert.Equal(heading.X, offset.X / 10, 6); + Assert.Equal(heading.Y, offset.Y / 10, 6); + + } + + } +} |