PercentileSelectorTests.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using Masuit.Tools.Maths;
  3. using Xunit;
  4. namespace Masuit.Tools.Abstractions.Test.Maths;
  5. public class PercentileSelectorTests
  6. {
  7. [Theory]
  8. [InlineData(new[] { 1, 2, 3, 4, 5 }, 50, 3)]
  9. [InlineData(new[] { 1, 2, 3, 4, 5 }, 100, 5)]
  10. [InlineData(new[] { 1, 2, 3, 4, 5, 6 }, 50, 3)]
  11. [InlineData(new[] { 1, 2, 3, 4, 5, 6 }, 75, 5)]
  12. public void Percentile_ShouldReturnCorrectElement(int[] arr, double percentile, int expected)
  13. {
  14. var result = arr.Percentile(percentile);
  15. Assert.Equal(expected, result);
  16. }
  17. [Fact]
  18. public void Percentile_ShouldReturnDefaultForEmptyArray()
  19. {
  20. var arr = new int[] { };
  21. var result = arr.Percentile(50);
  22. Assert.Equal(default, result);
  23. }
  24. [Theory]
  25. [InlineData(new[] { 1.0, 2.0, 3.0, 4.0, 5.0 }, 50, 3.0)]
  26. [InlineData(new[] { 1.0, 2.0, 3.0, 4.0, 5.0 }, 100, 5.0)]
  27. [InlineData(new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }, 50, 3.0)]
  28. [InlineData(new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }, 75, 5.0)]
  29. public void Percentile_ShouldReturnCorrectElementForDoubles(double[] arr, double percentile, double expected)
  30. {
  31. var result = arr.Percentile(percentile);
  32. Assert.Equal(expected, result);
  33. }
  34. }