Пример #1
0
        public void AtOrDefault_FromIndexedExtensions_ReturnsCorrectValues(int index, int length)
        {
            var source = Enumerable.Range(0, length).ToArray();
            var sut    = IndexedExtensions.AtOrDefault(source, index);

            if (index < 0)
            {
                index = length + index;
            }

            Assert.Equal(index, sut);
        }
Пример #2
0
        public void Slice_FromIndexedExtensions_ReturnsCorrectValues()
        {
            this.RunSliceTestCases((from, to, step, length) =>
            {
                var source   = Enumerable.Range(0, length).ToArray();
                var sut      = IndexedExtensions.Slice(source, from, to, step).ToArray();
                var expected = SliceExpectedResultCalculator.Calculate(from, to, step, length);

                Assert.True(
                    expected.SequenceEqual(sut),
                    ErrorFormatter.Format(sliceResultErrorFormat, source, from, to, step, expected, sut));
            });
        }
Пример #3
0
 public void Slice_FromIndexedExtensions_GivenNullSource_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => IndexedExtensions.Slice <int>(null));
 }
Пример #4
0
 public void Slice_FromIndexedExtensions_GivenStepZero_ThrowsArgumentException()
 {
     Assert.Throws <ArgumentException>(() => IndexedExtensions.Slice(Enumerable.Empty <int>().ToArray(), step: 0));
 }
Пример #5
0
        public void AtOrDefault_FromIndexedExtensions_GivenIndexOurOfRange_ReturnsNull_WhenExecutedOnReferenceCollection(int index, int collectionLength)
        {
            var source = Enumerable.Range(0, collectionLength).Select(x => x.ToString()).ToArray();

            Assert.Equal(null, IndexedExtensions.AtOrDefault(source, index));
        }
Пример #6
0
        public void AtOrDefault_FromIndexedExtensions_GivenIndexOurOfRange_ReturnsDefaultValue_WhenExecutedOnValueCollection(int index, int length)
        {
            var source = Enumerable.Range(0, length).ToArray();

            Assert.Equal(default(int), IndexedExtensions.AtOrDefault(source, index));
        }
Пример #7
0
 public void AtOrDefault_FromIndexedExtensions_GivenNullSource_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => IndexedExtensions.AtOrDefault <int>(null, 0));
 }
Пример #8
0
        public void At_FromIndexedExtensions_GivenIndexOurOfRange_ThrowsIndexOurOfRangeException(int index, int length)
        {
            var source = Enumerable.Range(0, length).ToArray();

            Assert.Throws <IndexOutOfRangeException>(() => IndexedExtensions.At(source, index));
        }