コード例 #1
0
        public void CBTree_Enumerate()
        {
            var btree = new BTreeDictionary <string, int>();

            btree.Add("3", 3);
            btree.Add("2", 2);
            var e = btree.GetEnumerator();

            Assert.IsTrue(e.MoveNext());
            Assert.AreEqual("2", e.Current.Key);
            Assert.AreEqual(2, e.Current.Value);
            Assert.IsTrue(e.MoveNext());
            Assert.AreEqual("3", e.Current.Key);
            Assert.AreEqual(3, e.Current.Value);
            Assert.IsFalse(e.MoveNext());
        }
コード例 #2
0
        public void TestClone()
        {
            BTreeDictionary <int, string> data = new BTreeDictionary <int, string>(Comparer, GetSample());
            BTreeDictionary <int, string> copy = (BTreeDictionary <int, string>)((ICloneable)data).Clone();

            using (IEnumerator <KeyValuePair <int, string> > e1 = data.GetEnumerator())
                using (IEnumerator <KeyValuePair <int, string> > e2 = copy.GetEnumerator())
                {
                    while (e1.MoveNext() && e2.MoveNext())
                    {
                        Assert.AreEqual(e1.Current.Key, e2.Current.Key);
                        Assert.AreEqual(e1.Current.Value, e2.Current.Value);
                    }
                    Assert.IsFalse(e1.MoveNext() || e2.MoveNext());
                }
        }
コード例 #3
0
        public void CBTree_EnumeratorThrowIfMutated()
        {
            var btree = new BTreeDictionary <string, int>();

            btree.Add("3", 3);
            var e = btree.GetEnumerator();

            Assert.True(e.MoveNext());
            btree.Add("2", 2);
            try
            {
                e.MoveNext();
                Assert.Fail("Should have thrown exception");
            }
            catch (InvalidOperationException)
            {
            }
        }