PageRenderTime 59ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/MongoDB.Driver.Core.Tests/Core/Misc/ExponentiallyWeightedMovingAverageTests.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 66 lines | 44 code | 8 blank | 14 comment | 0 complexity | 4717892a85a2fc3dfc9cffbf0732e510 MD5 | raw file
Possible License(s): Apache-2.0
  1. /* Copyright 2013-present MongoDB Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. using System;
  16. using FluentAssertions;
  17. using MongoDB.Driver.Core.Misc;
  18. using Xunit;
  19. namespace MongoDB.Driver.Core.Misc
  20. {
  21. public class ExponentiallyWeightedMovingAverageTests
  22. {
  23. [Theory]
  24. [InlineData(-0.001)]
  25. [InlineData(-0.01)]
  26. [InlineData(-0.1)]
  27. [InlineData(-1)]
  28. public void Constructor_should_throw_an_ArgumentOutOfRangeException_if_alpha_is_below_0(double alpha)
  29. {
  30. Action act = () => new ExponentiallyWeightedMovingAverage(alpha);
  31. act.ShouldThrow<ArgumentOutOfRangeException>();
  32. }
  33. [Theory]
  34. [InlineData(1.001)]
  35. [InlineData(1.01)]
  36. [InlineData(1.1)]
  37. [InlineData(2)]
  38. public void Constructor_should_throw_an_ArgumentOutOfRangeException_if_alpha_is_above_1(double alpha)
  39. {
  40. Action act = () => new ExponentiallyWeightedMovingAverage(alpha);
  41. act.ShouldThrow<ArgumentOutOfRangeException>();
  42. }
  43. [Theory]
  44. [InlineData(0.2, new[] { 10 }, 10)]
  45. [InlineData(0.2, new[] { 10, 20 }, 12)]
  46. [InlineData(0.2, new[] { 10, 20, 12 }, 12)]
  47. [InlineData(0.2, new[] { 10, 20, 12, 17 }, 13)]
  48. public void Average_should_be_properly_computed(double alpha, int[] samples, double result)
  49. {
  50. var subject = new ExponentiallyWeightedMovingAverage(alpha);
  51. foreach (var sample in samples)
  52. {
  53. subject.AddSample(TimeSpan.FromMilliseconds(sample));
  54. }
  55. subject.Average.TotalMilliseconds.Should().Be(result);
  56. }
  57. }
  58. }