Пример #1
0
        public void PopAll_Properly_Maintains_Order_And_Sequence()
        {
            var items    = new[] { 2, 4, 0, 1, 2 };
            var expected = new[] { 0, 1, 2, 2, 4 };
            var instance = new TestAbstractBinaryHeap(10, (x, y) => x < y);

            instance.AddAll(items);
            var poppedItems = instance.PopAll().ToList();

            Assert.IsTrue(poppedItems.Count.Equals(5));
            Assert.AreEqual(poppedItems, expected);
            poppedItems = instance.PopAll().ToList();
            Assert.IsTrue(poppedItems.Count.Equals(0));
            instance.AddAll(items);
            poppedItems = instance.PopAll().ToList();
            Assert.IsTrue(poppedItems.Count.Equals(5));
        }
Пример #2
0
        public void InternalStateAsEnumerable_Exposes_Internal_Buffer()
        {
            var instance = new TestAbstractBinaryHeap(10, (x, y) => x < y);

            Assert.True(instance.InternalStateAsEnumerable().ToList().Count.Equals(0));
            var items = new[] { 100, -58, 0, -52, 1, 10 };

            instance.AddAll(items);
            var internalState = new HashSet <int>(instance.InternalStateAsEnumerable());

            foreach (var item in items)
            {
                Assert.IsTrue(internalState.Contains(item));
            }
        }
Пример #3
0
        public void IEnumerable_Works_Fine_With_All()
        {
            var instance = new TestAbstractBinaryHeap(10, (x, y) => x < y);

            Assert.True(instance.ToList().Count.Equals(0));
            var items = new[] { 100, -58, 0, -52, 1, 10 };

            instance.AddAll(items);
            var internalState = new HashSet <int>(instance.All());
            var asEnumerable  = instance as IEnumerable;
            var all           = asEnumerable.Cast <object>().ToList();

            foreach (var item in items)
            {
                Assert.IsTrue(internalState.Contains(item));
                Assert.IsTrue(all.Contains(item));
            }
        }