Beispiel #1
0
        public void TestDequeueByInsertion()
        {
            var test = new LurchTableTest <int, string>(LurchTableOrder.Insertion);

            Assert.AreEqual(LurchTableOrder.Insertion, test.Ordering);
            var sample = GetSample();

            Array.Reverse(sample);
            foreach (var item in sample)
            {
                test.Add(item.Key, item.Value);
            }

            KeyValuePair <int, string> value;

            foreach (var item in sample)
            {
                Assert.IsTrue(test.Peek(out value));
                Assert.AreEqual(item.Key, value.Key);
                Assert.AreEqual(item.Value, value.Value);
                value = test.Dequeue();
                Assert.AreEqual(item.Key, value.Key);
                Assert.AreEqual(item.Value, value.Value);
            }

            Assert.IsFalse(test.Peek(out value));
            Assert.IsFalse(test.TryDequeue(out value));
        }
Beispiel #2
0
        public void TestAddRemoveByKey()
        {
            LurchTableTest <int, string> test = new LurchTableTest <int, string>();

            for (int i = 0; i < 10; i++)
            {
                test.Add(i, i.ToString());
            }

            for (int i = 0; i < 10; i++)
            {
                Assert.IsTrue(test.ContainsKey(i));
            }

            string cmp;

            for (int i = 0; i < 10; i++)
            {
                Assert.IsTrue(test.TryGetValue(i, out cmp) && cmp == i.ToString());
            }

            for (int i = 0; i < 10; i++)
            {
                Assert.IsTrue(test.Remove(i));
            }
        }
Beispiel #3
0
        public void TestDequeueByModified()
        {
            var test = new LurchTableTest <int, string>(LurchTableOrder.Modified);

            Assert.AreEqual(LurchTableOrder.Modified, test.Ordering);
            var sample = GetSample();

            foreach (var item in sample)
            {
                test.Add(item.Key, item.Value);
            }

            Array.Reverse(sample);
            for (int i = 0; i < sample.Length; i++)
            {
                var item = new KeyValuePair <int, string>(sample[i].Key, sample[i].Value + "-2");
                test[item.Key] = item.Value;
                sample[i]      = item;
            }

            KeyValuePair <int, string> value;

            foreach (var item in sample)
            {
                Assert.IsTrue(test.Peek(out value));
                Assert.AreEqual(item.Key, value.Key);
                Assert.AreEqual(item.Value, value.Value);
                value = test.Dequeue();
                Assert.AreEqual(item.Key, value.Key);
                Assert.AreEqual(item.Value, value.Value);
            }

            Assert.IsFalse(test.Peek(out value));
            Assert.IsFalse(test.TryDequeue(out value));
        }
Beispiel #4
0
        public void TestDisposed()
        {
            IConcurrentDictionary <int, string> test = new LurchTableTest <int, string>(new IntComparer());

            test.Dispose();
            test.Add(1, "");
        }
Beispiel #5
0
        public void TestDisposed()
        {
            IDictionary <int, string> test = new LurchTableTest <int, string>();
            var disposable = test as IDisposable;

            if (disposable != null)
            {
                disposable.Dispose();
            }
            Assert.Throws <ObjectDisposedException>(() => { test.Add(1, ""); });
        }
        public void TestDisposed()
        {
            IDictionary <int, string> test = new LurchTableTest <int, string>();
            var disposable = test as IDisposable;

            if (disposable != null)
            {
                disposable.Dispose();
            }
            test.Add(1, "");
        }