Exemplo n.º 1
0
    public void ShouldTimeSeriesOfEvents() {
      var signaler = new ManualResetEvent(false);
      var timer = new Timer();
      long count = 0;
      var snapshot = new Snapshot(new long[0]);

      timer.Update(10);
      timer.Update(20);
      timer.Update(20);
      timer.Update(30);
      timer.Update(40);

      timer.GetCount((x, context) => {
        count = x;
      });
      timer.GetSnapshot((x, timestamp) => snapshot = x);
      timer.Run(() => signaler.Set());

      signaler.WaitOne();

      Assert.That(count, Is.EqualTo(5));
      Assert.That(snapshot.Max, Is.InRange(40, 40.0001));
      Assert.That(snapshot.Min, Is.InRange(10, 10.0001));
      Assert.That(snapshot.Mean, Is.InRange(24, 24.0001));
      Assert.That(snapshot.StdDev, Is.InRange(11.401, 11.402));
      Assert.That(snapshot.Median, Is.InRange(20, 20.0001));
      Assert.That(snapshot[0.75], Is.InRange(35, 35.0001));
      Assert.That(snapshot[0.99], Is.InRange(40, 40.0001));
      Assert.That(snapshot.Values, Is.EqualTo(new double[] {10, 20, 20, 30, 40}));
      Assert.That(snapshot.Size, Is.EqualTo(5));
    }
Exemplo n.º 2
0
    public void ShouldTimeThroughContext() {
      var signaler = new ManualResetEvent(false);
      var timer = new Timer();
      var snapshot = new Snapshot(new long[0]);
      long count = 0;
      timer.Time().Stop();

      timer.GetCount((x, context) => count = x);
      timer.Run(() => signaler.Set());

      signaler.WaitOne();

      Assert.That(count, Is.EqualTo(1), "the timer has count of 1");
    }
Exemplo n.º 3
0
    public void ShouldCreateEmptyTimer() {
      var signaler = new ManualResetEvent(false);
      var timer = new Timer(new ClockMock());
      long count = 0;
      var snapshot = new Snapshot(new long[0]);

      timer.GetCount((x, context) => count = x);
      timer.GetSnapshot((x, timestamp) => snapshot = x);
      timer.Run(() => signaler.Set());

      signaler.WaitOne();

      Assert.That(count, Is.EqualTo(0));
      Assert.That(snapshot.Max, Is.InRange(0, 0.0001));
      Assert.That(snapshot.Min, Is.InRange(0, 0.0001));
      Assert.That(snapshot.Mean, Is.InRange(0, 0.0001));
      Assert.That(snapshot.StdDev, Is.InRange(0, 0.0001));
      Assert.That(snapshot.Median, Is.InRange(0, 0.0001));
      Assert.That(snapshot[0.75], Is.InRange(0, 0.0001));
      Assert.That(snapshot[0.99], Is.InRange(0, 0.0001));
      Assert.That(snapshot.Size, Is.EqualTo(0));
    }
Exemplo n.º 4
0
 internal static void Main(string[] args)
 {
     Timer pesho = new Timer(300);
     pesho.Run();
 }