Beispiel #1
0
        public void RemoveMethod_RemoveTargetItem_OneInstanceMissingFromList()
        {
            //Arrange
            LiteList <int> list = new LiteList <int>();

            list.Add(1);
            list.Add(1);
            list.Add(1);
            list.Add(1);
            int expected = 3;  // Expect list to contain three instances of int one.
            int actual   = default;

            //Act
            list.Remove(1);
            for (int i = 0; i <= list.Count; i++)
            {
                if (list[i] == 1)
                {
                    actual++;
                }
            }

            //Assert
            Assert.AreEqual(expected, actual);
        }
Beispiel #2
0
        public void RemoveMethod_RemoveTargetItem_ItemsCondenseReplaceIndexes()
        {
            //Arrange
            LiteList <int> list = new LiteList <int>();

            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);
            int target    = 2;  // Target object to remove.
            int expected1 = 1;
            int expected2 = 3;
            int expected3 = 4;
            int expected4 = 0;
            int actual1;
            int actual2;
            int actual3;
            int actual4;

            //Act
            list.Remove(target);
            actual1 = list[0];
            actual2 = list[1];
            actual3 = list[2];
            actual4 = list[3];

            //Assert
            Assert.AreEqual(expected1, actual1);
            Assert.AreEqual(expected2, actual2);
            Assert.AreEqual(expected3, actual3);
            Assert.AreEqual(expected4, actual4);
        }
Beispiel #3
0
        public void RemoveMethod_RemoveTargetItem_ItemMissingFromList()
        {
            //Arrange
            LiteList <int> list = new LiteList <int>();

            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);
            bool expected = false;  // Expect list to not-contain int 1.
            bool actual   = default;
            int  target   = 2;

            //Act
            list.Remove(target);
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i] == target)
                {
                    actual = true;
                    break;
                }
            }
            //Assert
            Assert.AreEqual(expected, actual);
        }
        public void SubtractOperator_SubtractTwoLists_NewListMatchesExpected()
        {
            //Arrange
            LiteList <int> listOne = new LiteList <int>();

            listOne.Add(6);
            listOne.Add(3);
            listOne.Add(2);

            LiteList <int> listTwo = new LiteList <int>();

            listTwo.Add(2);
            listTwo.Add(1);
            listTwo.Add(1);

            int expectedIndexZero = 4;
            int expectedIndexOne  = 2;
            int expectedIndexTwo  = 1;
            int actualIndexZero;
            int actualIndexOne;
            int actualIndexTwo;

            //Act
            LiteList <int> newList = listOne - listTwo;

            actualIndexZero = newList[0];
            actualIndexOne  = newList[1];
            actualIndexTwo  = newList[2];

            //Assert
            Assert.AreEqual(expectedIndexZero, actualIndexZero);
            Assert.AreEqual(expectedIndexOne, actualIndexOne);
            Assert.AreEqual(expectedIndexTwo, actualIndexTwo);
        }
Beispiel #5
0
        public void ZipMethod_ZipTwoLists_CountsUpdatedExpectedly()
        {
            //Arrange
            LiteList <int> oddList          = new LiteList <int>();
            int            oddListIndexZero = 1;
            int            oddListIndexOne  = 3;
            int            oddListIndexTwo  = 5;

            oddList.Add(oddListIndexZero); oddList.Add(oddListIndexOne); oddList.Add(oddListIndexTwo);

            LiteList <int> evenList          = new LiteList <int>();
            int            evenListIndexZero = 2;
            int            evenListIndexOne  = 4;
            int            evenListIndexTwo  = 6;

            evenList.Add(evenListIndexZero); evenList.Add(evenListIndexOne); evenList.Add(evenListIndexTwo);

            int expectedCount = 6;
            int actualCount;


            //Act
            LiteList <int> zipper = oddList.Zip(evenList);

            actualCount = zipper.Count;


            //Assert
            Assert.AreEqual(expectedCount, actualCount);
        }
Beispiel #6
0
        public void AddOperator_AddTwoLists_NewListMatchesAddedValues()
        {
            //Arrange
            LiteList <int> listOne = new LiteList <int>();

            listOne.Add(1);
            listOne.Add(3);
            listOne.Add(5);

            LiteList <int> listTwo = new LiteList <int>();

            listTwo.Add(2);
            listTwo.Add(4);
            listTwo.Add(6);

            int expectedIndexZero = 3;
            int expectedIndexOne  = 7;
            int expectedIndexTwo  = 11;
            int actualIndexZero;
            int actualIndexOne;
            int actualIndexTwo;

            //Act
            LiteList <int> newList = listOne + listTwo;

            actualIndexZero = newList[0];
            actualIndexOne  = newList[1];
            actualIndexTwo  = newList[2];

            //Assert
            Assert.AreEqual(expectedIndexZero, actualIndexZero);
            Assert.AreEqual(expectedIndexOne, actualIndexOne);
            Assert.AreEqual(expectedIndexTwo, actualIndexTwo);
        }
        public void SubtractOperator_SubtractTwoLists_ZeroOrNegativeValuesOmitted()
        {
            //Arrange
            LiteList <int> listOne = new LiteList <int>();

            listOne.Add(1);
            listOne.Add(5);
            listOne.Add(7);

            LiteList <int> listTwo = new LiteList <int>();

            listTwo.Add(2);
            listTwo.Add(4);
            listTwo.Add(6);

            int expectedIndexZero = 1;
            int expectedIndexOne  = 1;
            int expectedIndexTwo  = default;
            int actualIndexZero;
            int actualIndexOne;
            int actualIndexTwo;

            //Act
            LiteList <int> newList = listOne - listTwo;

            actualIndexZero = newList[0];
            actualIndexOne  = newList[1];
            actualIndexTwo  = newList[2];

            //Assert
            Assert.AreEqual(expectedIndexZero, actualIndexZero);
            Assert.AreEqual(expectedIndexOne, actualIndexOne);
            Assert.AreEqual(expectedIndexTwo, actualIndexTwo);
        }
Beispiel #8
0
        public void AddOperator_AddTwoLists_NewListCountCorrect()
        {
            //Arrange
            LiteList <int> listOne = new LiteList <int>();

            listOne.Add(1);
            listOne.Add(3);
            listOne.Add(5);

            LiteList <int> listTwo = new LiteList <int>();

            listTwo.Add(2);
            listTwo.Add(4);
            listTwo.Add(6);

            int expectedCount = 3;
            int actualCount;

            //Act
            LiteList <int> newList = listOne + listTwo;

            actualCount = newList.Count;

            //Assert
            Assert.AreEqual(expectedCount, actualCount);
        }
Beispiel #9
0
        public void AddMethod_AddFiveItems_ItemsAtIndexMatchOrderAdded()
        {
            //Arrange
            LiteList <int> list      = new LiteList <int>();
            int            expected1 = 1;
            int            expected2 = 2;
            int            expected3 = 3;
            int            expected4 = 4;
            int            expected5 = 5;
            int            actual1;
            int            actual2;
            int            actual3;
            int            actual4;
            int            actual5;

            //Act
            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);
            list.Add(5);

            actual1 = list[0];
            actual2 = list[1];
            actual3 = list[2];
            actual4 = list[3];
            actual5 = list[4];

            //Assert
            Assert.AreEqual(expected1, actual1);
            Assert.AreEqual(expected2, actual2);
            Assert.AreEqual(expected3, actual3);
            Assert.AreEqual(expected4, actual4);
            Assert.AreEqual(expected5, actual5);
        }
Beispiel #10
0
        public void InsertToList_AddsARecord_WithGivenValues()
        {
            UseConnection(database =>
            {
                Commit(database, x => x.InsertToList("my-key", "my-value"));

                LiteList record = database.StateDataList.FindAll().ToList().Single();

                Assert.Equal("my-key", record.Key);
                Assert.Equal("my-value", record.Value);
            });
        }
Beispiel #11
0
        public void AddMethod_AddOneInt_CountIsOne()
        {
            //Arrange
            LiteList <int> list     = new LiteList <int>();
            int            expected = 1;
            int            actual;

            //Act
            list.Add(5);
            actual = list.Count;

            //Assert
            Assert.AreEqual(expected, actual);
        }
Beispiel #12
0
        public void AddMethod_AddOneIntToEmpty_AddedItemInZeroIndex()
        {
            //Arrange
            LiteList <int> list     = new LiteList <int>();
            int            expected = 5;
            int            actual;

            //Act
            list.Add(5);
            actual = list[0];

            //Assert
            Assert.AreEqual(expected, actual);
        }
Beispiel #13
0
        public void ZipMethod_ZipTwoLists_IndexesMatchExpected()
        {
            //Arrange
            LiteList <int> oddList          = new LiteList <int>();
            int            oddListIndexZero = 1;
            int            oddListIndexOne  = 3;
            int            oddListIndexTwo  = 5;

            oddList.Add(oddListIndexZero); oddList.Add(oddListIndexOne); oddList.Add(oddListIndexTwo);

            LiteList <int> evenList          = new LiteList <int>();
            int            evenListIndexZero = 2;
            int            evenListIndexOne  = 4;
            int            evenListIndexTwo  = 6;

            evenList.Add(evenListIndexZero); evenList.Add(evenListIndexOne); evenList.Add(evenListIndexTwo);

            int expectedIndexZero  = oddListIndexZero;
            int expectedIndexOne   = evenListIndexZero;
            int expectedIndexTwo   = oddListIndexOne;
            int expectedIndexThree = evenListIndexOne;
            int expectedIndexFour  = oddListIndexTwo;
            int expectedIndexFive  = evenListIndexTwo;
            int actualIndexZero;
            int actualIndexOne;
            int actualIndexTwo;
            int actualIndexThree;
            int actualIndexFour;
            int actualIndexFive;

            //Act
            LiteList <int> zipper = oddList.Zip(evenList);

            actualIndexZero  = zipper[0];
            actualIndexOne   = zipper[1];
            actualIndexTwo   = zipper[2];
            actualIndexThree = zipper[3];
            actualIndexFour  = zipper[4];
            actualIndexFive  = zipper[5];

            //Assert
            Assert.AreEqual(expectedIndexZero, actualIndexZero);
            Assert.AreEqual(expectedIndexOne, actualIndexOne);
            Assert.AreEqual(expectedIndexTwo, actualIndexTwo);
            Assert.AreEqual(expectedIndexThree, actualIndexThree);
            Assert.AreEqual(expectedIndexFour, actualIndexFour);
            Assert.AreEqual(expectedIndexFive, actualIndexFive);
        }
Beispiel #14
0
        public void AddMethod_Add8Items_CapacityDoubles()
        {
            //Arrange
            LiteList <int> list     = new LiteList <int>();
            int            expected = 16;
            int            actual;

            //Act
            for (int i = 0; i < 8; i++)
            {
                list.Add(i);
            }
            actual = list.Capacity;

            //Assert
            Assert.AreEqual(expected, actual);
        }
Beispiel #15
0
        public void AddMethod_Add8Items_CountRefelctsAdded()
        {
            //Arrange
            LiteList <int> list     = new LiteList <int>();
            int            expected = 8;
            int            actual;

            //Act
            for (int i = 0; i < 8; i++)
            {
                list.Add(i);
            }
            actual = list.Count;

            //Assert
            Assert.AreEqual(expected, actual);
        }
Beispiel #16
0
        public void RemoveLastMethod_RemoveItem_CountDecrements()
        {
            //Arrange
            LiteList <int> list     = new LiteList <int>();
            int            expected = 3;
            int            actual;

            //Act
            list.Add(5);
            list.Add(5);
            list.Add(5);
            list.Add(5); // Count = 4
            list.RemoveLast();
            actual = list.Count;

            //Assert
            Assert.AreEqual(expected, actual);
        }
Beispiel #17
0
        public void RemoveLastMethod_RemoveItem_LastItemChanges()
        {
            //Arrange
            LiteList <int> list     = new LiteList <int>();
            int            expected = 3;
            int            actual;

            //Act
            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4); // Last Item (Count - 1)
            list.RemoveLast();
            actual = list[list.Count - 1];

            //Assert
            Assert.AreEqual(expected, actual);
        }
        public void ToString_ConvertListOfDoublesToString_ItemsAreOfTypeString()
        {
            //Arrange
            LiteList <double> list = new LiteList <double>();

            list.Add(1);
            list.Add(3);
            list.Add(5);
            list.Add(6);
            bool expected = true;
            bool actual;

            //Act
            var x = list.ToString();

            actual = x is string;

            //Assert
            Assert.AreEqual(expected, actual);
        }
Beispiel #19
0
        public void PersistList_ClearsTheListExpirationData()
        {
            UseConnection(database =>
            {
                var list1 = new LiteList {
                    Key = "List1", Value = "value1", ExpireAt = DateTime.Now
                };
                database.StateDataList.Insert(list1);

                var list2 = new LiteList {
                    Key = "List2", Value = "value2", ExpireAt = DateTime.Now
                };
                database.StateDataList.Insert(list2);

                Commit(database, x => x.PersistList(list1.Key));

                var testList1 = GetTestList(database, list1.Key);
                Assert.Null(testList1.ExpireAt);

                var testList2 = GetTestList(database, list2.Key);
                Assert.NotNull(testList2.ExpireAt);
            });
        }
Beispiel #20
0
        public void ExpireList_SetsListExpirationData()
        {
            UseConnection(database =>
            {
                var list1 = new LiteList {
                    Key = "List1", Value = "value1"
                };
                database.StateDataList.Insert(list1);

                var list2 = new LiteList {
                    Key = "List2", Value = "value2"
                };
                database.StateDataList.Insert(list2);

                Commit(database, x => x.ExpireList(list1.Key, TimeSpan.FromDays(1)));

                var testList1 = GetTestList(database, list1.Key);
                Assert.True(DateTime.Now.AddMinutes(-1) < testList1.ExpireAt && testList1.ExpireAt <= DateTime.UtcNow.AddDays(1));

                var testList2 = GetTestList(database, list2.Key);
                Assert.Null(testList2.ExpireAt);
            });
        }
Beispiel #21
0
        public void SortMethod_SortOneToFiveListDbls_ItemsInCorrectOrder()
        {
            //Arrange
            LiteList <double> list = new LiteList <double>();

            list.Add(1);
            list.Add(5);
            list.Add(2);
            list.Add(3);
            list.Add(4);
            double expected1 = 1;
            double expected2 = 2;
            double expected3 = 3;
            double expected4 = 4;
            double expected5 = 5;
            double actual1;
            double actual2;
            double actual3;
            double actual4;
            double actual5;

            //Act
            list.Sort();
            actual1 = list[0];
            actual2 = list[1];
            actual3 = list[2];
            actual4 = list[3];
            actual5 = list[4];

            //Assert
            Assert.AreEqual(expected1, actual1);
            Assert.AreEqual(expected2, actual2);
            Assert.AreEqual(expected3, actual3);
            Assert.AreEqual(expected4, actual4);
            Assert.AreEqual(expected5, actual5);
        }