public void Slice()
 {
     var array = new[] { 1, 2, 3 };
     var slice = array.Slice(1, 0);
     Assert.AreEqual(0, slice.Length);
     slice = array.Slice(0, 3);
     CollectionAssert.AreEqual(array, slice);
     slice = array.Slice(1, 2);
     Assert.AreEqual(2, slice.Length);
     Assert.AreEqual(2, slice[0]);
     Assert.AreEqual(3, slice[1]);
 }
        public void SliceTestCase1ArgumentOutOfRangeException()
        {
            var sourceArray = new[]
            {
                1
            };
            var targetArray = new Int32[2];

            Action test = () => sourceArray.Slice( 2, targetArray );

            test.ShouldThrow<ArgumentOutOfRangeException>();
        }
        public void SliceTestCase()
        {
            var sourceArray = new[]
            {
                1,
                2,
                3,
                4
            };

            var actual = sourceArray.Slice( 2 );

            Assert.AreEqual( 2, actual.Length );
            Assert.AreEqual( 1, actual[0] );
            Assert.AreEqual( 2, actual[1] );
        }
        public void SliceTestCase1()
        {
            var sourceArray = new[]
            {
                1,
                2,
                3,
                4
            };
            var targetArray = new Int32[2];

            var actual = sourceArray.Slice( 2, targetArray );

            Assert.AreSame( targetArray, actual );
            Assert.AreEqual( 2, actual.Length );
            Assert.AreEqual( 1, actual[0] );
            Assert.AreEqual( 2, actual[1] );
        }
Example #5
0
		private void AddCornerAdorner(ICollection<LLShape> list, PointT point, VectorT vector)
		{
			VectorT up = new VectorT(0, -vector.Y), down = new VectorT(0, vector.Y);
			VectorT left = new VectorT(-vector.X, 0), right = new VectorT(vector.X, 0);
			var points = new[] { 
				point, point.Add(up), point.Add(up).Add(right), 
				point.Add(vector), point.Add(left).Add(down), point.Add(left)
			};
			list.Add(new LLPolygon(SelAdornerFillStyle, points));
			list.Add(new LLPolyline(SelAdornerLineStyle, points.Slice(1).AsList()));
		}
        public void SliceTestCaseArgumentOutOfRangeExceptio()
        {
            var sourceArray = new[]
            {
                1,
                2,
                3,
                4
            };

            Action test = () => sourceArray.Slice( 10 );

            test.ShouldThrow<ArgumentOutOfRangeException>();
        }
Example #7
0
        public void ListExtensions_Partition_Slice_EndIndexTooSmall()
        {
            var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            Assert.Throws<IndexOutOfRangeException>(() => ls.Slice(0, -100000));
        }
Example #8
0
        public void ListExtensions_Partition_LargeLists()
        {
            var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            var slice = ls.Slice(0, 1000, true);

            Assert.AreEqual(slice.Count, 1000);

            slice = ls.Slice(0, 10000, true);
            Assert.AreEqual(slice.Count, 10000);

            slice = ls.Slice(0, 100000, true);
            Assert.AreEqual(slice.Count, 100000);

            slice = ls.Slice(0, -1000000, true);
            Assert.AreEqual(slice.Count, 1000000);
        }
Example #9
0
        public void ListExtensions_Partition_NegativeBackwardsOverflowWithPositiveStep()
        {
            var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            // slice length > list length
            // negative backwards
            Assert.Throws<InvalidOperationException>(() => ls.Slice(2, -13, 2, true));
        }
Example #10
0
        public void ListExtensions_Parition_Slice_SingleItem()
        {
            var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            //slice of one
            Assert.IsTrue(ls.Slice(0, 1).SequenceEqual(new[] { 0 }));
        }
Example #11
0
        public void ListExtensions_Partition_SlicePostiveForwardWithNegativeStepException()
        {
            var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            // slice length < list length 
            // positive 
            // forward 
            // this should throw an exception
            Assert.Throws<InvalidOperationException>(() => ls.Slice(0, 8, -2));
        }
Example #12
0
        public void ListExtensions_Partition_SlicePostiveForwardWithPositiveStep()
        {
            var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            // slice length < list length 
            // positive 
            // forward 
            var slice = ls.Slice(0, 8, 2);

            // result should be 0 , 2 , 4 , 6
            Assert.IsTrue(slice.SequenceEqual(new[] { 0, 2, 4, 6 }));
        }
Example #13
0
        public void Test_Matrix_Slicing_With_Indices()
        {
            Matrix x = new[,]{
                { 0d, 10 },
                { 1d, 20 },
                { 2d, 30 },
                { 3d, 40 },
                { 4d, 50 },
                { 5d, 60 },
                { 6d, 70 },
            };

            var indices = new[] { 6, 4, 2, 4, 1 };

            Matrix truth = new[,]{
                { 1d, 20 },
                { 2d, 30 },
                { 4d, 50 },
                { 6d, 70 },
            };

            var actual = x.Slice(indices);

            Assert.AreEqual(truth, actual);
        }
Example #14
0
    public bool TestSubslice(Tester t)
    {
        var slice = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }.Slice();

        // First a simple subslice over the whole array, using start.
        {
            var subslice1 = slice.Slice(0);
            t.AssertEqual(slice.Length, subslice1.Length);
            for (int i = 0; i < slice.Length; i++) {
                t.AssertEqual(slice[i], subslice1[i]);
            }
        }

        // Next a simple subslice over the whole array, using start and end.
        {
            var subslice2 = slice.Slice(0, slice.Length);
            t.AssertEqual(slice.Length, subslice2.Length);
            for (int i = 0; i < slice.Length; i++) {
                t.AssertEqual(slice[i], subslice2[i]);
            }
        }

        // Now do something more interesting; just take half the array.
        {
            int mid = slice.Length/2;
            var subslice3 = slice.Slice(mid);
            t.AssertEqual(mid, subslice3.Length);
            for (int i = mid, j = 0; i < slice.Length; i++, j++) {
                t.AssertEqual(slice[i], subslice3[j]);
            }
        }

        // Now take a hunk out of the middle.
        {
            int st = 3;
            int ed = 7;
            var subslice4 = slice.Slice(st, ed);
            t.AssertEqual(ed-st, subslice4.Length);
            for (int i = ed, j = 0; i < ed; i++, j++) {
                t.AssertEqual(slice[i], subslice4[j]);
            }
        }

        return true;
    }
Example #15
0
        public void ArrayExtensions_Slice()
        {
            var inner = new[] { 1, 2, 3, 4, 5 };

            var subject = inner.Slice(0, 5);
            Check.That(subject.Start).IsEqualTo(0);
            Check.That(subject.Length).IsEqualTo(5);
        }
Example #16
0
        public void ListExtensions_Partition_NegativeForwardOverflowWithPositiveStep()
        {
            var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            // slice length > list length
            // negative 
            // forward
            Assert.IsTrue(
                ls.Slice(-12, 3, 2, true).SequenceEqual(new[] { 10, 1, 3, 5, 7, 9, 0, 2 }));
        }
Example #17
0
        public void ListExtensions_Partition_NegativeForwardOverflowWithNegativeStep()
        {
            var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            // slice length > list length
            // negative 
            // forward
            // backwards step
            Assert.Throws<InvalidOperationException>(() => ls.Slice(-12, 3, -2, true));
        }
Example #18
0
 public void ListExtensions_Partition_Slice_NegativeBackwardsIndexWithNegativeStep()
 {
     var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
     //negative reverse slice
     Assert.IsTrue(ls.Slice(-1, -9, -2).SequenceEqual(new[] { 10, 8, 6, 4 }));
 }
Example #19
0
 public void ListExtensions_Partition_NegativeBackwardsOverflowWithNegativeStep()
 {
     var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
     // slice length > list length
     // negative backwards
     // should be
     Assert.IsTrue(
         ls.Slice(2, -13, -2, true).SequenceEqual(new[] { 2, 0, 9, 7, 5, 3, 1, 10 }));
 }
Example #20
0
        public void ListExtensions_Partition_Slice_NegativeBackwardsIndexWithPositiveStep()
        {
            var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            Assert.Throws<InvalidOperationException>(() => ls.Slice(-1, -9, 2));
        }
Example #21
0
        public void ListExtensions_Partition_Slice_StartIndexTooLarge()
        {
            var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            // no overflow means that this should throw an exception
            Assert.Throws<IndexOutOfRangeException>(() => ls.Slice(10000, 0));
        }
Example #22
0
 public void ListExtensions_Partition_Slice_NegativeForwards()
 {
     var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
     //negative slice
     Assert.IsTrue(ls.Slice(-3, -1).SequenceEqual(new[] { 8, 9 }));
 }
Example #23
0
        public void ListExtensions_Partition_Slice_NonMatchingIndexes()
        {
            var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            Assert.Throws<InvalidOperationException>(() => ls.Slice(0, -1));
        }
Example #24
0
        public void ListExtensions_Partition_Slice_PostiveBackwards()
        {
            var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            // slice length < list length
            // positive 
            // backwards
            // result should be 3 , 2 , 1 , 0
            Assert.IsTrue(ls.Slice(4, 0).SequenceEqual(new[] { 4, 3, 2, 1 }));
        }
        public void SliceTestCase3ArgumentOutOfRangeException4()
        {
            var sourceArray = new[]
            {
                1,
                2,
                3,
                4
            };
            var targetArray = new Int32[4];
            Action test = () => sourceArray.Slice( 1, -1, targetArray );

            test.ShouldThrow<ArgumentOutOfRangeException>();
        }
Example #26
0
 public void ListExtensions_Partition_Slice_PostiveForwardsOverflowWithPostiveStep()
 {
     var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
     // slice length > list length
     // positive
     // forward
     // result should be 3, 5, 7, 9, 0, 2, 4
     Assert.IsTrue(
         ls.Slice(3, 16, 2, true).SequenceEqual(new[] { 3, 5, 7, 9, 0, 2, 4 }));
 }
Example #27
0
        public void ListExtensions_Partition_Slice_PostiveBackwardsOverflowWithNegativeStep()
        {
            var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            // slice length > list length
            // positive
            // backwards
            Assert.IsTrue(
                ls.Slice(16, 3, -2, true).SequenceEqual(new[] { 5, 3, 1, 10, 8, 6, 4 }));
        }
Example #28
0
        public void ListExtensions_Partition_Slice_PostiveBackwardsOverflowWithPostiveStep()
        {
            var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            Assert.Throws<InvalidOperationException>(() => ls.Slice(16, 3, 2, true));
        }
        public void SliceTestCase1NullCheck1()
        {
            var sourceArray = new[]
            {
                1,
                2
            };
            Action test = () => sourceArray.Slice( 2, null );

            test.ShouldThrow<ArgumentNullException>();
        }
Example #30
0
    public void TwoSpansCreatedOverSameIntSubarrayAreEqual()
    {
        var slice = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }.Slice();

        // First a simple subslice over the whole array, using start.
        {
            var subslice1 = slice.Slice(0);
            Assert.Equal(slice.Length, subslice1.Length);
            for (int i = 0; i < slice.Length; i++)
            {
                Assert.Equal(slice[i], subslice1[i]);
            }
        }

        // Next a simple subslice over the whole array, using start and end.
        {
            var subslice2 = slice.Slice(0, slice.Length);
            Assert.Equal(slice.Length, subslice2.Length);
            for (int i = 0; i < slice.Length; i++)
            {
                Assert.Equal(slice[i], subslice2[i]);
            }
        }

        // Now do something more interesting; just take half the array.
        {
            int mid = slice.Length / 2;
            var subslice3 = slice.Slice(mid);
            Assert.Equal(mid, subslice3.Length);
            for (int i = mid, j = 0; i < slice.Length; i++, j++)
            {
                Assert.Equal(slice[i], subslice3[j]);
            }
        }

        // Now take a hunk out of the middle.
        {
            int st = 3;
            int ed = 7;
            var subslice4 = slice.Slice(st, 4);
            Assert.Equal(ed - st, subslice4.Length);
            for (int i = ed, j = 0; i < ed; i++, j++)
            {
                Assert.Equal(slice[i], subslice4[j]);
            }
        }
    }