当前位置: 首页>>代码示例>>C#>>正文


C# MultiDimensionalArray.InsertAt方法代码示例

本文整理汇总了C#中MultiDimensionalArray.InsertAt方法的典型用法代码示例。如果您正苦于以下问题:C# MultiDimensionalArray.InsertAt方法的具体用法?C# MultiDimensionalArray.InsertAt怎么用?C# MultiDimensionalArray.InsertAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MultiDimensionalArray的用法示例。


在下文中一共展示了MultiDimensionalArray.InsertAt方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InsertAt_3D

        public void InsertAt_3D()
        {
            IMultiDimensionalArray array = new MultiDimensionalArray(2, 2, 2);
            array[0, 0, 0] = 1;
            array[0, 0, 1] = 5;
            array[0, 1, 0] = 2;
            array[0, 1, 1] = 6;
            array[1, 0, 0] = 3;
            array[1, 0, 1] = 7;
            array[1, 1, 0] = 4;
            array[1, 1, 1] = 8;
            /*
             {
               {{1, 5}{2, 6}}
               {{3, 7}{4, 8}}
             }
             */

            Assert.IsTrue(array.Shape.SequenceEqual(new[] { 2, 2, 2 }));
            Assert.IsTrue(array.Stride.SequenceEqual(new[] { 4, 2, 1 }));

            array.InsertAt(2, 0);
            /*
             {
               {{<null>, 1, 5}{<null>, 2, 6}}
               {{<null>, 3, 7}{<null>, 4, 8}}
             }
             */

            Assert.IsTrue(array.Shape.SequenceEqual(new[] { 2, 2, 3 }));
            Assert.IsTrue(array.Stride.SequenceEqual(new[] { 6, 3, 1 }));

            array.InsertAt(2, 3);
            /*
             {
               {{<null>, 1, 5, <null>}{<null>, 2, 6, <null>}}
               {{<null>, 3, 7, <null>}{<null>, 4, 8, <null>}}
             }
             */

            Assert.IsTrue(array.Shape.SequenceEqual(new[] { 2, 2, 4 }));
            Assert.IsTrue(array.Stride.SequenceEqual(new[] { 8, 4, 1 }));
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:43,代码来源:MultiDimensionalArrayTest.cs

示例2: InsertAtRemoveAt

        public void InsertAtRemoveAt()
        {
            IMultiDimensionalArray array = new MultiDimensionalArray();
            array.Resize(2, 2);
            array[0, 0] = 5;
            array[1, 1] = 2;

            array.InsertAt(0, 2);
            log.Info(array.ToString());
            array.RemoveAt(0, 2);
            log.Info(array.ToString());
            array.InsertAt(0, 2);
            log.Info(array.ToString());
            array.RemoveAt(0, 2);
            log.Info(array.ToString());
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:16,代码来源:MultiDimensionalArrayTest.cs

示例3: InsertAndRemoveOneDimensionalArray

        public void InsertAndRemoveOneDimensionalArray()
        {
            //{ 1, 3, 4} --> {1, 2, 3, 4}
            IMultiDimensionalArray array = new MultiDimensionalArray(3);
            array[0] = 1;
            array[1] = 3;
            array[2] = 4;

            //insert our new item
            array.InsertAt(0, 1);
            array[1] = 2;
            //TODO : find a nicer way for these asserts.
            Assert.AreEqual(1, array[0]);
            Assert.AreEqual(2, array[1]);
            Assert.AreEqual(3, array[2]);
            Assert.AreEqual(4, array[3]);

            // {1,2,3,4} --> {1,4}
            array.RemoveAt(0, 1, 2);
            Assert.AreEqual(1, array[0]);
            Assert.AreEqual(4, array[1]);
            Assert.AreEqual(2, array.Count);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:23,代码来源:MultiDimensionalArrayTest.cs

示例4: InsertAt

        public void InsertAt()
        {
            // 1 2
            // 5 6 
            IMultiDimensionalArray array = new MultiDimensionalArray(2, 2);
            array[0, 0] = 1;
            array[0, 1] = 2;
            array[1, 0] = 5;
            array[1, 1] = 6;
            Assert.IsTrue(array.Shape.SequenceEqual(new[] { 2, 2 }));
            Assert.IsTrue(array.Stride.SequenceEqual(new[] { 2, 1 }));

            //insert a row between the other rows
            array.InsertAt(0, 1);
            array[1, 0] = 3;
            array[1, 1] = 4;
            //now should have the following
            // 1 2
            // 3 4
            // 5 6
            Assert.IsTrue(array.Shape.SequenceEqual(new[] { 3, 2 }));
            Assert.IsTrue(array.Stride.SequenceEqual(new[] { 2, 1 }));
            Assert.AreEqual(2, array[0, 1]);
            Assert.AreEqual(3, array[1, 0]);
            Assert.AreEqual(4, array[1, 1]);
            Assert.AreEqual(6, array[2, 1]);

            //now insert two empty columns like this
            // - - 1 2
            // - - 3 4
            // - - 5 6 
            array.InsertAt(1, 0, 2);
            Assert.IsTrue(array.Shape.SequenceEqual(new[] { 3, 4 }));
            Assert.IsTrue(array.Stride.SequenceEqual(new[] { 4, 1 }));
            Assert.AreEqual(null, array[0, 0]);
            Assert.AreEqual(null, array[0, 1]);
            Assert.AreEqual(1, array[0, 2]);
            Assert.AreEqual(2, array[0, 3]);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:39,代码来源:MultiDimensionalArrayTest.cs

示例5: BubblePropertyChangesOfInsertedObject

        public void BubblePropertyChangesOfInsertedObject()
        {
            var testNotifyPropertyChangedObject = new TestNotifyPropertyChangedObject();

            IMultiDimensionalArray<TestNotifyPropertyChangedObject> array = new MultiDimensionalArray<TestNotifyPropertyChangedObject>
                                                                                {
                                                                                    IsAutoSorted = false
                                                                                };
            array.Add(new TestNotifyPropertyChangedObject());

            array.InsertAt(0, 0, 1, new[] { testNotifyPropertyChangedObject });

            TestHelper.AssertPropertyChangedIsFired((INotifyPropertyChanged)array, 1, testNotifyPropertyChangedObject.FireChanged);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:14,代码来源:MultiDimensionalArrayTest.cs

示例6: InsertOneRowInEmptyMatrix

 [NUnit.Framework.Category(TestCategory.WorkInProgress)] //not required yet?
 public void InsertOneRowInEmptyMatrix()
 {
     IMultiDimensionalArray array = new MultiDimensionalArray(2,2);
     array.Clear();
     array.Resize(2,2);
     array.InsertAt(0, 0, 2, new List<double> { 1.0, 2.0 });
     Assert.AreEqual(array[0, 0], 1.0);
     Assert.AreEqual(array[1, 0], 2.0);
 }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:10,代码来源:MultiDimensionalArrayTest.cs

示例7: InsertAtGivesAggregatedCollectionChangedEvent

        public void InsertAtGivesAggregatedCollectionChangedEvent()
        {
            var array = new MultiDimensionalArray<double>(new[] { 2, 2 });

            var callCount = 0;
            array.CollectionChanged += (s, e) =>
            {
                callCount++;
                var args = (MultiDimensionalArrayChangingEventArgs)e;
                Assert.AreEqual(NotifyCollectionChangeAction.Add, args.Action);
                Assert.AreEqual(new[] { 0, 0 }, args.MultiDimensionalIndex);
                Assert.AreEqual(new[] { 3, 2 }, args.Shape);
                //inserted a 3x2 block
                Assert.AreEqual(new[] { 1, 2, 3, 4, 5, 6 }, args.Items);
            };

            //insert 2 slices on the first dimension
            array.InsertAt(0, 0, 3, new object[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 });

            Assert.AreEqual(1, callCount);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:21,代码来源:MultiDimensionalArrayTest.cs

示例8: ThrowExceptionIfInsertedValuesCountIsIncorrect

        public void ThrowExceptionIfInsertedValuesCountIsIncorrect()
        {
            //array of 4x3
            var array = new MultiDimensionalArray<double>(new[] {4, 3});

            //insert 2 slices of dim1 ...expected 2*3 = 6 values insert 2 should give exception
            array.InsertAt(0, 0, 2, new object[] {1.0, 2.0});
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:8,代码来源:MultiDimensionalArrayTest.cs

示例9: InsertAtWithValuesInTheMiddle

 public void InsertAtWithValuesInTheMiddle()
 {
     var array = new MultiDimensionalArray<int>(new[] {3});
     array[0] = 0;
     array[1] = 4;
     array[2] = 5;
     array.InsertAt(0, 1, 3, new object[] {1, 2, 3});
     Assert.AreEqual(new[] {6}, array.Shape);
     Assert.AreEqual(new[] {0, 1, 2, 3, 4,5}, array);
 }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:10,代码来源:MultiDimensionalArrayTest.cs

示例10: InsertAtWithValuesAtTheEnd

 public void InsertAtWithValuesAtTheEnd()
 {
     var array = new MultiDimensionalArray<int>(new[] {1});
     array[0] = 4;
     array.InsertAt(0, 1, 3, new object[] {1, 2, 3});
     Assert.AreEqual(new[] {4}, array.Shape);
     Assert.AreEqual(new[] {4, 1, 2, 3}, array);
 }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:8,代码来源:MultiDimensionalArrayTest.cs

示例11: ReadOnlyInsertAt2Args

 public void ReadOnlyInsertAt2Args()
 {
     var array = new MultiDimensionalArray(true, false, 1, new[] { 1 }, new[] { 1 });
     array.InsertAt(0, 0,1);
 }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:5,代码来源:MultiDimensionalArrayTest.cs

示例12: InsertAtOnFirstDimensionShouldPerformLinearly

        [NUnit.Framework.Category(TestCategory.BadQuality)] // TODO: split this test in two tests measuring actual time and use TestHelper.AssertIsFasterThan()
        public void InsertAtOnFirstDimensionShouldPerformLinearly()
        {
            //TODO: move this test back to MDAT...only here to use functionview..

            // TODO: split this test in two tests measuring actual time and use TestHelper.AssertIsFasterThan()

            int secondDimensionSize = 500;
            var array = new MultiDimensionalArray(new[] { 0, secondDimensionSize });
            int collectionChangedCount = 0;
            array.CollectionChanged += (s, e) =>
            {
                collectionChangedCount++;
            };
            var perfSeries = new Function { Arguments = { new Variable<int> { Name = "values added" } }, Components = { new Variable<double> { Name = "total ticks" } } };

            var startTime = DateTime.Now;
            int slicesToAdd = 20000;
            for (int i = 0; i < slicesToAdd; i++)
            {
                array.InsertAt(0, i);
                if ((i % 1000) == 0)
                {
                    perfSeries[i] = (DateTime.Now - startTime).TotalMilliseconds;
                }
            }
            //one collection change per slice
            Assert.AreEqual(slicesToAdd, collectionChangedCount);
            //check the numberslice/elapsed is just about constant..
            var ratios = new List<double>();
            for (int i = 0; i < perfSeries.Arguments[0].Values.Count; i++)
            {
                ratios.Add(((double)perfSeries.Components[0].Values[i]) / (int)perfSeries.Arguments[0].Values[i]);
            }
            //check the ratios are 'about' the same 'everywhere'..get this formalized in a testhelper or something..
            Assert.AreEqual(ratios[5], ratios[9], 0.05);
            Assert.AreEqual(ratios[12], ratios[9], 0.05);
            Assert.AreEqual(ratios[12], ratios[4], 0.05);
            // to see it move this test to functionviewtest and uncomment
            //var functionView = new FunctionView { Data = perfSeries };
            //WindowsFormsTestHelper.ShowModal(functionView);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:42,代码来源:MultiDimensionalArrayTest.cs

示例13: ReduceBeforeAddingValuesAndGetValuesAfterwards

        public void ReduceBeforeAddingValuesAndGetValuesAfterwards()
        {
            var array = new MultiDimensionalArray(3, 3);
            for (int i = 0; i < 3; i++)
                for (int j = 0; j < 3; j++)
                    array[i, j] = i * 3 + j;
            var subArray = new MultiDimensionalArrayView(array);

            subArray.SelectedIndexes[0] = new int[] { 3 }; //set non-existent index
            subArray.Reduce[0] = true; //try to reduce the first dimension

            //we can't get any values
            subArray.Count.Should("Count should be 0").Be.EqualTo(0);
            foreach(var value in subArray)
                throw new ExpectationViolationException("Shouldn't return any values");
            
            //add the index the view is looking for
            array.InsertAt(0,3);
            array[3, 0] = 9;
            array[3, 1] = 10;
            array[3, 2] = 11;

            //and now we can get values
            subArray.Count.Should("Count should be 3").Be.EqualTo(3);
            int actualCount = subArray.Cast<object>().Count();
            actualCount.Should("Actual count should be 3").Be.EqualTo(3);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:27,代码来源:MultiDimensionalArrayViewTest.cs


注:本文中的MultiDimensionalArray.InsertAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。