Exemple #1
0
 public void IndexOfReturnsMinusOneIfItemNotInHive(ListTestArgs <T, TSize, THive> args)
 {
     if (!args.ExpectedItems.Contains(default(T)))
     {
         Assert.AreEqual(-1, args.Hive.IndexOf(default(T)));
     }
 }
Exemple #2
0
        public void InsertRangeInMiddle(ListTestArgs <T, TSize, THive> args)
        {
            IgnoreTestIfHiveIsReadOnly(args.Hive);
            if (Size.Compare(args.Hive.Count, Size.From(2)) < 0)
            {
                return;
            }

            List <T> range       = new List <T>(CreateRange(3));
            TSize    insertIndex = Size.Add(GetRandomIndex(Size.Subtract(args.Hive.Count, 2)), 1);

            args.Hive.InsertRange(insertIndex, range);

            TSize itemIndex = Size.Zero;

            foreach (T expectedItem in args.ExpectedItems)
            {
                Assert.AreEqual(expectedItem, args.Hive[itemIndex], "item[{0}]", itemIndex);
                Size.Increment(ref itemIndex);

                if (Size.Equals(itemIndex, insertIndex))
                {
                    foreach (T rangeItem in range)
                    {
                        Assert.AreEqual(rangeItem, args.Hive[itemIndex], "item[{0}]", itemIndex);
                        Size.Increment(ref itemIndex);
                    }
                }
            }
        }
Exemple #3
0
        public void InsertInMiddle(ListTestArgs <T, TSize, THive> args)
        {
            IgnoreTestIfHiveIsReadOnly(args.Hive);

            long itemCount = Size.ToInt64(args.Hive.Count);

            if (itemCount < 2)
            {
                return;
            }

            TSize insertIndex  = Size.Add(GetRandomIndex(Size.Subtract(args.Hive.Count, 2)), 1);
            T     insertedItem = CreateRandomItem();

            args.Hive.Insert(insertIndex, insertedItem);

            TSize itemIndex = Size.Zero;

            foreach (T expectedItem in args.ExpectedItems)
            {
                Assert.AreEqual(expectedItem, args.Hive[itemIndex], "item[{0}]", itemIndex);
                Size.Increment(ref itemIndex);

                if (Size.Equals(itemIndex, insertIndex))
                {
                    Assert.AreEqual(insertedItem, args.Hive[itemIndex], "item[{0}]", itemIndex);
                    Size.Increment(ref itemIndex);
                }
            }
        }
Exemple #4
0
        public void InsertRangeDoesNotIncrementRevisionWhenRangeIsEmpty(ListTestArgs <T, TSize, THive> args)
        {
            IgnoreTestIfHiveIsReadOnly(args.Hive);

            long initialRevision = args.Hive.Revision;

            args.Hive.InsertRange(Size.Zero, CreateRange(0));
            Assert.AreEqual(args.Hive.Revision, initialRevision);
        }
Exemple #5
0
        public void IndexOfReturnsIndexOfItemIfItemInHive(ListTestArgs <T, TSize, THive> args)
        {
            TSize itemIndex = Size.Zero;

            foreach (T expectedItem in args.ExpectedItems)
            {
                Assert.AreEqual(itemIndex, args.Hive.IndexOf(expectedItem), "Item #{0}", itemIndex);
                Size.Increment(ref itemIndex);
            }
        }
Exemple #6
0
        public void RemoveFromEnd(ListTestArgs <T, TSize, THive> args)
        {
            IgnoreTestIfHiveIsReadOnly(args.Hive);

            for (int itemIndex = args.ExpectedItems.Count - 1; itemIndex >= 0; itemIndex--)
            {
                T expectedItem = args.ExpectedItems[itemIndex];
                args.Hive.Remove(expectedItem);
                Assert.AreEqual(Size.From(-1), args.Hive.IndexOf(expectedItem), "item[{0}]", itemIndex);
            }
        }
Exemple #7
0
        public void InsertRangeIncrementsRevisionWhenRangeIsNotEmpty(ListTestArgs <T, TSize, THive> args)
        {
            const int RANGE_SIZE = 3;

            IgnoreTestIfHiveIsReadOnly(args.Hive);

            long initialRevision = args.Hive.Revision;

            args.Hive.InsertRange(Size.Zero, CreateRange(RANGE_SIZE));
            Assert.Greater(args.Hive.Revision, initialRevision);
        }
Exemple #8
0
        public void InsertRangeIncrementsCount(ListTestArgs <T, TSize, THive> args)
        {
            const int RANGE_SIZE = 3;

            IgnoreTestIfHiveIsReadOnly(args.Hive);

            TSize initialCount = args.Hive.Count;

            args.Hive.InsertRange(Size.Zero, CreateRange(RANGE_SIZE));
            Assert.AreEqual(Size.Add(initialCount, RANGE_SIZE), args.Hive.Count);
        }
Exemple #9
0
        public void InsertIncrementsRevision(ListTestArgs <T, TSize, THive> args)
        {
            IgnoreTestIfHiveIsReadOnly(args.Hive);

            for (int i = 0; i < 3; i++)
            {
                long revision = args.Hive.Revision;
                args.Hive.Insert(GetRandomIndex(args.Hive.Count), CreateRandomItem());
                Assert.GreaterThan(args.Hive.Revision, revision, "Insert #{0}", i);
            }
        }
Exemple #10
0
        public void InsertIncrementsCount(ListTestArgs <T, TSize, THive> args)
        {
            IgnoreTestIfHiveIsReadOnly(args.Hive);

            for (int i = 0; i < 3; i++)
            {
                TSize initialCount = args.Hive.Count;
                args.Hive.Insert(GetRandomIndex(args.Hive.Count), CreateRandomItem());
                Assert.AreEqual(Size.Add(initialCount, 1), args.Hive.Count, "Insert #{0}", i);
            }
        }
Exemple #11
0
 public void InsertRangeIncreasesCapacityIfNoSpareCapacityExists
     (ListTestArgs <T, TSize, THive> args)
 {
     for (int capacityIncreaseCount = 0; capacityIncreaseCount < 3; capacityIncreaseCount++)
     {
         TSize initialCapacity = args.Hive.Capacity;
         args.Hive.InsertRange(Size.Zero, CreateRange(Size.ToInt64(initialCapacity) + 1));
         Assert.GreaterEqualThan(
             Size.ToInt64(args.Hive.Capacity),
             Size.ToInt64(initialCapacity),
             "Capacity increase #{0}", capacityIncreaseCount);
     }
 }
Exemple #12
0
        public void RemoveFromBegin(ListTestArgs <T, TSize, THive> args)
        {
            IgnoreTestIfHiveIsReadOnly(args.Hive);

            TSize itemIndex = Size.Zero;

            foreach (T expectedItem in args.ExpectedItems)
            {
                args.Hive.Remove(expectedItem);
                Assert.AreEqual(Size.From(-1), args.Hive.IndexOf(expectedItem), "item[{0}]", itemIndex);
                Size.Increment(ref itemIndex);
            }
        }
Exemple #13
0
        public void AddAtEnd(ListTestArgs <T, TSize, THive> args)
        {
            IgnoreTestIfHiveIsReadOnly(args.Hive);

            T lastItem = CreateRandomItem();

            args.Hive.Add(lastItem);

            TSize itemIndex = Size.Zero;

            foreach (T expectedItem in args.ExpectedItems)
            {
                Assert.AreEqual(expectedItem, args.Hive[(TSize)(object)itemIndex], "item[{0}]", itemIndex);
                Size.Increment(ref itemIndex);
            }
            Assert.AreEqual(lastItem, args.Hive[itemIndex], "item[{0}]", itemIndex);
        }
Exemple #14
0
 public void InsertIncreasesCapacityIfNoSpareCapacityExists
     (ListTestArgs <T, TSize, THive> args)
 {
     for (int capacityIncreaseCount = 0; capacityIncreaseCount < 3; capacityIncreaseCount++)
     {
         TSize initialCapacity = args.Hive.Capacity;
         for (TSize itemIndex = Size.Zero
              ; Size.Compare(itemIndex, initialCapacity) <= 0
              ; Size.Increment(ref itemIndex)
              )
         {
             args.Hive.Insert(GetRandomIndex(args.Hive.Count), CreateRandomItem());
         }
         Assert.GreaterEqualThan(
             Size.ToInt64(args.Hive.Capacity), Size.ToInt64(initialCapacity),
             "Capacity increase #{0}", capacityIncreaseCount);
     }
 }
Exemple #15
0
        public void InsertAtBegin(ListTestArgs <T, TSize, THive> args)
        {
            IgnoreTestIfHiveIsReadOnly(args.Hive);

            T firstItem = CreateRandomItem();

            args.Hive.Insert((TSize)(object)0, firstItem);

            TSize itemIndex = Size.Zero;

            Assert.AreEqual(firstItem, args.Hive[itemIndex], "item[{0}]", itemIndex);

            Size.Increment(ref itemIndex);
            foreach (T expectedItem in args.ExpectedItems)
            {
                Assert.AreEqual(expectedItem, args.Hive[itemIndex], "item[{0}]", itemIndex);
                Size.Increment(ref itemIndex);
            }
        }
Exemple #16
0
        public void AddRangeAtEnd(ListTestArgs <T, TSize, THive> args)
        {
            IgnoreTestIfHiveIsReadOnly(args.Hive);

            List <T> range = new List <T>(CreateRange(3));

            args.Hive.AddRange(range);

            TSize itemIndex = Size.Zero;

            foreach (T expectedItem in args.ExpectedItems)
            {
                Assert.AreEqual(expectedItem, args.Hive[itemIndex], "item[{0}]", itemIndex);
                Size.Increment(ref itemIndex);
            }
            foreach (T rangeItem in range)
            {
                Assert.AreEqual(rangeItem, args.Hive[itemIndex], "item[{0}]", itemIndex);
                Size.Increment(ref itemIndex);
            }
        }
Exemple #17
0
 public void InsertRangeThrowsArgumentOutOfRangeExceptionIfIndexIsLessThanZero(ListTestArgs <T, TSize, THive> args)
 {
     IgnoreTestIfHiveIsReadOnly(args.Hive);
     args.Hive.InsertRange(Size.From(-1), CreateRange(1));
 }
Exemple #18
0
 public void InsertRangeThrowsArgumentOutOfRangeExceptionIfIndexIsGreaterThanCount(ListTestArgs <T, TSize, THive> args)
 {
     IgnoreTestIfHiveIsReadOnly(args.Hive);
     args.Hive.InsertRange(Size.Add(args.Hive.Count, 1), CreateRange(1));
 }