本文整理汇总了C#中MultiDimensionalArray类的典型用法代码示例。如果您正苦于以下问题:C# MultiDimensionalArray类的具体用法?C# MultiDimensionalArray怎么用?C# MultiDimensionalArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MultiDimensionalArray类属于命名空间,在下文中一共展示了MultiDimensionalArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestNotifyCollectionChanged
public void TestNotifyCollectionChanged()
{
var sourceArray = new MultiDimensionalArray<int>(2, 2);
IMultiDimensionalArray<int> array =
new LazyMultiDimensionalArray<int>(()=>
sourceArray,()=>sourceArray.Count);
bool called = false;
EventHandler<MultiDimensionalArrayChangingEventArgs> arrayOnCollectionChanged = delegate { called = true; };
array.CollectionChanged += arrayOnCollectionChanged;
array[0, 0] = 0;
array[0, 1] = 1;
array[1, 0] = 2;
array[1, 1] = 3;
//called when values added
Assert.IsTrue(called);
//called when we replace a value
called = false;
array[0, 0] = 5;
Assert.IsTrue(called);
//unsubscribe
called = false;
array.CollectionChanged -= arrayOnCollectionChanged;
array[0, 0] = 3;
Assert.IsFalse(called);
}
示例2: ChangeSizeOfLastDimension
public void ChangeSizeOfLastDimension()
{
//we don't use interface because want to check stride
var array = new MultiDimensionalArray();
array.Resize(2, 1);
array[0, 0] = 1; // 0 + 0
array[1, 0] = 2; // 2 + 0
// 1 1 <= stride
Assert.AreEqual(new[] { 1, 1 }, array.Stride);
log.InfoFormat("Before resize: {0}", array.ToString());
array.Resize(new[] { 2, 2 });
log.InfoFormat("After resize: {0}", array.ToString());
Assert.AreEqual(2, array.Rank);
Assert.AreEqual(4, array.Count);
Assert.AreEqual(1, array[0, 0]);
Assert.AreEqual(2, array[1, 0]);
Assert.IsNull(array[0, 1]);
Assert.IsNull(array[1, 1]);
}
示例3: ToString
public void ToString()
{
var source = new MultiDimensionalArray<int>(new List<int> { 1, 2, 3, 4, 5, 6 }, new[] { 2, 3 });
var target = new ConvertedArray<string, int>(source, Convert.ToInt32, Convert.ToString);
Assert.AreEqual("{{1, 2, 3}, {4, 5, 6}}", target.ToString());
}
示例4: Count
public void Count()
{
//array = 1,2,3,4,5
IMultiDimensionalArray<int> array = new MultiDimensionalArray<int> {1, 2, 3, 4, 5};
//view = 2,3
IMultiDimensionalArrayView<int> view = new MultiDimensionalArrayView<int>(array, 0, 1, 2);
Assert.AreEqual(2, view.Count);
}
示例5: EnumerateEmptyArray
public void EnumerateEmptyArray()
{
IMultiDimensionalArray<int> array = new MultiDimensionalArray<int>();
foreach (int o in array)
{
Assert.Fail("No objects in the array. Should not come here");
}
}
示例6: Add
public void Add()
{
IMultiDimensionalArray<int> array = new MultiDimensionalArray<int>();
IMultiDimensionalArrayView view = new MultiDimensionalArrayView(array, 0, int.MinValue, int.MaxValue);
view.Add(4);
Assert.AreEqual(1, view.Count);
Assert.AreEqual(1, array.Count);
}
示例7: ClearView
public void ClearView()
{
IMultiDimensionalArray<int> array = new MultiDimensionalArray<int> {1, 2, 3, 4, 5};
IMultiDimensionalArrayView view = new MultiDimensionalArrayView(array, 0, 1, 2);
view.Clear();
Assert.AreEqual(0, view.Count);
Assert.AreEqual(3, array.Count);
Assert.IsTrue(new[] {1, 4, 5}.SequenceEqual(array));
}
示例8: TestGetInsertionIndex
public void TestGetInsertionIndex()
{
IMultiDimensionalArray<int> ints = new MultiDimensionalArray<int>{1, 2, 40, 50};
Assert.AreEqual(2, MultiDimensionalArrayHelper.GetInsertionIndex(3, ints));
Assert.AreEqual(0, MultiDimensionalArrayHelper.GetInsertionIndex(0, ints));
Assert.AreEqual(4, MultiDimensionalArrayHelper.GetInsertionIndex(60, ints));
Assert.AreEqual(1, MultiDimensionalArrayHelper.GetInsertionIndex(2, ints));
Assert.AreEqual(0, MultiDimensionalArrayHelper.GetInsertionIndex(2, new MultiDimensionalArray<int>()));
}
示例9: ConvertToListUsingCopyConstructor
public void ConvertToListUsingCopyConstructor()
{
MultiDimensionalArray array = new MultiDimensionalArray<double>(2);
IMultiDimensionalArray<double> view = new MultiDimensionalArrayView<double>(array);
view[0] = 10;
view[1] = 5;
var arrayList = new ArrayList(view);
Assert.AreEqual(10, arrayList[0]);
Assert.AreEqual(5, arrayList[1]);
}
示例10: InBetweenTest
public void InBetweenTest()
{
IMultiDimensionalArray<int> ints = new MultiDimensionalArray<int> { 1, 2, 40, 50 };
int prev = ints[0];
int next = ints[ints.Count - 1];
Assert.IsTrue(Comparer.IsBetween(prev, 3, next));
Assert.IsFalse(Comparer.IsBetween(prev, 0, next));
Assert.IsFalse(Comparer.IsBetween(prev, 1, next));
Assert.IsFalse(Comparer.IsBetween(prev, 50, next));
Assert.IsTrue(Comparer.IsBetween(prev, 40, next));
}
示例11: GetLastValueSmallerThan
public void GetLastValueSmallerThan()
{
var array = new MultiDimensionalArray { 1.0, 2.0 };
Assert.IsNull(FunctionHelper.GetLastValueSmallerThan(1.0, array));
Assert.AreEqual(1.0, FunctionHelper.GetLastValueSmallerThan(1.5, array));
Assert.AreEqual(2.0, FunctionHelper.GetLastValueSmallerThan(2.5, array));
array = new MultiDimensionalArray { 1.0 };
Assert.IsNull(FunctionHelper.GetLastValueSmallerThan(1.0, array));
Assert.AreEqual(1.0, FunctionHelper.GetLastValueSmallerThan(55.0, array));
}
示例12: ConvertToListUsingCopyConstructorGeneric
public void ConvertToListUsingCopyConstructorGeneric()
{
IList<int> values = new List<int> {1, 2, 3, 4};
MultiDimensionalArray array = new MultiDimensionalArray<int>(values, new[] {1, 4});
IMultiDimensionalArray<int> view = new MultiDimensionalArrayView<int>(array);
IList array1D = new List<int>(view);
Assert.AreEqual(4, array1D.Count);
Assert.AreEqual(4, array1D[3]);
Assert.AreEqual(2, array1D[1]);
}
示例13: EnumerateRowMajor
public void EnumerateRowMajor()
{
IMultiDimensionalArray<int> array = new MultiDimensionalArray<int>(2, 2);
array[0, 0] = 0;
array[0, 1] = 1;
array[1, 0] = 2;
array[1, 1] = 3;
//verify we traverse in row major order
int i = 0;
foreach (int j in array)
{
Assert.AreEqual(j, i++);
}
}
示例14: TestConvertedArray
public void TestConvertedArray()
{
IMultiDimensionalArray<int> intArray = new MultiDimensionalArray<int>(new List<int> { 1, 2, 3, 4, 5 }, new[] { 5 });
IMultiDimensionalArray<string> stringArray = new ConvertedArray<string, int>(intArray, Convert.ToInt32, Convert.ToString);
Assert.AreEqual(intArray.Shape, stringArray.Shape);
Assert.AreEqual("1", stringArray[0]);
//assignment on the converted array are passed to the source
stringArray.Add("30");
Assert.AreEqual(30, intArray[5]);
intArray.Add(31);
Assert.AreEqual("31", stringArray[6]);
}
示例15: Bind2D
public void Bind2D()
{
IMultiDimensionalArray array = new MultiDimensionalArray();
array.Resize(2, 2);
array[0, 0] = 5;
array[1, 1] = 2;
DataGridView gridView = new DataGridView();
MultiDimensionalArrayBindingList multiDimensionalArrayBindingList = new MultiDimensionalArrayBindingList(array);
gridView.DataSource = multiDimensionalArrayBindingList;
Form form = new Form();
gridView.Dock = DockStyle.Fill;
form.Controls.Add(gridView);
WindowsFormsTestHelper.ShowModal(form);
}