public void PerfTest() { var heap = RealTimeQueue <int> .Empty; for (var i = 0; i < Size; i++) { heap = RealTimeQueue <int> .Snoc(heap, i); } Console.WriteLine(DumpQueue(heap, true)); var count = 0; while (!RealTimeQueue <int> .IsEmpty(heap)) { var next = RealTimeQueue <int> .Head(heap); Assert.AreEqual(count, next); heap = RealTimeQueue <int> .Tail(heap); count++; } Assert.AreEqual(Size, count); }
public void EmptyTest() { var queue = RealTimeQueue <string> .Empty; Assert.IsTrue(RealTimeQueue <string> .IsEmpty(queue)); queue = RealTimeQueue <string> .Snoc(queue, "Item"); Assert.IsFalse(RealTimeQueue <string> .IsEmpty(queue)); queue = RealTimeQueue <string> .Tail(queue); Assert.IsTrue(RealTimeQueue <string> .IsEmpty(queue)); }
public void SnocTest() { var queue = RealTimeQueue <string> .Empty; queue = RealTimeQueue <string> .Snoc(queue, "One"); Assert.AreEqual("[{$}, null, {$}]", DumpQueue(queue, false)); queue = RealTimeQueue <string> .Snoc(queue, "Two"); Assert.AreEqual("[{One}, [Two], {}]", DumpQueue(queue, false)); queue = RealTimeQueue <string> .Snoc(queue, "Three"); Assert.AreEqual("[{$One, $Two, $Three}, null, {One, Two, Three}]", DumpQueue(queue, true)); }
public bool Enqueue(T t) { lock (_lock) { while (!_token.IsCancellationRequested && _count >= _size) { Monitor.Wait(_lock); } if (_token.IsCancellationRequested) { return(false); } _count++; _queue = RealTimeQueue <T> .Snoc(_queue, t); Monitor.PulseAll(_lock); } return(true); }
public void EmptySnocTest() { AssertThrows <NullReferenceException>(() => RealTimeQueue <string> .Snoc(null, "Item")); }