本文整理汇总了C#中RubyArray.Freeze方法的典型用法代码示例。如果您正苦于以下问题:C# RubyArray.Freeze方法的具体用法?C# RubyArray.Freeze怎么用?C# RubyArray.Freeze使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RubyArray
的用法示例。
在下文中一共展示了RubyArray.Freeze方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RubyArray_Add
public void RubyArray_Add()
{
RubyArray a;
a = new RubyArray();
for (int i = 0; i < Utils.MinListSize; i++) {
a.Add(i);
Assert((int)a[i] == i && a.Count == i + 1 && a.Capacity == Utils.MinListSize);
}
Assert(((IList)a).Add(Utils.MinListSize) == Utils.MinListSize);
Assert(a.Count == Utils.MinListSize + 1);
for (int i = 0; i < a.Count; i++) {
Assert((int)a[i] == i);
}
a = new RubyArray(new[] { 1,2,3 });
a.AddCapacity(0);
Assert(a.Count == 3);
a.AddCapacity(100);
Assert(a.Count == 3 && a.Capacity >= 103);
a = new RubyArray(new[] { 1, 2, 3 });
a.AddMultiple(0, 4);
AssertValueEquals(a, 1, 2, 3);
a.AddMultiple(5, 4);
AssertValueEquals(a, 1, 2, 3, 4, 4, 4, 4, 4);
a = new RubyArray(new[] { 1, 2, 3 });
a.AddRange(new object[0]);
AssertValueEquals(a, 1, 2, 3);
a.AddRange(new[] { 4 });
AssertValueEquals(a, 1, 2, 3, 4);
a.AddRange(new[] { 5, 6, 7, 8, 9, 10 });
AssertValueEquals(a, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
a.AddRange(new[] { 11 });
AssertValueEquals(a, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
a = new RubyArray();
a.AddRange((IEnumerable)new RubyArray(new[] { 1, 2, 3 }));
a.AddRange((IList)new RubyArray(new[] { 1, 2, 3 }), 1, 2);
AssertValueEquals(a, 1, 2, 3, 2, 3);
a.Freeze();
AssertExceptionThrown<RuntimeError>(() => a.Add(1));
AssertExceptionThrown<RuntimeError>(() => a.AddCapacity(10));
AssertExceptionThrown<RuntimeError>(() => a.AddMultiple(10, 10));
AssertExceptionThrown<RuntimeError>(() => a.AddRange(new object[0]));
AssertExceptionThrown<RuntimeError>(() => a.AddRange(Enumerable(0)));
}
示例2: RubyArray_Misc
public void RubyArray_Misc() {
RubyArray a;
a = new RubyArray(new[] { 3, 5, 2, 4, 1 });
a.InsertRange(0, new[] {10, 20});
a.RemoveRange(0, 2);
a.Sort();
Assert(ArrayUtils.ValueEquals(a.ToArray(), new object[] { 1, 2, 3, 4, 5 }));
a.Sort((x, y) => (int)x == (int)y ? 0 : ((int)x < (int)y ? 1 : -1));
Assert(ArrayUtils.ValueEquals(a.ToArray(), new object[] { 5, 4, 3, 2, 1 }));
a.Reverse();
Assert(ArrayUtils.ValueEquals(a.ToArray(), new object[] { 1, 2, 3, 4, 5 }));
a.Freeze();
AssertExceptionThrown<RuntimeError>(() => a.Reverse());
AssertExceptionThrown<RuntimeError>(() => a.Sort());
}
示例3: RubyArray_Insert
public void RubyArray_Insert() {
RubyArray a;
a = new RubyArray(new[] { 1, 2, 3, 4, 5 });
a.InsertRange(0, new[] { 10, 20, 30, 40 });
AssertValueEquals(a, 10, 20, 30, 40, 1, 2, 3, 4, 5);
a.InsertRange(2, new[] { 8 });
AssertValueEquals(a,10, 20, 8, 30, 40, 1, 2, 3, 4, 5);
a.InsertRange(10, new[] { 9 });
AssertValueEquals(a, 10, 20, 8, 30, 40, 1, 2, 3, 4, 5, 9);
a.RemoveRange(1, 5);
AssertValueEquals(a, 10, 2, 3, 4, 5, 9);
a.InsertRange(1, new[] { 0 });
AssertValueEquals(a, 10, 0, 2, 3, 4, 5, 9);
a.InsertRange(6, new[] { 8 });
AssertValueEquals(a, 10, 0, 2, 3, 4, 5, 8, 9);
a.RemoveRange(6, 2);
AssertValueEquals(a, 10, 0, 2, 3, 4, 5);
a.InsertRange(3, new[] { 11, 12, 13, 14 });
AssertValueEquals(a, 10, 0, 2, 11, 12, 13, 14, 3, 4, 5);
a = new RubyArray(new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
// make enough space on both sides:
a.RemoveRange(0, 2);
AssertValueEquals(a, 2, 3, 4, 5, 6, 7, 8, 9);
a.RemoveRange(6, 2);
AssertValueEquals(a, 2, 3, 4, 5, 6, 7);
// closer to start:
a.InsertRange(1, new[] { 10 });
AssertValueEquals(a, 2, 10, 3, 4, 5, 6, 7);
// closer to end:
a.InsertRange(5, new[] { 11 });
AssertValueEquals(a, 2, 10, 3, 4, 5, 11, 6, 7);
a = new RubyArray(new[] { 1, 2, 3 });
a.Insert(0, 0);
AssertValueEquals(a, 0, 1, 2, 3);
a.InsertRange(0, Enumerable(2));
AssertValueEquals(a, 1, 2, 0, 1, 2, 3);
a.InsertRange(0, new RubyArray(new[] { 1, 0 }), 1, 1);
a.InsertRange(0, new object[] { 0, -1 }, 1, 1);
a.InsertRange(0, new[] { 0, -2 }, 1, 1);
AssertValueEquals(a, -2, -1, 0, 1, 2, 0, 1, 2, 3);
a.InsertRange(0, (IEnumerable)new RubyArray(new[] { 30 }));
a.InsertRange(0, (IEnumerable)new object[] { 20 });
a.InsertRange(0, (IEnumerable)new[] { 10 });
AssertValueEquals(a, 10, 20, 30, -2, -1, 0, 1, 2, 0, 1, 2, 3);
a.Freeze();
AssertExceptionThrown<RuntimeError>(() => a.Insert(0, 1));
AssertExceptionThrown<RuntimeError>(() => a.InsertRange(0, new object[0]));
AssertExceptionThrown<RuntimeError>(() => a.InsertRange(0, Enumerable(0)));
}
示例4: RubyArray_Remove
public void RubyArray_Remove() {
RubyArray a;
a = new RubyArray(new[] { 1, 2, 3, 4, 5 });
a.RemoveAt(1);
AssertValueEquals(a, 1, 3, 4, 5);
a.RemoveAt(1);
AssertValueEquals(a, 1, 4, 5);
a.RemoveAt(1);
AssertValueEquals(a, 1, 5);
a.RemoveAt(1);
AssertValueEquals(a, 1);
a.AddRange(new[] { 2, 3 });
AssertValueEquals(a, 1, 2, 3);
a.RemoveAt(0);
AssertValueEquals(a, 2, 3);
a.RemoveAt(0);
AssertValueEquals(a, 3);
a.RemoveAt(0);
AssertValueEquals(a);
a.AddRange(new[] { 1, 2, 3 });
AssertValueEquals(a, 1, 2, 3);
a = new RubyArray();
a.AddMultiple(100, 1);
a[0] = 0;
a[99] = 99;
a.RemoveRange(1, 98);
AssertValueEquals(a, 0, 99);
Assert(a.Capacity < 100, "array should shrink");
((IList)a).Remove(0);
AssertValueEquals(a, 99);
a.Clear();
Assert(a.Count == 0);
a = new RubyArray(new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 });
a.RemoveRange(0, 4);
AssertValueEquals(a, 4, 5, 6, 7, 8, 9, 10, 11);
a.AddMultiple(3, 1);
AssertValueEquals(a, 4, 5, 6, 7, 8, 9, 10, 11, 1, 1, 1);
a.RemoveRange(0, 6);
AssertValueEquals(a, 10, 11, 1, 1, 1);
a.AddMultiple(2, 2);
AssertValueEquals(a, 10, 11, 1, 1, 1, 2, 2);
a = new RubyArray();
a = new RubyArray(new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 });
a.RemoveRange(0, 4);
AssertValueEquals(a, 4, 5, 6, 7, 8, 9, 10, 11);
a.AddMultiple(3, null);
AssertValueEquals(a, 4, 5, 6, 7, 8, 9, 10, 11, null, null, null);
var vector = new object[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
a = new RubyArray(vector);
for (int i = 0, c = a.Count; i < c; i++) {
a.RemoveAt(0);
vector = ArrayUtils.ShiftLeft(vector, 1);
AssertValueEquals(a, vector);
}
a = new RubyArray(new[] { 1, 2, 3 });
a.Freeze();
Assert(!a.Remove(0));
AssertExceptionThrown<RuntimeError>(() => a.Remove(1));
AssertExceptionThrown<RuntimeError>(() => a.Clear());
AssertExceptionThrown<RuntimeError>(() => a.RemoveAt(0));
AssertExceptionThrown<RuntimeError>(() => a.RemoveRange(0, 1));
}