Skip to content

Instantly share code, notes, and snippets.

@slumos
Forked from besquared/gist:5164617
Last active December 14, 2015 23:19
Show Gist options
  • Save slumos/5165256 to your computer and use it in GitHub Desktop.
Save slumos/5165256 to your computer and use it in GitHub Desktop.
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);
}
}
}
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