示例#1
0
        // TODO: Test
        /// <summary>
        ///     Shuffles the items in the list according to the specified random source.
        /// </summary>
        /// <param name="list">The list to shuffle.</param>
        /// <param name="random">The random source.</param>
        public static void Shuffle <T>(this SCG.IList <T> list, Random random)
        {
            #region Code Contracts

            // Argument must be non-null
            Requires(list != null, ArgumentMustBeNonNull);

            // List must be non-read-only
            Requires(!list.IsReadOnly, CollectionMustBeNonReadOnly);

            // The elements are the same
            Ensures(list.HasSameAs(OldValue(list.ToList())));

            #endregion

            if (random == null)
            {
                random = new Random(); // TODO: Use C5.Random?
            }

            var n = list.Count;
            while (--n > 0)
            {
                list.Swap(random.Next(n + 1), n);
            }
        }
示例#2
0
        // TODO: Test?
        /// <summary>
        ///     Swaps the elements at the specified indices in a list.
        /// </summary>
        /// <param name="list">
        ///     The list in which to swap the elements.
        /// </param>
        /// <param name="i">
        ///     The index of the first element.
        /// </param>
        /// <param name="j">
        ///     The index of the second element.
        /// </param>
        /// <typeparam name="T">
        ///     The type of the elements in the list.
        /// </typeparam>
        public static void Swap <T>(this SCG.IList <T> list, int i, int j)
        {
            #region Code Contracts

            // Argument must be non-null
            Requires(list != null, ArgumentMustBeNonNull);

            // List must be non-read-only
            Requires(!list.IsReadOnly, CollectionMustBeNonReadOnly);

            // Argument must be within bounds
            Requires(0 <= i, ArgumentMustBeWithinBounds);
            Requires(i < list.Count, ArgumentMustBeWithinBounds);

            // Argument must be within bounds
            Requires(0 <= j, ArgumentMustBeWithinBounds);
            Requires(j < list.Count, ArgumentMustBeWithinBounds);


            // The values are swapped
            Ensures(Equals(list[i], OldValue(list[j])));
            Ensures(Equals(list[j], OldValue(list[i])));

            #endregion

            if (i != j)
            {
                var element = list[i];
                list[i] = list[j];
                list[j] = element;
            }
        }
示例#3
0
        /// <summary>
        /// Returns a set of ModifyEnumerable delegates that modify the enumerable passed to them.
        /// </summary>
        protected override SCG.IEnumerable <ModifyEnumerable> GetModifyEnumerables(ModifyOperation operations)
        {
            foreach (var item in base.GetModifyEnumerables(operations))
            {
                yield return(item);
            }

            if (!AddRemoveClear_ThrowsNotSupported && (operations & ModifyOperation.Insert) == ModifyOperation.Insert)
            {
                yield return((SCG.IEnumerable <T> enumerable) =>
                {
                    SCG.IList <T> casted = ((SCG.IList <T>)enumerable);
                    if (casted.Count > 0)
                    {
                        casted.Insert(0, CreateT(12));
                        return true;
                    }
                    return false;
                });
            }
            if (!AddRemoveClear_ThrowsNotSupported && (operations & ModifyOperation.Remove) == ModifyOperation.Remove)
            {
                yield return((SCG.IEnumerable <T> enumerable) =>
                {
                    SCG.IList <T> casted = ((SCG.IList <T>)enumerable);
                    if (casted.Count > 0)
                    {
                        casted.RemoveAt(0);
                        return true;
                    }
                    return false;
                });
            }
        }
示例#4
0
        public void IList_Generic_ItemGet_ValidGetWithinListBounds(int count)
        {
            SCG.IList <T> list = GenericIListFactory(count);
            T             result;

            Assert.All(Enumerable.Range(0, count), index => result = list[index]);
        }
示例#5
0
        public override SC.IEnumerable Write(SC.IEnumerable enumerableInstance, object value)
        {
            SCG.IList <T> list       = (SCG.IList <T>)enumerableInstance;
            T             typedValue = (T)value;

            list.Add(typedValue);
            return(list);
        }
示例#6
0
 public override void AddRange(SCG.IList <T> elements)
 {
     _E = _E.EnsureCapacity(Count + elements.Count);
     for (int i = 0; i < elements.Count; i++)
     {
         _E[Count + i] = elements[i];
     }
     Count += elements.Count;
 }
示例#7
0
 public void IList_Generic_RemoveAt_OnReadOnlyList(int count)
 {
     if (IsReadOnly || AddRemoveClear_ThrowsNotSupported)
     {
         SCG.IList <T> list = GenericIListFactory(count);
         Assert.Throws <NotSupportedException>(() => list.RemoveAt(count / 2));
         Assert.Equal(count, list.Count);
     }
 }
示例#8
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]));
     });
 }
示例#9
0
 public void IList_Generic_Insert_ToReadOnlyList(int count)
 {
     if (IsReadOnly || AddRemoveClear_ThrowsNotSupported)
     {
         SCG.IList <T> list = GenericIListFactory(count);
         Assert.Throws <NotSupportedException>(() => list.Insert(count / 2, CreateT(321432)));
         Assert.Equal(count, list.Count);
     }
 }
示例#10
0
 public void IList_Generic_ItemSet_FirstItemToNonDefaultValue(int count)
 {
     if (count > 0 && !IsReadOnly)
     {
         SCG.IList <T> list  = GenericIListFactory(count);
         T             value = CreateT(123452);
         list[0] = value;
         Assert.Equal(value, list[0]);
     }
 }
示例#11
0
 public void IList_Generic_ItemSet_OnReadOnlyList(int count)
 {
     if (IsReadOnly && count > 0)
     {
         SCG.IList <T> list   = GenericIListFactory(count);
         T             before = list[count / 2];
         Assert.Throws <NotSupportedException>(() => list[count / 2] = CreateT(321432));
         Assert.Equal(before, list[count / 2]);
     }
 }
示例#12
0
 public void IList_Generic_ItemSet_InvalidValue(int count)
 {
     if (count > 0 && !IsReadOnly)
     {
         Assert.All(InvalidValues, value =>
         {
             SCG.IList <T> list = GenericIListFactory(count);
             Assert.Throws <ArgumentException>(() => list[count / 2] = value);
         });
     }
 }
示例#13
0
 public void IList_Generic_Insert_FirstItemToDefaultValue(int count)
 {
     if (!IsReadOnly && !AddRemoveClear_ThrowsNotSupported && DefaultValueAllowed)
     {
         SCG.IList <T> list  = GenericIListFactory(count);
         T             value = default(T);
         list.Insert(0, value);
         Assert.Equal(value, list[0]);
         Assert.Equal(count + 1, list.Count);
     }
 }
示例#14
0
 public void IList_Generic_ItemSet_NegativeIndex_ThrowsException(int count)
 {
     if (!IsReadOnly)
     {
         SCG.IList <T> list     = GenericIListFactory(count);
         T             validAdd = CreateT(0);
         Assert.Throws(IList_Generic_Item_InvalidIndex_ThrowType, () => list[-1]           = validAdd);
         Assert.Throws(IList_Generic_Item_InvalidIndex_ThrowType, () => list[int.MinValue] = validAdd);
         Assert.Equal(count, list.Count);
     }
 }
示例#15
0
 public void IList_Generic_ItemSet_LastItemToNonDefaultValue(int count)
 {
     if (count > 0 && !IsReadOnly)
     {
         SCG.IList <T> list      = GenericIListFactory(count);
         T             value     = CreateT(123452);
         int           lastIndex = count > 0 ? count - 1 : 0;
         list[lastIndex] = value;
         Assert.Equal(value, list[lastIndex]);
     }
 }
示例#16
0
 public void IList_Generic_Insert_IndexGreaterThanListCount_Appends(int count)
 {
     if (!IsReadOnly && !AddRemoveClear_ThrowsNotSupported)
     {
         SCG.IList <T> list     = GenericIListFactory(count);
         T             validAdd = CreateT(12350);
         list.Insert(count, validAdd);
         Assert.Equal(count + 1, list.Count);
         Assert.Equal(validAdd, list[count]);
     }
 }
示例#17
0
 public void IList_Generic_Insert_NegativeIndex_ThrowsArgumentOutOfRangeException(int count)
 {
     if (!IsReadOnly && !AddRemoveClear_ThrowsNotSupported)
     {
         SCG.IList <T> list     = GenericIListFactory(count);
         T             validAdd = CreateT(0);
         Assert.Throws <ArgumentOutOfRangeException>(() => list.Insert(-1, validAdd));
         Assert.Throws <ArgumentOutOfRangeException>(() => list.Insert(int.MinValue, validAdd));
         Assert.Equal(count, list.Count);
     }
 }
示例#18
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));
         });
     }
 }
示例#19
0
 public void IList_Generic_RemoveAt_IndexGreaterThanListCount_ThrowsArgumentOutOfRangeException(int count)
 {
     if (!IsReadOnly && !AddRemoveClear_ThrowsNotSupported)
     {
         SCG.IList <T> list     = GenericIListFactory(count);
         T             validAdd = CreateT(0);
         Assert.Throws <ArgumentOutOfRangeException>(() => list.RemoveAt(count));
         Assert.Throws <ArgumentOutOfRangeException>(() => list.RemoveAt(count + 1));
         Assert.Equal(count, list.Count);
     }
 }
示例#20
0
 public void IList_Generic_Insert_InvalidValue(int count)
 {
     if (!IsReadOnly && !AddRemoveClear_ThrowsNotSupported)
     {
         Assert.All(InvalidValues, value =>
         {
             SCG.IList <T> list = GenericIListFactory(count);
             Assert.Throws <ArgumentException>(() => list.Insert(count / 2, value));
         });
     }
 }
示例#21
0
 public void IList_Generic_ItemSet_IndexGreaterThanListCount_ThrowsException(int count)
 {
     if (!IsReadOnly)
     {
         SCG.IList <T> list     = GenericIListFactory(count);
         T             validAdd = CreateT(0);
         Assert.Throws(IList_Generic_Item_InvalidIndex_ThrowType, () => list[count]     = validAdd);
         Assert.Throws(IList_Generic_Item_InvalidIndex_ThrowType, () => list[count + 1] = validAdd);
         Assert.Equal(count, list.Count);
     }
 }
示例#22
0
        // TODO: Test
        /// <summary>
        ///     Shuffles the elements in the list.
        /// </summary>
        /// <param name="list">The list to shuffle.</param>
        public static void Shuffle <T>(this SCG.IList <T> list)
        {
            #region Code Contracts

            // Argument must be non-null
            Requires(list != null, ArgumentMustBeNonNull);

            #endregion

            Shuffle(list, new Random());
        }
示例#23
0
 public void IList_Generic_ItemSet_DuplicateValues(int count)
 {
     if (count >= 2 && !IsReadOnly && DuplicateValuesAllowed)
     {
         SCG.IList <T> list  = GenericIListFactory(count);
         T             value = CreateT(123452);
         list[0] = value;
         list[1] = value;
         Assert.Equal(value, list[0]);
         Assert.Equal(value, list[1]);
     }
 }
示例#24
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));
        }
示例#25
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));
     }
 }
示例#26
0
 public void IList_Generic_RemoveAt_ZeroMultipleTimes(int count)
 {
     if (!IsReadOnly && !AddRemoveClear_ThrowsNotSupported)
     {
         SCG.IList <T> list = GenericIListFactory(count);
         Assert.All(Enumerable.Range(0, count), index =>
         {
             list.RemoveAt(0);
             Assert.Equal(count - index - 1, list.Count);
         });
     }
 }
示例#27
0
 public void IList_Generic_Insert_LastItemToNonDefaultValue(int count)
 {
     if (!IsReadOnly && !AddRemoveClear_ThrowsNotSupported)
     {
         SCG.IList <T> list      = GenericIListFactory(count);
         T             value     = CreateT(123452);
         int           lastIndex = count > 0 ? count - 1 : 0;
         list.Insert(lastIndex, value);
         Assert.Equal(value, list[lastIndex]);
         Assert.Equal(count + 1, list.Count);
     }
 }
 public override void AddRange(SCG.IList <T> elements)
 {
     _E = _E.EnsureCapacity(Count + elements.Count);
     for (int i = 0; i < elements.Count; i++)
     {
         _E[Count + i] = elements[i];
         if (!Comparer.Equals(elements[i], default))          // If the newly assigned value is not null.
         {
             AfterEmtEntry(Count + i);
         }
     }
     Count += elements.Count;
 }
示例#29
0
        [Test] public void list_test()
        {
            SDL.Tag root = new SDL.Tag("root").ReadString("numbers 12 53 2");
            Tag     num  = root.GetChild("numbers");

            Assert.AreEqual(num.Values.Count, 3);
            Assert.AreEqual(num.Values[0], 12);
            Assert.AreEqual(num.Values[1], 53);
            Assert.AreEqual(num.Values[2], 2);

            SCG.IList <Tag> list = num.GetChildren(false);
            Assert.AreEqual(list.Count, 0);
        }
示例#30
0
 public void IList_Generic_RemoveAt_AllValidIndices(int count)
 {
     if (!IsReadOnly && !AddRemoveClear_ThrowsNotSupported)
     {
         SCG.IList <T> list = GenericIListFactory(count);
         Assert.Equal(count, list.Count);
         Assert.All(Enumerable.Range(0, count).Reverse(), index =>
         {
             list.RemoveAt(index);
             Assert.Equal(index, list.Count);
         });
     }
 }
示例#31
0
        public Tile(Gameboard gameboard, int X, int Y)
        {
            Chits = new ObservableCollection<ProductionChit>();
            //Chits.CollectionChanged += Chits_CollectionChanged;

            this.X = X;
            this.Y = Y;

            var offsetX = 192 * X;
            var offsetY = heightConstant * 256 * Y;
            if (X % 2 == 0)
                offsetY += heightConstant * 128;

            //this.Position = new Point(offsetX, offsetY);

            InitializeComponent();
            this.Location.Text = X + "," + Y;
        }