Example #1
0
        public void Remove_OneOccurrence()
        {
            // Arrange
            ReverseCollection <int> reversedCollection = new ReverseCollection <int>(initialArray);

            int  itemToRemove         = 2;
            bool expectedRemoveResult = true;

            bool expectedContainItemBeforeRemoving = true;
            bool exoectedContainItemAfterRemoving  = false;

            int[] expectedCollection = new int[4] {
                5, 4, 3, 1
            };

            // Act
            bool actualContainItemBeforeRemoving = reversedCollection.Contains(itemToRemove);
            bool actualRemoveResult             = reversedCollection.Remove(itemToRemove);
            bool actualContainItemAfterRemoving = reversedCollection.Contains(itemToRemove);

            int[] actualCollection = reversedCollection.ToArray();

            // Assert
            Assert.AreEqual(expectedRemoveResult, actualRemoveResult);
            Assert.AreEqual(expectedContainItemBeforeRemoving, actualContainItemBeforeRemoving);
            Assert.AreEqual(exoectedContainItemAfterRemoving, actualContainItemAfterRemoving);
            CollectionAssert.AreEqual(expectedCollection, actualCollection);
            CollectionAssert.DoesNotContain(actualCollection, itemToRemove);
        }
Example #2
0
        public void Remove_ManyOccurrence()
        {
            // Arrange
            int[] startCollection = new int[] { 1, 2, 3, 3, 2, 1 };
            ReverseCollection <int> reversedCollection = new ReverseCollection <int>(startCollection);

            int  itemToRemove         = 2;
            bool expectedRemoveResult = true;

            bool expectedContainItemBeforeRemoving = true;
            bool exoectedContainItemAfterRemoving  = true;

            int[] expectedCollection = new int[] { 1, 3, 3, 2, 1 };

            // Act
            bool actualContainItemBeforeRemoving = reversedCollection.Contains(itemToRemove);
            bool actualRemoveResult             = reversedCollection.Remove(itemToRemove);
            bool actualContainItemAfterRemoving = reversedCollection.Contains(itemToRemove);

            // Assert
            Assert.AreEqual(expectedRemoveResult, actualRemoveResult);
            Assert.AreEqual(expectedContainItemBeforeRemoving, actualContainItemBeforeRemoving);
            Assert.AreEqual(exoectedContainItemAfterRemoving, actualContainItemAfterRemoving);
            CollectionAssert.Contains(reversedCollection.ToArray(), itemToRemove);
        }
Example #3
0
        public void RemoveAt()
        {
            // Arrange
            ReverseCollection <int> reversedCollection = new ReverseCollection <int>(initialArray);

            int indexToRemove = 2;
            int itemToRemove  = 3;

            int[] expectedCollection = new int[4] {
                5, 4, 2, 1
            };

            bool expectedHasItemBeforeRemoving = true;
            bool actualHasItemBeforeRemoving   = reversedArray.Contains(itemToRemove);

            bool expectedHasItemAfterRemoving = false;

            // Act
            reversedCollection.RemoveAt(indexToRemove);

            bool actualHasItemAfterRemoving = reversedCollection.Contains(itemToRemove);

            int[] actualCollectionAfterRemoving = reversedCollection.ToArray();

            // Assert
            CollectionAssert.DoesNotContain(actualCollectionAfterRemoving, itemToRemove);
            Assert.AreEqual(expectedHasItemBeforeRemoving, actualHasItemBeforeRemoving);
            Assert.AreEqual(expectedHasItemAfterRemoving, actualHasItemAfterRemoving);
            CollectionAssert.AreEqual(expectedCollection, actualCollectionAfterRemoving);
        }
Example #4
0
        public void Remove_WrongItem_False()
        {
            // Arrange
            ReverseCollection <int> reversedCollection = new ReverseCollection <int>(initialArray);

            int  itemToRemove         = int.MaxValue;
            bool expectedRemoveResult = false;

            bool expectedContainItemBeforeRemoving = false;
            bool exoectedContainItemAfterRemoving  = false;

            // Act
            bool actualContainItemBeforeRemoving = reversedCollection.Contains(itemToRemove);
            bool actualRemoveResult             = reversedCollection.Remove(itemToRemove);
            bool actualContainItemAfterRemoving = reversedCollection.Contains(itemToRemove);

            // Assert
            Assert.AreEqual(expectedRemoveResult, actualRemoveResult);
            Assert.AreEqual(expectedContainItemBeforeRemoving, actualContainItemBeforeRemoving);
            Assert.AreEqual(exoectedContainItemAfterRemoving, actualContainItemAfterRemoving);
            CollectionAssert.DoesNotContain(reversedCollection.ToArray(), itemToRemove);
        }
Example #5
0
        public void Contains()
        {
            // Arrange
            ReverseCollection <int> reversedCollection = new ReverseCollection <int>();

            int  elementToSearch = 2;
            bool expectedContainsElementBeforeAdding = false;
            bool expectedContainsElementAfterAdding  = true;

            // Act
            bool actualContainsElementBeforeAdding = reversedCollection.Contains(elementToSearch);

            foreach (int item in initialArray)
            {
                reversedCollection.Add(item);
            }
            bool actualContainsElementAfterAdding = reversedCollection.Contains(elementToSearch);

            // Assert
            Assert.AreEqual(expectedContainsElementBeforeAdding, actualContainsElementBeforeAdding);
            Assert.AreEqual(expectedContainsElementAfterAdding, actualContainsElementAfterAdding);
            CollectionAssert.Contains(reversedCollection.ToArray(), elementToSearch);
        }