public void Test() { Init(1); PushBackThreadFunc(0); PopFrontThreadFunc(0); Assert.AreEqual(value, Result, "value should be equal to result."); Init(1); PushBackThreadFunc(0); PopBackThreadFunc(0); Assert.AreEqual(value, Result, "value should be equal to result."); Init(1); PushBackThreadFunc(0); var result = yqueue.PopAll(); Assert.IsNotNull(result, "result should not be null."); foreach (var i in result) { value += i; } Assert.AreEqual(value, Result, "value should be equal to result."); }
public void TestApi() { yqueue = new CacheQueue <int>(); Assert.AreEqual(yqueue.FrontPos, 0); Assert.AreEqual(yqueue.BackPos, 0); Assert.AreEqual(yqueue.EndPos, 0); int valueResult; valueResult = yqueue.Front; Assert.AreEqual(valueResult, default(int)); valueResult = yqueue.Back; Assert.AreEqual(valueResult, default(int)); var rc = yqueue.PopFront(out valueResult); Assert.IsFalse(rc); rc = yqueue.PopBack(out valueResult); Assert.IsFalse(rc); int value = 1; yqueue.PushBack(ref value); Assert.AreEqual(yqueue.Count, 1); Assert.AreEqual(yqueue.FrontPos, 0); Assert.AreEqual(yqueue.BackPos, 0); Assert.AreEqual(yqueue.EndPos, 1); valueResult = yqueue.Front; Assert.AreEqual(valueResult, value); valueResult = yqueue.Back; Assert.AreEqual(valueResult, value); rc = yqueue.PopFront(out valueResult); Assert.IsTrue(rc); Assert.AreEqual(valueResult, value); Assert.AreEqual(yqueue.Count, 0); Assert.AreEqual(yqueue.FrontPos, 1); Assert.AreEqual(yqueue.BackPos, 0); Assert.AreEqual(yqueue.EndPos, 1); rc = yqueue.PopBack(out valueResult); Assert.IsFalse(rc); Assert.AreEqual(yqueue.Count, 0); Assert.AreEqual(yqueue.FrontPos, 1); Assert.AreEqual(yqueue.BackPos, 0); Assert.AreEqual(yqueue.EndPos, 1); yqueue.PushBack(ref value); Assert.AreEqual(yqueue.Count, 1); Assert.AreEqual(yqueue.FrontPos, 1); Assert.AreEqual(yqueue.BackPos, 1); Assert.AreEqual(yqueue.EndPos, 2); rc = yqueue.PopBack(out valueResult); Assert.IsTrue(rc); Assert.AreEqual(valueResult, value); Assert.AreEqual(yqueue.Count, 0); Assert.AreEqual(yqueue.FrontPos, 1); Assert.AreEqual(yqueue.BackPos, 0); Assert.AreEqual(yqueue.EndPos, 1); rc = yqueue.PopFront(out valueResult); Assert.IsFalse(rc); Assert.AreEqual(yqueue.FrontPos, 1); Assert.AreEqual(yqueue.BackPos, 0); Assert.AreEqual(yqueue.EndPos, 1); yqueue.PushBack(ref value); Assert.AreEqual(yqueue.Count, 1); Assert.AreEqual(yqueue.FrontPos, 1); Assert.AreEqual(yqueue.BackPos, 1); Assert.AreEqual(yqueue.EndPos, 2); yqueue.PushBack(ref value); Assert.AreEqual(yqueue.Count, 2); Assert.AreEqual(yqueue.FrontPos, 1); Assert.AreEqual(yqueue.BackPos, 2); Assert.AreEqual(yqueue.EndPos, 3); var array = yqueue.PopAll(); Assert.AreEqual(array.Length, 2); for (int i = 0; i < array.Length; i++) { Assert.AreEqual(array[i], value); } Assert.AreEqual(yqueue.Count, 0); Assert.AreEqual(yqueue.FrontPos, 3); Assert.AreEqual(yqueue.BackPos, 2); Assert.AreEqual(yqueue.EndPos, 3); yqueue.PushBack(ref value); Assert.AreEqual(yqueue.Count, 1); Assert.AreEqual(yqueue.FrontPos, 3); Assert.AreEqual(yqueue.BackPos, 3); Assert.AreEqual(yqueue.EndPos, 4); yqueue.PushBack(ref value); Assert.AreEqual(yqueue.Count, 2); Assert.AreEqual(yqueue.FrontPos, 3); Assert.AreEqual(yqueue.BackPos, 4); Assert.AreEqual(yqueue.EndPos, 5); yqueue.Clear(); Assert.AreEqual(yqueue.Count, 0); Assert.AreEqual(yqueue.FrontPos, 5); Assert.AreEqual(yqueue.BackPos, 4); Assert.AreEqual(yqueue.EndPos, 5); }