예제 #1
0
        public void NonIComparable()
        {
            var splayTree = new SplayTree <NonComparableTClass, string>
            {
                { new NonComparableTClass(4), "4" },
                { new NonComparableTClass(6), "6" },
                { new NonComparableTClass(2), "2" },
                { new NonComparableTClass(5), "5" },
                { new NonComparableTClass(19), "19" },
                { new NonComparableTClass(1), "1" }
            };


            var newTree = SerializeUtil.BinarySerializeDeserialize(splayTree);

            Assert.AreNotSame(splayTree, newTree);
            Assert.AreEqual(splayTree.Count, newTree.Count);

            var splayTreeEnumerator = splayTree.GetEnumerator();
            var newTreeEnumerator   = newTree.GetEnumerator();

            while (splayTreeEnumerator.MoveNext())
            {
                Assert.IsTrue(newTreeEnumerator.MoveNext());
                Assert.AreEqual(splayTreeEnumerator.Current.Key.Number, newTreeEnumerator.Current.Key.Number);
                Assert.AreEqual(splayTreeEnumerator.Current.Value, newTreeEnumerator.Current.Value);

                //TODO: Need a way of accessing an item without splaying
                //Assert.AreEqual(newTree.ContainsKey(splayTreeEnumerator.Current.Key));
                //Assert.AreEqual(newTree[treeEnumerator.Current.Key], splayTreeEnumerator.Current.Value);
            }

            Assert.IsFalse(newTreeEnumerator.MoveNext());
        }
예제 #2
0
        public void NonIComparable()
        {
            var splayTree = new SplayTree<NonComparableTClass, string>
                                {
                                    {new NonComparableTClass(4), "4"},
                                    {new NonComparableTClass(6), "6"},
                                    {new NonComparableTClass(2), "2"},
                                    {new NonComparableTClass(5), "5"},
                                    {new NonComparableTClass(19), "19"},
                                    {new NonComparableTClass(1), "1"}
                                };

            var newTree = SerializeUtil.BinarySerializeDeserialize(splayTree);

            Assert.AreNotSame(splayTree, newTree);
            Assert.AreEqual(splayTree.Count, newTree.Count);

            var splayTreeEnumerator = splayTree.GetEnumerator();
            var newTreeEnumerator = newTree.GetEnumerator();

            while (splayTreeEnumerator.MoveNext())
            {
                Assert.IsTrue(newTreeEnumerator.MoveNext());
                Assert.AreEqual(splayTreeEnumerator.Current.Key.Number, newTreeEnumerator.Current.Key.Number);
                Assert.AreEqual(splayTreeEnumerator.Current.Value, newTreeEnumerator.Current.Value);

                //TODO: Need a way of accessing an item without splaying
                //Assert.AreEqual(newTree.ContainsKey(splayTreeEnumerator.Current.Key));
                //Assert.AreEqual(newTree[treeEnumerator.Current.Key], splayTreeEnumerator.Current.Value);
            }

            Assert.IsFalse(newTreeEnumerator.MoveNext());
        }
예제 #3
0
파일: Set.cs 프로젝트: LowerCode/Malins
 public IEnumerator <T> GetEnumerator()
 {
     return(data.GetEnumerator());
 }