Esempio n. 1
0
 public void IList_Generic_IndexOf_EachValueNoDuplicates(int count)
 {
     // Assumes no duplicate elements contained in the list returned by GenericIListFactory
     SCG.IList <T> list = GenericIListFactory(count);
     Assert.All(Enumerable.Range(0, count), index =>
     {
         Assert.Equal(index, list.IndexOf(list[index]));
     });
 }
Esempio n. 2
0
 public void IList_Generic_IndexOf_InvalidValue(int count)
 {
     if (!IsReadOnly)
     {
         Assert.All(InvalidValues, value =>
         {
             SCG.IList <T> list = GenericIListFactory(count);
             Assert.Throws <ArgumentException>(() => list.IndexOf(value));
         });
     }
 }
Esempio n. 3
0
 public void IList_Generic_IndexOf_ValueInCollectionMultipleTimes(int count)
 {
     if (count > 0 && !IsReadOnly && DuplicateValuesAllowed)
     {
         // IndexOf should always return the lowest index for which a matching element is found
         SCG.IList <T> list  = GenericIListFactory(count);
         T             value = CreateT(12345);
         list[0]         = value;
         list[count / 2] = value;
         Assert.Equal(0, list.IndexOf(value));
     }
 }
Esempio n. 4
0
        public void IList_Generic_IndexOf_ValidValueNotContainedInList(int count)
        {
            SCG.IList <T> list  = GenericIListFactory(count);
            int           seed  = 54321;
            T             value = CreateT(seed++);

            while (list.Contains(value))
            {
                value = CreateT(seed++);
            }
            Assert.Equal(-1, list.IndexOf(value));
        }
Esempio n. 5
0
        public void IList_Generic_IndexOf_ReturnsFirstMatchingValue(int count)
        {
            if (!IsReadOnly && !AddRemoveClear_ThrowsNotSupported)
            {
                SCG.IList <T> list = GenericIListFactory(count);
                foreach (T duplicate in list.ToList()) // hard copies list to circumvent enumeration error
                {
                    list.Add(duplicate);
                }
                List <T> expectedList = list.ToList();

                Assert.All(Enumerable.Range(0, count), (index =>
                                                        Assert.Equal(index, list.IndexOf(expectedList[index]))
                                                        ));
            }
        }
Esempio n. 6
0
 public void IList_Generic_IndexOf_DefaultValueContainedInList(int count)
 {
     if (count > 0 && DefaultValueAllowed)
     {
         SCG.IList <T> list  = GenericIListFactory(count);
         T             value = default(T);
         if (!list.Contains(value))
         {
             if (IsReadOnly)
             {
                 return;
             }
             list[0] = value;
         }
         Assert.Equal(0, list.IndexOf(value));
     }
 }
Esempio n. 7
0
 public void IList_Generic_IndexOf_DefaultValueNotContainedInList(int count)
 {
     if (DefaultValueAllowed)
     {
         SCG.IList <T> list  = GenericIListFactory(count);
         T             value = default(T);
         if (list.Contains(value))
         {
             if (IsReadOnly)
             {
                 return;
             }
             list.Remove(value);
         }
         Assert.Equal(-1, list.IndexOf(value));
     }
     else
     {
         SCG.IList <T> list = GenericIListFactory(count);
         Assert.Throws <ArgumentNullException>(() => list.IndexOf(default(T)));
     }
 }