コード例 #1
0
        public void List_ElementAt()
        {
            var list = new int[] { 3 };

            Assert.AreEqual(3, ReadOnlyList.ElementAt(list, 0));
            list = new int[] { 9, 3, 1 };
            Assert.AreEqual(3, ReadOnlyList.ElementAt(list, 1));
        }
コード例 #2
0
        public void ElementAt_With_OutOfRange_Must_Throw(int[] source, int index)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueReadOnlyList(source);

            // Act
            Action action = () => _ = ReadOnlyList
                                      .ElementAt <Wrap.ValueReadOnlyList <int>, int>(wrapped, index);

            // Assert
            _ = action.Must()
                .Throw <ArgumentOutOfRangeException>();
        }
コード例 #3
0
        public void ElementAt_With_ValidData_Must_Succeed(int[] source, int index)
        {
            // Arrange
            var wrapped = Wrap
                          .AsValueReadOnlyList(source);
            var expected =
                System.Linq.Enumerable.ElementAt(wrapped, index);

            // Act
            var result = ReadOnlyList
                         .ElementAt <Wrap.ValueReadOnlyList <int>, int>(wrapped, index);

            // Assert
            _ = result.Must()
                .BeEqualTo(expected);
        }
コード例 #4
0
        public void ElementAt_With_ValidData_Must_Return_Some(int[] source)
        {
            for (var index = 0; index < source.Length; index++)
            {
                // Arrange
                var wrapped  = Wrap.AsValueReadOnlyList(source);
                var expected =
                    System.Linq.Enumerable.ElementAt(source, index);

                // Act
                var result = ReadOnlyList
                             .ElementAt <Wrap.ValueReadOnlyList <int>, int>(wrapped, index);

                // Assert
                _ = result.Match(
                    value => value.Must().BeEqualTo(expected),
                    () => throw new Exception());
            }
        }
コード例 #5
0
        public void ElementAt_With_OutOfRange_Must_Return_None(int[] source)
        {
            // Arrange
            var wrapped = Wrap.AsValueReadOnlyList(source);

            // Act
            var optionNegative = ReadOnlyList
                                 .ElementAt <Wrap.ValueReadOnlyList <int>, int>(wrapped, -1);
            var optionTooLarge = ReadOnlyList
                                 .ElementAt <Wrap.ValueReadOnlyList <int>, int>(wrapped, source.Length);

            // Assert
            _ = optionNegative.Must()
                .BeOfType <Option <int> >()
                .EvaluateTrue(option => option.IsNone);
            _ = optionTooLarge.Must()
                .BeOfType <Option <int> >()
                .EvaluateTrue(option => option.IsNone);
        }