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); }
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 })); }
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()); }
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]); }
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); }
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); }
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 })); }
[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); }
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}); }
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); }
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); }
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); }
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); }
public void ReadOnlyInsertAt2Args() { var array = new MultiDimensionalArray(true, false, 1, new[] { 1 }, new[] { 1 }); array.InsertAt(0, 0,1); }
[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); }