-
-
Save slumos/5165256 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using NUnit.Framework; | |
using metrics.Stats; | |
namespace metrics.Tests.Stats | |
{ | |
[TestFixture] | |
public class ExponentiallyDecayingSampleTests | |
{ | |
[Test] | |
public void HoldsRequestedNumberOfSamples() | |
{ | |
var reservoirSize = 1000; | |
var sample = new ExponentiallyDecayingSample(reservoirSize, 0); | |
for (var i = 0; i < reservoirSize; i++) | |
{ | |
sample.Update(i); | |
} | |
Assert.AreEqual(reservoirSize, sample.Count); | |
Assert.AreEqual(reservoirSize, sample.Values.Count); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WebBase : NancyModule | |
{ | |
private ExponentiallyDecayingSample _sample; | |
public WebBase() | |
{ | |
Setup(); | |
Get["/sampling"] = param => | |
{ | |
_sample.Clear(); | |
for (int i = 0; i < 100; i++) | |
{ | |
_sample.Update(i); | |
} | |
var values = new List<long>(_sample.Values); | |
values.Sort(); | |
return string.Join(",", values); | |
}; | |
} | |
private void Setup() | |
{ | |
_sample = new ExponentiallyDecayingSample(1024, 0.15); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment