Ejemplo n.º 1
0
        public void Remove(RemoveScenario scenario)
        {
            IMyCollection <TestItem> list = (IMyCollection <TestItem>)scenario.List;

            bool wasRemoved = list.Remove(scenario.ToRemove);

            Assert.AreEqual(scenario.ExpectedRemoved, wasRemoved);
            AssertHelper.AreCollectionSame(scenario.ExpectedElements, list);
        }
Ejemplo n.º 2
0
        public void Add(AddScenario scenario)
        {
            IMyCollection <TestItem> list = (IMyCollection <TestItem>)scenario.List;

            foreach (var item in scenario.ItemsToAdd)
            {
                list.Add(item);
            }

            AssertHelper.AreCollectionSame(scenario.ExpectedElements, list);
        }
Ejemplo n.º 3
0
        public void Remove(RemoveScenario scenario)
        {
            var heap = (MyBinaryHeap <TestItem>)scenario.List;

            for (int i = 0; i < scenario.ToRemove.Length; i++)
            {
                heap.Remove(scenario.ToRemove[i]);
                Assert.AreEqual(scenario.PopResult[i], heap.Root);
            }

            AssertHelper.AreCollectionSame(scenario.Expected, heap);
        }
Ejemplo n.º 4
0
        public void Pop(PopScenario scenario)
        {
            var heap = (MyBinaryHeap <TestItem>)scenario.List;

            for (int i = 0; i < scenario.PopResult.Length; i++)
            {
                TestItem item = heap.Pop();
                Assert.AreEqual(scenario.PopResult[i], item);
            }

            AssertHelper.AreCollectionSame(scenario.Expected, heap);
        }
Ejemplo n.º 5
0
        public void Stack(Scenario scenario)
        {
            var stack = (MyStack <TestItem>)scenario.List;

            for (int i = 0; i < scenario.Pushed.Length; i++)
            {
                stack.Push(scenario.Pushed[i]);
            }

            for (int i = 0; i < scenario.ToPop.Length; i++)
            {
                TestItem poped = stack.Pop();
                Assert.AreEqual(scenario.ToPop[i], poped);
            }

            AssertHelper.AreCollectionSame(scenario.Expected, stack);
        }
Ejemplo n.º 6
0
        public void Queue(Scenario scenario)
        {
            var queue = (MyQueue <TestItem>)scenario.List;

            for (int i = 0; i < scenario.ToEnqueue.Length; i++)
            {
                queue.Enqueue(scenario.ToEnqueue[i]);
            }

            for (int i = 0; i < scenario.Dequeued.Length; i++)
            {
                TestItem dequeued = queue.Dequeue();
                Assert.AreEqual(scenario.Dequeued[i], dequeued);
            }

            AssertHelper.AreCollectionSame(scenario.Expected, queue);
        }
Ejemplo n.º 7
0
        public void RemoveAt(RemoveAtScenario scenario)
        {
            IMyList <TestItem> list = (IMyList <TestItem>)scenario.List;

            try
            {
                list.RemoveAt(scenario.ToRemove);
            }
            catch (Exception ex)
            {
                if (scenario.ExpectedExceptionType == null)
                {
                    throw;
                }

                Assert.IsInstanceOfType(scenario.ExpectedExceptionType, ex);
            }

            AssertHelper.AreCollectionSame(scenario.ExpectedElements, list);
        }
Ejemplo n.º 8
0
        public void Insert(InsertScenario scenario)
        {
            IMyList <TestItem> list = (IMyList <TestItem>)scenario.List;

            try
            {
                foreach (var toInsert in scenario.ToInsert)
                {
                    list.Insert(toInsert.Key, toInsert.Value);
                }
            }
            catch (Exception ex)
            {
                if (scenario.ExpectedExceptionType == null)
                {
                    throw;
                }

                Assert.IsInstanceOfType(scenario.ExpectedExceptionType, ex);
            }

            AssertHelper.AreCollectionSame(scenario.ExpectedElements, list);
        }